如何解决Lisp编译器的汇编器输出不正确
我正在为x86编写Lisp编译器。我一直在尝试调试它,因为对于某些变量声明,它会产生错误的输出代码。这是我给它的代码:
(define y (+ 1 2))
(define x 6)
(display x)
我期望输出为6。但是,它输出为零。我将其范围缩小到下面的代码。
我正在MacOS上组装GAS:
gcc -masm=intel overflow_q.asm
.global _main
.text
_main:
push 1 # arg 2 for proc +
push 2 # arg 1 for proc +
pop rsi # begin plus
pop rdi
add rdi,rsi # end plus
push rdi # for the caller of +
pop rax # get result in rax
mov [y + rip],rax # put computed value of 3 into y
mov rsi,[x + rip] # put value of x,6,into rsi
/*
I have not included the code for the call to "display"
because it's irrelevant - and the program still fails
in the same way without it
*/
/*
The bug:
RSI turns out to be zero here! Why is that happening?
I know this given the exit code returned from running it.
*/
mov rdi,rsi
mov rax,0x2000001
syscall
.data
y:
.long 0 # initialize with a value of zero
x:
.long 6
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。