x86 assembly(MASM) - 64位整数的平方根?

qwe*_*ium 1 x86 assembly masm masm32

我正在用x86汇编语言(MASM32)为Windows编写一个简单的素性测试程序,它涉及计算(64位)整数的平方根.我的问题是:有没有简单的方法来获得平方根?我应该使用ADD/SUB/DIV/MUL指令的某些组合吗?

我找到了一些关于如何用C语言实现这一目标的信息,但我只是想知道我是否在这里遗漏了一些东西?

Smi*_*Smi 8

我认为最简单的方法是使用FPU指令fsqrt:

.data?
int64 dq ?
squareRoot dd ?

.code
fild int64        ;load the integer to ST(0)
fsqrt             ;compute square root and store to ST(0)
fistp squareRoot  ;store the result in memory (as a 32-bit integer) and pop ST(0)
Run Code Online (Sandbox Code Playgroud)