x86汇编(MASM) - 一个64位整数的平方根? [英] x86 assembly (MASM) - Square root of a 64-bit integer?
本文介绍了x86汇编(MASM) - 一个64位整数的平方根?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在x86汇编语言(MASM32),其中涉及计算(64位)整数的平方根编码一个简单的测试素性程序为Windows。我的问题是:有没有获得平方根什么简单的办法?我应该使用ADD / SUB的组合/ DIV / MUL指令?
I'm coding a simple primality tester program for Windows in x86 assembly language (MASM32), which involves calculating a square root of a (64-bit) integer. My question is: Is there any simple way for obtaining the square root? Should I use some combination of ADD/SUB/DIV/MUL instructions?
我发现了一些 的信息C语言,但我只是想知道如果我在这里失去了一些东西?
I found some information on how this could be achieved in C language, but I'm just wondering if I'm missing something here?
推荐答案
我觉得最简单的方法就是使用FPU指令 FSQRT
是这样的:
I think the simplest way is to use the FPU instruction fsqrt
like this:
.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)
这篇关于x86汇编(MASM) - 一个64位整数的平方根?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文