问题描述
我试图在x86 Assembly中添加两个数字2和3。我不是主要使用寄存器,而是从堆栈中推送和弹出值(这就是Forth编译器项目的一部分,这就是原因)。但是,我的代码给我一个分段错误。我已经在GDB中运行了它,但是回溯并没有给我任何有价值的信息。有谁确切知道为什么我的代码中会发生此错误? (我正在Mac上这样编译它:gcc -g -mstackrealign -masm=intel -o test test.asm
)。
.global _main
.text
plus:
add rdi,rsi
push rdi # push accumulated rdi value onto stack
ret
minus:
sub rdi,rsi
push rdi
ret
_main:
push 2 # push 2 and 3 onto stack
push 3
pop rdi # as preparation for the function call,load rdi and rsi with 2 and 3
pop rsi
call plus
pop rax # put result into rax
mov rdi,rax # then,put the result into rdi
mov rax,0x2000001 # exit system call
syscall
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)