Lisp x86_64编译器产生不正确的输出

问题描述

我正在编写一个Lisp编译器,该编译器为x86_64体系结构(特别是针对OS X)生成代码。我使用Chez Scheme作为参考编译器,以检查编译器的输出是否正确。 Chez为下面的表达式提供了32的输出,但是我的编译器代码给了我8的输出(在Lisp代码下面)。我无法弄清楚原因,也无法弄清楚如何调整程序集以使其返回正确的结果。如果您精通x86_64(GAS,Intel语法),可以在这里给我一些建议吗?

(define (f x y) (* (* y 2) (+ x 3)))
(define x (f 5 2)); expecting an output of 32
    .global _main
    .text
_main:
    push 2  # push argument to f
    push 5  # push argument to f
    call f
    mov [x + rip],rax
    mov rdi,rax
    mov rax,0x2000001
    syscall
f:
    push rbp
    mov rbp,rsp
    push 3  # push argument to +
    push [rbp + 16]  # push argument to +
    call plus
    push rax  # result of +
    push 2  # push argument to *
    push [rbp + 24]  # push argument to *
    call multiply
    push rax  # result of *
    call multiply
    mov rsp,rbp
    pop rbp
    ret

    .data
x:
    .quad 0

这是addmultiply函数:

.macro operator mnemonic
push rbp
mov rbp,rsp

mov rdi,[rbp + 24]
mov rsi,[rbp + 16]
\mnemonic rdi,rsi
mov rax,rdi

mov rsp,rbp
pop rbp
ret
.endm

plus: operator add
multiply: operator imul

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...