我有这段代码:
section .data
x dw 10
y dw 10
section .text
global _main
_main: xor rax, rax
mov rax, x
mov rbx, y
add rax, rbx
result: nop
exit: mov rax, 0x2000001 ; System call number for exit = 1
mov rdi, 0 ; Exit success = 0
syscall ; Invoke the kernel
并尝试编译:
nasm -f macho64 hello.asm
gcc -m64 hello.o -o hello
并使用lldb进行调试
(lldb) r
Process 74574 launched: './hello' (x86_64)
Process 74574 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
frame #0: 0x0000000100000fab hello`result
hello`result:
-> 0x100000fab <+0>: nop
hello`exit:
0x100000fac <+0>: movl $0x2000001, %eax ; imm = 0x2000001
0x100000fb1 <+5>: movl $0x0, %edi
0x100000fb6 <+10>: syscall
Target 0: (hello) stopped.
(lldb) register read rax
rax = 0x0000000200002004
我预计在rax中是0x014,但我有0x0000000200002004,我做错了什么?