当前位置:网站首页>第四章-第一个程序
第四章-第一个程序
2022-06-12 08:42:00 【皮卡乒的皮卡乓】
第四章-第一个程序
4.1 一个源程序从写出到执行的过程
编写汇编源程序
使用文本编辑器,用汇编语言编写汇编源程序。
编译连接
- 使用汇编语言编译程序(MASM.EXE)对源程序文件中的源程序进行编译,产生目标文件;
- 再用连接程序(LINK.EXE)对目标文件进行连接,生成可在操作系统中直接运行的可执行文件。
可执行文件
- 程序(汇编指令翻译过来的机器码)和数据(定义的数据)
- 相关的描述信息(比如:占用多大内存,程序多大)
执行可执行文件中的程序
- 在操作系统中执行可执行文件中的程序。
- 操作系统依照可执行文件中的描述信息,将可执行文件中的机器码和数据载入内存,并进行初始化,然后由CPU执行程序。
4.2源程序
汇编指令
由CPU识别,对应机器码
伪指令
由编译器看懂,CPU看不懂的。告诉编译器怎么执行我们的代码。
XXX segment(段)
XXX endssegment和ends是成对使用的伪指令,功能是定义一个段,前者代表开始,后面代表结束。
end是一个汇编程序的结束标记。
assume:假如、假设。
标号
- 一个标号代表了一个地址
- codesg:放在segment的前面,作为一个段的名称,这个段的名称最终
DOS中的程序运行
- DOS是一个单任务操作系统。
- 一个程序结束后,将CPU控制器交还,这叫:程序的返回
- 要在程序的末尾添加返回的程序段。
- 这两条指令所实现的功能就是程序返回。
mov ax,4c00H
int 21H
##中断
段结束、程序结束、程序返回

语法错误和逻辑错误
- 语法错误,在编译时被编译器发现的错误;
- 逻辑错误是程序在编译时不能表现出来的、在运行时发生的。
关于编译和连接
- 编译:汇编语言翻译为机器语言
- 连接:把目标文件连接到一起,生成一个可执行文件。
4.8可执行文件中的程序装入内存并运行的原理
- 在DOS中,可执行文件中的程序P1若要运行,必须有一个正在运行的程序P2,将P1从可执行文件中加载入内存,将CPU的控制权交给它,P1才能得以运行;当P1运行完毕,应该将CPU的控制权交还给CPU使它可以继续运行程序P2
- 我们在DOS中直接运行1.exe时,是正在运行的command将1.exe中的程序加载入内存。
- command设置CPU的CS:IP指向程序的第一条指令(即程序的入口),从而使程序得以运行。
- 程序结束后,返回到command中,CPU继续运行command。

操作系统的外壳
- DOS中有一个程序command.com,这个程序在DOS中称为命令解释器,也就是DOS系统的shell
4.9程序执行过程的跟踪

总结:EXE文件中的程序的加载过程
- 程序加载后,ds中存放着程序所在内存区的段地址,这个内存区的偏移地址为0,则程序所在的内存区的地址为:ds:0;
- 这个内存区的前256个字节中存放的是PSP,dos用来和程序进行通信。
- 从256字节处向后的空间存放的是程序。
- so,我们从ds中可以得到PSP的段地址SA,PSP的偏移地址为0,则物理地址为:SA×16+0。
- 因为PSP占256(100H)字节,所以程序的物理地址是:
SA×16+0+256=(SA+16)×16
可用段地址和偏移地址表示为:SA+10:0
命令:
- 用U命令查看其他指令;
- 用T命令但不执行程序中的每一条指令,并观察每条指令的执行结果
- 到了int21,我们要用P命令执行
- 结束后回到debug,q回到command
边栏推荐
- 余压监控系统保证火灾发生时消防疏散通道的通畅,为大型高层建筑的安全运行和人民生命财产安全保驾护航
- Lock mechanism in MySQL
- 【进阶指针一】字符数组&数组指针&指针数组
- Py & go programming skills: logic control to avoid if else
- 安科瑞消防应急照明和疏散指示系统
- Knee joint
- (p19-p20) delegate constructor (proxy constructor) and inheritance constructor (using)
- 【指針進階三】實現C語言快排函數qsort&回調函數
- When converting tensor to ndarray in tensorflow, the run or Eval function is constantly called in the loop, and the code runs more and more slowly!
- Hands on learning and deep learning -- simple implementation of linear regression
猜你喜欢

Hands on deep learning -- activation function and code implementation of multi-layer perceptron

根据有效期显示距离当前还剩多少天有效期

Hands on deep learning -- implementation of multi-layer perceptron from scratch and its concise implementation

x64dbg 调试 EXCEPTION_ACCESS_VIOLATION C0000005

【数据存储】浮点型数据在内存中的存储

Engineers learn music theory (II) scale and tendency
![[compilation principle] understand BNF](/img/64/9a0e7507606781336fdc44116ba423.jpg)
[compilation principle] understand BNF

The difference between deep copy and shallow copy

Centos8 installing MySQL 8.0 (upper)

Engineers learn music theory (I) try to understand music
随机推荐
Inheritance of row height
JVM学习笔记:垃圾回收机制
Scope of bean
ctfshow web4
Hands on deep learning -- weight decay and code implementation
(p19-p20) delegate constructor (proxy constructor) and inheritance constructor (using)
Shell basic syntax -- arithmetic operation
How to understand the production scheduling of APS system?
Engineers learn music theory (III) interval mode and chord
Background location case 1
Hands on deep learning -- concise implementation code of weight decay
Engineers learn music theory (II) scale and tendency
The newline character with in the string is converted to an array
【 pointeur avancé Ⅲ】 mise en œuvre de la fonction de tri rapide qsort& fonction de rappel en langage C
What is the beauty of MES equipment management for enterprises?
动态创建表单并提交
When converting tensor to ndarray in tensorflow, the run or Eval function is constantly called in the loop, and the code runs more and more slowly!
【进阶指针一】字符数组&数组指针&指针数组
Arrays in JS
Hands on deep learning -- activation function and code implementation of multi-layer perceptron