Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A simple assembly code cause a segment fault?

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

like image 885
simowce Avatar asked Jan 23 '26 22:01

simowce


1 Answers

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.

like image 117
David Hoelzer Avatar answered Jan 26 '26 13:01

David Hoelzer