0

i have a sum value stored in

fstp    qword [ebx]  ; Copy contents of st0 to space currently on top of the system stack

how do i divide it by an integer value that is stored in register edi?

i thought it was just

fdiv edi

but it says invalid combination of....blah blah blha

insight?

2 Answers 2

1

You can't. The FPU does not have access to the integer registers.

2
  • i was thinking maybe this would work fstp qword [ebx] ;Copy contents of st0 to space currently on top of the system stack fld qword [edi] ;move edi onto FPU fdiv ; divide? fstp qword [ebx] ;copy the result to print it out
    – John
    Mar 19, 2011 at 0:18
  • why not just push edi, fdiv [esp]? Mar 19, 2011 at 4:29
0

As Jens says in his answer, the FPU does not have any direct access to the integer registers. You will need to use scratch memory to make the transfer. This is one of the major disadvantages of the x87 FPU. Example code might look something like:

section .bss
fpscratch: resd 1

...

section .text

;other code goes here

MOV fpscratch, edi
FILD fpscratch
FDIV

(Note on the above code: it has not been tested, obviously, and I'm a little rusty on my assembly so there is probably something wrong with it, even though it's nice and short.)

2
  • i tried that and it doesn't work, however i'm working this code right now and it's outputting -nan
    – John
    Mar 19, 2011 at 4:05
  • fild qword [ebp+12] fstp qword [ebx] ;Copy contents of st0 to space currently on top of the system stack ;mov fpscratch, edi ;fild edi fdiv fstp qword [ebx] ;Copy contents of st0 to space currently on top of the system stack
    – John
    Mar 19, 2011 at 4:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.