📄 masm3.htm
字号:
<html>
<head>
<title>汇编指令的格式(伪指令)</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="#CCCCCC">
<b>
<p align="center" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" face="宋体" lang="ZH-CN">第四节</font><font size="2"><font face="宋体">
</font><font face="宋体" lang="ZH-CN">伪</font><font face="宋体"> </font>
<font face="宋体" lang="ZH-CN">指</font><font face="宋体"> </font></font>
<font size="2" face="宋体" lang="ZH-CN">令</font></p>
</b>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font face="宋体" lang="ZH-CN" size=2>伪指令是对汇编起某种控制作用的特殊命令,其格式与通常的操作指令一样,并可加在汇编程序的任何地方,但它们并不产生机器指令。</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font face="宋体" lang="ZH-CN" size=2>许多伪指令要求带参数,这在定义伪指令时由“表达式”域指出,任何数值与表达式匀可以作为参数。</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font face="宋体" lang="ZH-CN" size=2>不同汇编程序允许的伪指令并不相同,以下所述的伪指令仅适用于MASM51系统,但一些基本的伪指令在大部份汇编程序中都能使用,当使用其它的汇编程序版本时,只要注意一下它们之间的区别就可以了。MASM51中可用的伪指令有:</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font face="宋体" size=2> ORG </font><font face="宋体" lang="ZH-CN" size=2>设置程序起始地址</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font face="宋体" size=2> END </font><font face="宋体" lang="ZH-CN" size=2>标志源代码结束</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font face="宋体" size=2> EQU </font><font face="宋体" lang="ZH-CN" size=2>定义常数</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font face="宋体" size=2> SET </font><font face="宋体" lang="ZH-CN" size=2>定义整型数</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font face="宋体" size=2> DATA </font><font face="宋体" lang="ZH-CN" size=2>给字节类型符号定值</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font face="宋体" size=2> BYTE </font><font face="宋体" lang="ZH-CN" size=2>给字节类型符号定值</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font face="宋体" size=2> WROD </font><font face="宋体" lang="ZH-CN" size=2>给字类型符号定值</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font face="宋体" size=2> BIT </font><font face="宋体" lang="ZH-CN" size=2>给位地址取名</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font face="宋体" size=2> ALTNAME </font><font face="宋体" lang="ZH-CN" size=2>用自定义名取代保留字</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font face="宋体" size=2> DB </font><font face="宋体" lang="ZH-CN" size=2>给一块连续的存储区装载字节型数据</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font face="宋体" size=2> DW </font><font face="宋体" lang="ZH-CN" size=2>给一块连续的存储区装载字型数据</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font face="宋体" size=2> DS </font><font face="宋体" lang="ZH-CN" size=2>预留一个连续的存储区或装入指定字节。</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font face="宋体" size=2> INCLUDE </font><font face="宋体" lang="ZH-CN" size=2>将一个源文件插入程序中</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font face="宋体" size=2> TITLE </font><font face="宋体" lang="ZH-CN" size=2>列表文件中加入标题行</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font face="宋体" size=2> NOLIST </font><font face="宋体" lang="ZH-CN" size=2>汇编时不产生列表文件</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font face="宋体" size=2> NOCODE </font><font face="宋体" lang="ZH-CN" size=2>条件汇编时,条件为假的不产生清单</font></p>
<ol>
<b>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" face="宋体" lang="ZH-CN">一、</font><font size="2" face="宋体">ORG
</font><font face="Arial">
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0"></p>
</font></b>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font face="宋体" lang="ZH-CN" size=2>伪指令</font><font face="宋体" size=2>ORG</font><font face="宋体" lang="ZH-CN" size=2>用于为在它之后的程序设置地址值,它有一个参数,其格式为:</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font face="宋体" size=2> ORG </font><font face="宋体" lang="ZH-CN" size=2>表达式</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font face="宋体" lang="ZH-CN" size=2>表达式可以是一个具体的数值,也可以包含变量名,如果包含变量名,则必须保证,当第一次遇到这条伪指令时,其中的变量必须已有定义(已有具体的数值),否则,无定义的值将由</font><font face="宋体" size=2>0</font><font face="宋体" lang="ZH-CN" size=2>替换,这将会造成错误。在列表文件中,由</font><font face="宋体" size=2>ORG</font><font face="宋体" lang="ZH-CN" size=2>定义的指令地址会被打印出来。</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font face="宋体" size=2> ORG</font><font face="宋体" lang="ZH-CN" size=2>指令有什么用途呢?指令被翻译成机器码后,将被存入系统的ROM中,一般情况下,机器码总是一个接一个地放在存储器中,但有一些代码,其位置有特殊要求,典型的是五个中断入口,它们必须被放在</font><font face="宋体" size=2>0003H,000BH,0013H,001BH</font><font face="宋体" lang="ZH-CN" size=2>和</font><font face="宋体" size=2>0023H</font><font face="宋体" lang="ZH-CN" size=2>的位置,否则就会出错,如果我们编程时不作特殊处理,让机器代码一个接一个地生成,不能保证这些代码正好处于这些规定的位置,执行就会出错,这时就要用到</font><font face="宋体" size=2>ORG</font><font face="宋体" lang="ZH-CN" size=2>伪指令了。看如下例子:</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font face="宋体" lang="ZH-CN" size=2>例:</font></p>
<i><font face="宋体" size=2>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">INT_0 EQU 1000H</p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">TIME_0 EQU 1010H</p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">INT_1 EQU 1020H</p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">TIME_1 EQU 1030H</p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">SERIAL EQU 1040H</p>
</font>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font face="宋体" size=2> AJMP START ;</font><font face="宋体" lang="ZH-CN" size=2>跳转到主程序起始点</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font face="宋体" size=2> LJMP INT_0 ;</font><font face="宋体" lang="ZH-CN" size=2>外中断</font><font face="宋体" size=2>0</font><font face="宋体" lang="ZH-CN" size=2>处理程序</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font face="宋体" size=2> LJMP TIME_0 ;</font><font face="宋体" lang="ZH-CN" size=2>定时中断</font><font face="宋体" size=2>0</font><font face="宋体" lang="ZH-CN" size=2>处理程序</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font face="宋体" size=2> LJMP INT_1 ;</font><font face="宋体" lang="ZH-CN" size=2>外中断</font><font face="宋体" size=2>1</font><font face="宋体" lang="ZH-CN" size=2>处理程序</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font face="宋体" size=2> LJMP TIME_1 ;</font><font face="宋体" lang="ZH-CN" size=2>定时中断</font><font face="宋体" size=2>1</font><font face="宋体" lang="ZH-CN" size=2>处理程序</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font face="宋体" size=2> LJMP SERIAL ;</font><font face="宋体" lang="ZH-CN" size=2>串行口中断程序</font></p>
<font face="宋体" size=2>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">START:</p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"> NOP</p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"> END</p>
</font></i>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font face="宋体" lang="ZH-CN" size=2>上面的程序经汇编后列表文件如下</font><font face="宋体" size=2>:</font></p>
<font face="Arial" size=3>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"> </p>
</font>
<i>
<font face="宋体" size=2>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">The Cybernetic Micro Systems 8051 Family Assembler, Version
3.03 Page 1</p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"> 08-26-96</p>
</font>
<font face="Arial" size=3>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"></p>
</font>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size=2 face="宋体">
</font>
</p>
<font face="宋体" size=2>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"> 1000 = INT_0 EQU 1000H</p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"> 1010 = TIME_0 EQU 1010H</p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"> 1020 = INT_1 EQU 1020H</p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"> 1030 = TIME_1 EQU 1030H</p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"> 1040 = SERIAL EQU 1040H</p>
</font>
</i>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"><i>
<font face="宋体" size=2> 0000 0111 AJMP START ;</font><font face="宋体" lang="ZH-CN" size=2>跳转到主程序起始点</font></i></p>
<i>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font face="宋体" size=2> 0002 021000 LJMP INT_0 ;</font><font face="宋体" lang="ZH-CN" size=2>外中断</font><font face="宋体" size=2>0</font><font face="宋体" lang="ZH-CN" size=2>处理程序</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font face="宋体" size=2> 0005 021010 LJMP TIME_0 ;</font><font face="宋体" lang="ZH-CN" size=2>定时中断</font><font face="宋体" size=2>0</font><font face="宋体" lang="ZH-CN" size=2>处理程序</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font face="宋体" size=2> 0008 021020 LJMP INT_1 ;</font><font face="宋体" lang="ZH-CN" size=2>外中断</font><font face="宋体" size=2>1</font><font face="宋体" lang="ZH-CN" size=2>处理程序</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font face="宋体" size=2> 000B 021030 LJMP TIME_1 ;</font><font face="宋体" lang="ZH-CN" size=2>定时中断</font><font face="宋体" size=2>1</font><font face="宋体" lang="ZH-CN" size=2>处理程序</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font face="宋体" size=2> 000E 021040 LJMP SERIAL ;</font><font face="宋体" lang="ZH-CN" size=2>串行口中断程序</font></p>
<font face="宋体" size=2>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"> START:</p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"> 0011 00 NOP</p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"> 0000 END</p>
</font>
<font face="Arial" size=3>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"></p>
</font>
<font face="宋体" size=2>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">The Cybernetic Micro Systems 8051 Family Assembler, Version
3.03 Page 2</p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"> 08-26-96</p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"> ;%T Symbol Name Type Value</p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"> INT_0 . . . . . . . . . . . . . I 1000</p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"> INT_1 . . . . . . . . . . . . . I 1020</p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"> SERIAL. . . . . . . . . . . . . I 1040</p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"> START . . . . . . . . . . . . . L 0011</p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"> TIME_0. . . . . . . . . . . . . I 1010</p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"> TIME_1. . . . . . . . . . . . . I 1030</p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"> ;%Z</p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"> 00 Errors (0000)</p>
</font></i>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font face="宋体" lang="ZH-CN" size=2>由列表文件,可以绘出代码在ROM中的映象图如下:</font></p>
<table BORDER cellspacing=1 bordercolor="#000000" cellpadding=1 width=451>
<tr>
<td width="9%" valign="TOP"> <font face="宋体" lang="ZH-CN" size=2>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">代码
</font></td>
<td width="8%" valign="TOP"> <font face="宋体" size=2>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">01H
</font></td>
<td width="9%" valign="TOP"> <font face="宋体" size=2>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">11H
</font></td>
<td width="9%" valign="TOP"> <font face="宋体" size=2>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">02H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -