Toggle navigation
首页
博客
文章
美图
笔记
管理后台
如何搭建书中程序运行环境(附英文电子书)
笔者:chen | 书名:Programming from the Ground Up
🪶
笔记摘要
阅读字号:
小
中
大
-
+
16px
1. 将下面程序保存文件名为exit.s ``` #PURPOSE: Simple program that exits and returns a # status code back to the Linux kernel # #INPUT: none # #OUTPUT: returns a status code. This can be viewed # by typing # # echo $? # # after running the program # #VARIABLES: # %eax holds the system call number # (this is always the case) # # %ebx holds the return status # .section .data .section .text .globl _start _start: movl $1, %eax # this is the linux kernel command # number (system call) for exiting # a program movl $0, %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 ``` 2. 用 GNU 汇编器将汇编源文件编译成目标文件: ``` as exit.s -o exit.o ``` 3. 要链接该文件,请输入命令: ``` ld exit.o -o exit ``` 4. 运行 exit 程序,你可以通过输入命令: ``` ./exit ``` 5. 验证结果,如果你输入以下命令,正常状态它会显示 0: ``` echo $? ``` 其他程序也一样调试,这是在linux下操作,不同系统版本按提示完成,ubuntu24版本已默认安装gun汇编器。
笔记附件
下载附件: 2/ProgrammingGroundUp-0-9.pdf
返回内容列表
返回书名列表