简体   繁体   English

在汇编中将任何st寄存器中的浮点数除以整数常量

[英]Divide a float in any of the st registers by an integer constant in assembly

I need to divide a float in let's say st0 by an integer (in this example 2): So know that i can achieve this by simply: 我需要用整数将st0中的浮点数除以整数(在此示例中为2):所以知道我可以通过以下方式实现此目的:

mov rax, 2
fild rax
fdivp st1

but is there a more elegant and less bulky version like (and I know the following doesn't work): 但是是否有一个更优雅,更不那么笨重的版本(我知道以下内容不起作用):

fidiv 2

:S please let me know too if it's impossible :) thanks in advance :S请让我知道是否不可能:)预先感谢

None of the x87 instructions support immediate values. x87指令均不支持立即值。 What you need to do is store the constant you want to divide by in some memory location and then load it implicitly using a memory operand: 您需要做的是将要除以的常数存储在某个内存位置,然后使用内存操作数隐式加载它:

    fdiv DWORD PTR two      ; st0 = st0 / 2
    ...

two REAL4 2.0

Note that division by constants can be sped up massively by multiplying with the reciprocal instead: 请注意,可以通过乘以倒数来大量加速常数的除法运算:

    fmul DWORD PTR two     ; st0 = st0 * 0.5 = st0 / 2
    ...

two REAL4 0.5

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM