当esp没有时,为什么会重新引用ebp寄存器segfaul?

时间:2013-12-01 23:18:22

标签: assembly x86 nasm

有没有理由为什么取消引用ebp寄存器会使程序出现段错误 取消引用esp寄存器不? 两个寄存器都包含相同的值。

例如,以下代码段将为我崩溃

mov ebp, esp
mov eax, [ebp]

但下一个代码段不会

mov eax, [esp]

我已经包含了一个完整的nasm程序,可以解决这个问题。 我很难过。

section .text
global main

%define TEST 'My test'

BITS 32

main:
    push dword msg
    jmp print_message

carry_on_here:

    mov eax, 1   ;  The system call (sys_exit)
    int 0x80     ; System interupt which invokes the kernel 

print_message:
    mov ebp, esp ; Store esp in ebp
    mov ecx, [ebp] ; <---- CRASH BECAUSE OF THIS, works with "mov ecx, [esp]"
    mov edx, len ; Length of message

    mov ebx, 1   ; the stdout file descriptor
    mov eax,4    ; the system call (sys_write)
    int 0x80     ; system interupt which invokes the kernel

    jmp carry_on_here

section .bss
section .data ; The memory here is initialised

msg db  "My message"    ,10 ;the message. Allocate d (initialised), b (bytes) , 10 of them which is: db "Initalised" 10
len equ $ - msg         ;the message length

提前致谢!

修改

所以问题是我如何编译和链接程序。 最初我开始使用x64程序集,然后转换到x86。 我错过了将-f选项更改为elf32,因此它仍在elf64上。 进行此更改后,epb寄存器将在不崩溃的情况下取消引用。

0 个答案:

没有答案