如何在X86组装中分配两个未签名的长64位值,然后将商和剩余的返回到C程序
在单独的C程序中,我已将4个参数传递给X86 ASM程序。
- 股息
- 除数
- 商指针
- 剩余指针
股息= 0xa
除数= 0x3
,即10/3。
商应为3,其余应为1。
但是,我的商正在返回C2,其余的是返回7FFFFFFF396F687。这两者都远远与我应该得到的相距遥远。我已经尝试调试我的ASM代码,但我无法弄清楚问题是什么。
这就是我到目前为止的。我是初学者。
global divide64u
divide64u:
push rbp
mov rbp, rsp
mov rdx, rdi
mov rax, rsi
xor rdx, rdx
div r10
divide64uDone:
pop rbp
ret
In a separate C program, I have passed 4 parameters to an x86 ASM program.
- dividend
- divisor
- Quotient pointer
- Remainder pointer
dividend = 0xA
divisor = 0x3
Which is 10/3.
The quotient should be 3 and the remainder should be 1.
However, my quotient is returning c2 and my remainder is returning 7ffff396f687. Both of which are extremely far off of what i should be getting. I've tried debugging my ASM code and I can't figure out what the problem is.
This is what I have so far. I'm a beginner at this.
global divide64u
divide64u:
push rbp
mov rbp, rsp
mov rdx, rdi
mov rax, rsi
xor rdx, rdx
div r10
divide64uDone:
pop rbp
ret
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于
X86_64
,根据ABI,ARGS全部传递在寄存器中。因此,无需按/pop
rbp/rsp
实际上可以在C中进行编码,并且编译器Optimizer将生成最有效的代码:
这是上述用
-O2汇编的拆卸代码
:For
x86_64
, the args are all passed in registers, per the ABI.So, no need to push/pop
rbp/rsp
You can actually code this in C and the compiler optimizer will generate the most efficient code:
Here is the disassembly of the above compiled with
-O2
: