一 ORG指令
ORG是Origin的缩写:起始地址,源。在汇编语言源程序的开始通常都用一条ORG伪指令来实现规定程序的起始地址。如果不用ORG规定则汇编得到的目标程序将从0000H开始。例如:
ORG 2000H
START:MOV AX,#00H
汇编语言源程序中若没有ORG伪指令,则程序执行时,指令代码被放到自由内存空间的CS:0处;若有ORG伪指令,编译器则把其后的指令代码放到ORG伪指令指定的偏移地址。两个ORG伪指令之间,除了指令代码,若有自由空间,则用0填充。
预处理–>编译–>汇编–>链接,这是高级语言的编译全过程。对于纯汇编,就只有汇编和链接两个步骤。
org指令是链接时使用的,不是汇编那一步使用的。即不是cpu的一条指令,而是给编译器看的伪指令。
在51单片机、x86 dos、win32 exe中实现都有差异。
以最简单的51单片机为例,编译器最终链接生成HEX文件,再烧录到51的rom中去。单片机很简单,没有x86的分段、分页,启动就是从rom的0x0的位置开始执行。同时0x30H位置开始存放中断向量,
所以单片机程序一般开头就是:
ORG 0000H
AJMP MAIN
ORG 0030H
这里的ORG 0000H指令,使得程序链接成HEX文件时,AJMP MAIN这条指令的机器码就在HEX文件的0x0位置。这是链接器的工作。
二 英文版
ORG用来自定义程序的起始位置,从而达到control section和 REDFEIN portions的目的
If a control section has not been previously established, ORG initiates an unnamed (private) control section.
>>-+--------+--ORG---------------------------------------------->
'-symbol-'
>--+--------------------------------------------+--------------><
'-expression-+-----------------------------+-'
'-,-+-boundary--+---------+-+-'
| '-,offset-' |
'-,--offset-------------'
这玩意内部可以分成如上图所示
symbol
Is one of the following:
- An ordinary symbol
- A variable symbol that has been assigned a character string with a value
that is valid for an ordinary symbol - A sequence symbol。
If symbol denotes an ordinary symbol, the ordinary symbol is defined with the value that the location counter had before the ORG statement is processed.
expression
Is a relocatable expression, the value of which is used to set the location counter. If expression is omitted, the location counter is set to the next available location for the current control section.
boundary
Is an absolute expression that must be a number that is a power of 2 with a range from 2 (halfword) to 4096 (page). If boundary exceeds the SECTALGN value, message ASMA500E is issued. This message is not issued if the section being processed is a Reference Control Section (DSECT, DXD, or COM).
boundary must be a predefined absolute expression whose value is known at the time the ORG statement is processed.
If the boundary operand is greater than 16, the GOFF option must be specified in addition to the SECTALGN option.
offset
Any absolute expression
If boundary or offset are provided, then the resultant location counter is calculated by rounding the expression up to the next higher boundary and then adding the offset value.
origin csect
ds 235x Define 235 bytes
org origin,,3 Move location counter back to start + 3
org *,8 Align on 8 byte boundary
org *,8,-2 Align to 8 byte boundary -2 bytes
translate dc cl256' ' Define aligned translate table
org translate+c'a'
dc c'ABCDEFGHI'
org translate+c'j'
dc c'JKLMNOPQR'
org translate+c's'
dc c'STUVWXYZ'
org translate+c'A'
dc c'ABCDEFGHI'
org translate+c'J'
dc c'JKLMNOPQR'
org translate+c'S'
dc c'STUVWXYZ'
org ,
end
下面是上面那个程序的解析
Source Module │ Object Code
─────────────────────────────────────────────────────┼────────────────────────
│
FIRST START 0 │
. │
. │
1 TABLE DC XL256'0' │ TABLE (in Hex)
2 ORG TABLE+0 │ +0 ┌────┐
┌ DC C'0' 3 │ │ F0 │
│ DC C'1' │ │ F1 │
│ . │ │ . │
│ . │ │ . │
│ ORG TABLE+13 │ +13 │ . │
│ DC C'D' │ │ C4 │
│ DC C'E' │ │ C5 │
│ . │ │ . │
│ . │ │ . │
4 ─┤ ORG TABLE+C'D' │ │ . │
│ DC AL1(13) │ +196 │ 13 │
│ DC AL1(14) │ │ 14 │
│ . │ │ . │
│ . │ │ . │
│ ORG TABLE+C'0' │ +240 │ . │
│ DC AL1(0) │ │ 00 │
│ DC AL1(1) │ │ 01 │
│ . │ │ │
└ . │ +255 └────┘
ORG │
5 GOON DS 0H │
∧ . │
TABLE+256 . │
TR INPUT,TABLE │
. │
. │
INPUT DS CL20 │
. │
. │
END │
标签:汇编语言,DC,指令,org,ORG,boundary,translate,TABLE
From: https://blog.csdn.net/CNMBZY/article/details/136954720