What cause segment fault after function call in assembly x64 [duplicate]

主宰稳场 提交于 2020-08-09 17:52:25

问题


My OS: Linux debian 4.19.0-9-amd64 #1 SMP Debian x86_64 GNU/Linux Compiler: NASM version 2.14

I try play with conditional jumps, function calling and comparing expressions. I wrote something simple, and it seems to by work, but i don't understand what cause error: EnSegmentation fault

For compilation purpose i'm use: nasm -f elf64 sample_file.asm -o sample_file.o and: ld sample_file.o -o sample_file

section .data
msg: db 'Hello world',10
end: db 'Ending program', 10
section .text

global _start

hello_world:

        mov rax, 1
        mov rdi, 1
        mov rsi, msg
        mov rdx , 14

        syscall

        ret

exit:

        mov rax, 1
        mov rdi, 1
        mov rsi, end
        mov rdx, 20
        syscall

        mov rax, 60
        xor rdi, rdi
        syscall

        ret
_start:

        mov rax, 10
        mov rdx, 10
        cmp rax, rdx 
        je hello_world
        jne exit

        call hello_world
        mov rax, 60
        xor rdi,rdi
        syscall

        call exit

But the output is :

Hello world
EnSegmentation fault

来源:https://stackoverflow.com/questions/63308385/what-cause-segment-fault-after-function-call-in-assembly-x64

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!