The ORG Directive and Actual Offsets

Zastarané vyhlásenie týkajúce sa obsahu databázy KB

Tento článok sa týka produktov, ku ktorým už spoločnosť Microsoft neposkytuje technickú podporu. Preto sa tento článok ponúka tak, „ako je“, a už nebude aktualizovaný.


The ORG directive in MASM does not necessarily produce an actual offset that matches the offset specified by "ORG XXX". For example, if you use "ORG 100h" in your program, the following code will not always begin at the 100h offset relative to the start of the segment.

When you are using a .COM source file and there is only one module, the "ORG 100h" will result in an actual offset of 100h for the code that follows the ORG statement. This behavior also occurs with segments with AT combine type (in which case segments are not combined by the linker, and no data or code is defined).

However, if you have multiple modules and/or you are not dealing with a .COM source file, the "ORG 100h" produces an actual offset, which is somewhat greater than 100h.

This behavior occurs because the linker, in these circumstances, will do some padding that you have no control over.

More Information

In the following illustration (which deals with the source modules below), note that the ORG instruction increments the local offset by 100h, resulting in the offset of the PUSH instruction in example2 being 100h (that's what it would report in the listing file). However, when these modules are linked, all the portions of segment code are concatenated. Thus, EXAMPLE2.asm:code:100h is converted into code:113h. The order of concatenation is the order of linking.

The following example illustrates the scenario:

     Actual                      Offset
offset from start
from of segment
code code in module
------- ---------------
0117 | ret | 0105
0116 | pop | 0103 test2.asm
0114 | mov | 0101
0113 | push | 0100
0013 | org | 0000
0012 | ret | 0004
0011 | pop | 0003 test1.asm
000F | mov | 0001
000E | push | 0000
000C | int | 000C
0009 | mov | 0009 testmain.asm
0006 | call | 0006
0003 | call | 0003
0000 | mov | 0000
segment code

|---------------testmain.asm: |---------------test1.asm:
code segment public 'code' PUBLIC _test
assume cs:code code segment public 'code'
assume cs:code
mov ax, 0a0ah _test proc

extrn _test:proc push bp
extrn _test2:proc mov bp, sp

call _test pop bp
call _test2 ret

mov ax, 4c00h _test ENDP
int 21h code ends
code ends


code segment public 'code'
assume cs:code
org 100h

PUBLIC _test2
_test2 PROC

push bp
mov bp, sp

pop bp

_test2 ENDP
code ends

ID článku: 39441 – Posledná kontrola: 29. 10. 2003 – Revízia: 1