How to convert an integer to a floating point value in x86 ASM?

牧云@^-^@ 提交于 2020-12-06 04:20:13

问题


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 cvtdq2psdoc

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!