我是很新的x86汇编,我试图构建一种Hello World程序。我试图做一个子程序,单个字节到标准输出写,但我已经打了一个问题。行mov ebx, [esp+1]
(加载字节通过,当我调用子程序)导致段错误。
我试过异或的EBX与自己注册,以确保它是空的,以确保,它不惹的系统调用
_start:
push 32h
call _writeByte
; This just jumps to an exit routine
jmp _exit
_writeByte:
; This line causes the problem. If I remove it the program works fine
mov ebx, [esp+1]
xor ebx, ebx
mov eax, 1
mov edi, 1
mov esi, tmp
mov edx, 1
syscall
ret
为什么程序段错误?
我在64位模式,像一堆的人建议使用mov ebx, [rsp+8]
工作的意见,因为esp
只是寄存器的4位字节。