问题
I need to multiply an integer (two's compliment) by a floating point constant. Here is what I have:
.data
pi dd 3.14
int dd 0ah
.code
fld pi
???
fmul ST(1), ST
How can I convert int
to a floating point value for multiplying against pi
?
回答1:
You need the fild
instruction. Here's one reference: http://www.website.masmforum.com/tutorials/fptute/fpuchap5.htm
回答2:
Using the x86 FPU is really outdated now and way slower than SSE/AVX/etc.
Better to use at least SSE with cvtdq2ps
doc
ex:
.data
int dd 0ah
pi dd 3.14
.code
movss xmm0, [data] ; load 32bit data into xmm0
cvtdq2ps xmm0, xmm0 ; convert 4 float values to integers, we use only lowest float/integer
mulss xmm0, [pi]
来源:https://stackoverflow.com/questions/3027424/how-to-convert-an-integer-to-a-floating-point-value-in-x86-asm