A simple assembly code cause a segment fault?

点点圈 提交于 2019-12-10 18:25:01

问题


.section .data

.section .text
.globl _start
_start:
 movl $1, %eax  # this is the linux kernel command
    # number (system call) for exiting
    # a program

movl $4, %ebx   # this is the status number we will
    # return to the operating system.
    # Change this around and it will
    # return different things to
    # echo $?

int $0x80   # this wakes up the kernel to run
    # the exit command

But if I remove the last line of code int 0x80 , then it'll cause a segment fault.

I don't know why? Can anyone tell me.

Thanks for your time.


Thanks everyone. Now I get the answer.

Without the line of code int $0x80 , the system doesn't know that whether this application has ended or when this application ended. So it will cause crash.


回答1:


If you remove the int 0x80 you will have a segmentation fault because it will begin executing whatever random bytes were in RAM immediately following your program. You really can't predict what will be there and other things can certainly happen, but a segfault is likely because the random data will very likely work out to be a memory access outside of your process memory.



来源:https://stackoverflow.com/questions/30456230/a-simple-assembly-code-cause-a-segment-fault

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