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 (将#修改为@)