当我执行推送指令时,我收到:Segmentation fault (core dumped)

When I do a push instruction, I receive: Segmentation fault (core dumped)

在下面的代码中,当我取消注释任何 push 指令时,我收到错误 Segmentation fault (core dumped) 而 运行 可执行文件。我试图查明错误原因,但尚未找到原因。

section .data
; Message contains app purpose
msg db 'This app calculates 2^3+5^2',0x0a
mlen equ $-msg

msg1 db 'Computation is done',0x0a
lmsg1 equ $-msg1

num1 dd 2
lnum1 equ $-num1

pow1 dd 3
lpow1 equ $-pow1

num2 dd 5
lnum2 equ $-num2

pow2 dd 2
lpow2 equ $-pow2

section .text
global _start
_start:

    xor edx, edx ; clear registers
    xor ecx, ecx
    xor ebx, ebx
    xor eax, eax
    xor esi, esi
    xor edi, edi
    xor esp, esp
    xor ebp, ebp

    mov edx, mlen
    mov ecx, msg
    mov ebx, 1
    mov eax, 4
    int 0x80 ; print message

    mov edx, dword [pow2]
    mov ecx, dword [num2]
    mov ebx, dword [pow1]
    mov eax, dword [num1]
    ;push edx
    ;push ecx ; --> When I un-comment any push command,
    ;push ebx ; --> I receive: Segmentation fault (core dumped)
    ;push eax ;

    jmp end

end:
    mov edx, lmsg1      ; length
    mov ecx, msg1       ; memory location
    mov ebx, 1
    mov eax, 4
    int 0x80            ; print a newline i.e. 0x0a 

    mov ebx, 0
    mov eax, 1
    int 0x80

你期待什么?
如果你弄乱了堆栈指针(esp),显然你会有麻烦。

在 x86 保护模式下地址 0 永远不是有效目标。
此外,所有 'negative' 地址 (0x80000000-0xFFFFFFFF) 都在内核 space 中。

您重置 esp,然后您 push,这意味着您在地址 0-4 = 0xFFFFFFFC 中存储了一个寄存器。这将失败,因为您在用户 space 中的进程没有访问内核 space 的权限。

无论细节如何,你都不能这样乱搞ESP。仅根据需要递增或递减 ESP 以清除或创建堆栈 space.
切勿将 esp 设置为绝对地址。