【发布时间】:2011-09-28 11:32:46
【问题描述】:
所以我在我的 mac 上学习 x86_64 nasm 汇编是为了好玩。在 hello world 和一些基本算术之后,我尝试从 this site 复制一个稍微高级一点的 hello world 程序并将其修改为 64 位 intel,但我无法摆脱这个错误消息:hello.s:53: error: Mach-O 64-bit format does not support 32-bit absolute addresses。这是我用来组装和链接的命令:nasm -f macho64 hello.s && ld -macosx_version_min 10.6 hello.o。这是相关的行:
cmp rsi, name+8
rsi 是我在循环中用于索引的寄存器,name 是为用户输入保留的四字,即名称,此时已经写入。
这里是部分代码(要查看其余部分,请单击链接并转到底部,唯一的区别是我使用的是64位寄存器):
loopAgain:
mov al, [rsi] ; al is a 1 byte register
cmp al, 0x0a ; if al holds an ascii newline...
je exitLoop ; then jump to label exitLoop
; If al does not hold an ascii newline...
mov rax, 0x2000004 ; System call write = 4
mov rdi, 1 ; Write to stdout = 1
mov rdx, 1 ; Size to write
syscall
inc rsi
cmp rsi, name+8 ; LINE THAT CAUSES ERROR
jl loopAgain
【问题讨论】:
-
一个建议:尝试用 C 编写相同的代码,使用
gcc -S编译它,然后查看程序集以了解 GCC 是如何处理它的。 -
@bdonlan: 在.bss 部分,我有
name: resb 8 -
@Nemo:我试过了,但我无法理解它。
标签: macos assembly x86-64 nasm mach-o