0

I have a question: let's say my stack of the Floating-point unit is as follows:

ST0 = +1.5000000000000000e+0001   ST1 = +5.0000000000000000e+0000
ST2 = +2.5000000000000000e+0001   ST3 = +0.0000000000000000e+0000  
ST4 = +0.0000000000000000e+0000   ST5 = +0.0000000000000000e+0000   
ST6 = +0.0000000000000000e+0000   ST7 = +0.0000000000000000e+0000 

After doing this instruction:

fstp st(1) 

My prediction it that the unit would send the st(0) to st(1) (the situation on the stack would be 1.5;1.5;2.5;0 etc) and then pop the top of the stack so the stiuation would be 1.5;2.5;0 etc.

Instead, I see the following:

ST0 = +1.5000000000000000e+0001   ST1 = +2.5000000000000000e+0001   
ST2 = +0.0000000000000000e+0000   ST3 = +0.0000000000000000e+0000   
ST4 = +0.0000000000000000e+0000   ST5 = +0.0000000000000000e+0000   
ST6 = +0.0000000000000000e+0000   ST7 = +1.5000000000000000e+0001

My question is, why has st(7) changed and how can I achieve my expected results. Thanks for any help!

Jens Björnhager
  • 5,632
  • 3
  • 27
  • 47
Simon
  • 2,643
  • 3
  • 40
  • 61

2 Answers2

0

ST7 has changed because it is the previous contents of st0 after rotating the stack. Your debugger should somehow indicate that the value is not usable.

Jens Björnhager
  • 5,632
  • 3
  • 27
  • 47
0

Ok I got the answer now. The problem of showing a non-zero value in the last register is a result of the built of the FPU stack. The value shown in st(7) is just rubbish, being a result of the compiler's method of popping the top items. So to pop the stack, it just rotates the stack.

Side note: other compilers may but dont have to work in that way, so we shouldn't expect every code to execute like that. It's a matter of a compiler.

Simon
  • 2,643
  • 3
  • 40
  • 61