当前位置:网站首页>第四章-第一个程序
第四章-第一个程序
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
边栏推荐
- Background position - exact units
- Regularization to limit the number of digits after the decimal point of an input number
- Method to limit the input box to only numbers
- Configuration and principle of MSTP
- Engineers learn music theory (I) try to understand music
- [GUI development] browsing function implementation model of image processing software
- Handling abnormal data
- Seurat package addmodulescore is used for bulk RNA SEQ data
- 余压监控系统保证火灾发生时消防疏散通道的通畅,为大型高层建筑的安全运行和人民生命财产安全保驾护航
- Graphic analysis of viewbox in SVG
猜你喜欢

电气火灾探测器对各用电回路进行实时监控

Handling abnormal data

Configuration and principle of MSTP

This article is required for the popularization of super complete MES system knowledge

Error: clear the history in the search box in the website?

Hands on learning and deep learning -- simple implementation of linear regression

(p21-p24) unified data initialization method: List initialization, initializing objects of non aggregate type with initialization list, initializer_ Use of Lisy template class

Hands on learning and deep learning -- Realization of linear regression from scratch

网站Colab与Kaggle

FDA审查人员称Moderna COVID疫苗对5岁以下儿童安全有效
随机推荐
Py & go programming skills: logic control to avoid if else
JVM学习笔记:三 本地方法接口、执行引擎
Jump to an interface at a specified time. (Web Development)
svg中viewbox图解分析
Production scheduling status of manufacturing enterprises and solutions of APS system
(p17-p18) define the basic type and function pointer alias by using, and define the alias for the template by using and typedef
What is the MES system? What is the operation process of MES system?
2022.6.9-----leetcode.497
Audio and video related links
【新规划】
[GUI development] browsing function implementation model of image processing software
2022.6.11-----leetcode. nine hundred and twenty-six
Dynamic segment tree leetcode six hundred and ninety-nine
Audio and video engineer (Preliminary) (I) basic concepts of audio and video
(p15-p16) optimization of the right angle bracket of the template and the default template parameters of the function template
Knee joint
Database foundation -- normalization and relational schema
余压监控系统保证火灾发生时消防疏散通道的通畅,为大型高层建筑的安全运行和人民生命财产安全保驾护航
Webrtc adding third-party libraries
The Three Kingdoms kill the surrounding areas -------- explanation of the pig Kingdom kill problem