《Linux C一站式编程》:不加 int $0x80 导致段错误

在 《Linux C一站式编程》中有这样一个问题:

.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 这一句去掉,也能够编译链接成功,但是却会导致一个段错误,请问这是为什么?

谢谢大家了~

阅读 6.7k
2 个回答

这是一个中断,操作系统(这个 int 80 是在 Linux 下)定死的,现推荐用 SYSENTER. 那么一个调用最后没有 SYSENTER 或者 SYSEXIT,当然会报错啦。

它的作用去 Google 把,我就不当搬运工啦,毕竟很长时间没有接触了。

新手上路,请多包涵

程序从_start入口开始执行,如果去掉int $0x80,当执行完movl $4, %ebx,后就没有调用_exit系统调用结束程序,于是会接着从程序加载内存位置之后取下一条不属于本程序的指令,于是出现段错误

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题