简体   繁体   中英

Segmentation fault when not interrupting in assembly

I'm confused about something, I'm new and learning assembly on GNU/Linux, and if you used movl instruction and didn't interrupt (terminate) the program, it will trigger a segmentation fault error.
For clarifying, the only thing the program I made for that does is exiting by a system call.

Why does it do that? I mean, why when there is interruption it isn't considered "accessing memory that it isn't allowed to access"?

Edit: I'm not trying to do anything by this, it is a question out of confusion of the result, but here is the code:

movl $1, %eax
movl $2, %ebx
#int $0x80 (if you remove the comment, it won't trigger a segmentation fault error, even though now we are using registers normally)

I think what you're seeing is a segmentation fault due to the program not having a proper exit.

Once you start executing, the CPU doesn't know how long a program is and needs a hlt, or a syscall to change control flow and actually exit the program. Thus, when you remove the syscall instruction (and as a result any exit from the program), the CPU continues to execute. The problem is, you haven't specified what will be executing, rather it's what is currently in memory that is executing. From there, you have two likely outcomes: a segfault (like you're seeing) because the CPU incremented past some point of valid memory, or an illegal instruction because some combination of memory actually translates to an invalid opcode.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM