问题
.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