64位NASM师IDIV [英] 64bit nasm division idiv
问题描述
;print out division message
mov rcx, 0 ;zero out register
mov rax, [input]
mov rcx, [input2]
idiv rcx ;divide rax by rcx
mov rdi, rax ;for printing purposes
call print_int
我似乎无法弄清楚这是为什么不分裂,我得到一个enrror浮点异常我使用的是64位机和值不整数浮点....想法?
I can't seem to figure out why this isn't dividing, I'm getting a enrror "Floating Point Exception" I'm using a 64bit machine and the values are integers not floating point.... ideas?
我知道发生分裂后,放置商应在RAX,其余应在RDX我相信,但截至现在,我只是试图让我的手在商。
I know after the division takes place the quotient should be in rax, and the remainder should be in rdx i believe, but as of right now i'm just trying to get my hands on the quotient.
推荐答案
您的功能看起来有点复杂,我。 IDIV
与该功能预计我在这里工作的:
Your function looks a little bit complicated to me. idiv
works as expected for me here with this function:
_mydiv:
xor %rdx, %rdx ; clear high bits of dividend
mov %rdi, %rax ; copy dividend argument into rax
idiv %rsi ; divide by divisor argument
ret ; return (quotient is in rax)
翻译成NASM语法和窗户ABI,我想这会是这样的:
Translated into NASM syntax and to the windows ABI, I think that would be something like:
_mydiv:
mov r8, rdx ; copy divisor argument to scratch register
xor rdx, rdx ; clear high bits of dividend
mov rax, rcx ; copy dividend argument into rax
idiv r8 ; divide by divisor in scratch register
ret ; return (quotient is in rax)
您也许踩在你的参数和沿途混乱的东西吗?
Are you maybe stomping on your parameters and confusing something along the way?
编辑:看你的code,它发生,我认为它可能根本无法写成一个正常功能。最重要的步骤是:
looking at your code, it occurs to me that it might not be written as a proper function at all. The important steps are:
- 把股息RDX:RAX - 你这可能意味着清理出RDX并把输入股息RAX
- 把除数在其他一些寄存器 - 你选择RCX,这应该是罚款 。
- 分割 -
IDIV RCX
- 结果将在RAX。
您应该特别注意步骤1 - 确保RDX:RAX有理智的内容!为什么你得到一个浮点例外,我无法从$ C $猜c您已经证明。
You should pay particular attention to step 1 - make sure that RDX:RAX has sane contents! Why you're getting a floating point exception I can't guess from the code you've shown.
这篇关于64位NASM师IDIV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!