开发者

FDIV how to use it in nasm, assembly

开发者 https://www.devze.com 2023-02-18 14:42 出处:网络
i have a sum value stored in 开发者_开发技巧 fstpqword [ebx]; Copy contents of st0 to space currently on top of the system stack

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?


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


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.)

0

精彩评论

暂无评论...
验证码 换一张
取 消