加载函数参数到寄存器时,段错误

问题描述 投票:1回答:1

我是很新的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

为什么程序段错误?

assembly x86 segmentation-fault nasm x86-64
1个回答
0
投票

我在64位模式,像一堆的人建议使用mov ebx, [rsp+8]工作的意见,因为esp只是寄存器的4位字节。

© www.soinside.com 2019 - 2024. All rights reserved.