一个简单的汇编代码会导致段故障? [英] A simple assembly code cause a segment fault?

查看:103
本文介绍了一个简单的汇编代码会导致段故障?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.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

但是,如果我删除代码的最后一行int 0x80,那么它将导致段错误.

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 everyone. Now I get the answer.

没有代码行int $0x80系统不知道此应用程序是否已终止或该应用程序何时终止.因此,它将导致崩溃.

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.

推荐答案

如果删除int 0x80,将出现分段错误,因为它将在程序之后立即开始执行RAM中随机的任何字节.您确实无法预测会发生什么,并且肯定会发生其他事情,但是可能会出现段错误,因为随机数据很可能会成为过程内存之外的内存访问.

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.

这篇关于一个简单的汇编代码会导致段故障?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆