我有以下文件:
; hello.s
.section __TEXT,__text
.globl _main
_main:
movl $0x2000001, %eax
movl $42, %ebx
syscall
我尝试按照以下步骤运行它:
# run.sh
as -mmacosx-version-min=10.9 hello.s -o hello.o
ld -macosx_version_min 10.9 -lSystem hello.o -e _main -o hello
./hello
echo $?
输出结果为:
$ ./run.sh
1
I expect it to be
$ ./run.sh
42
这里出了什么问题?
编辑:
根据zneak的答案,我们需要使用%edi寄存器进行系统调用,因此可正常工作的程序如下:
; hello.s
.section __TEXT,__text
.globl _main
_main:
movl $0x2000001, %eax
movl $42, %edi
syscall