The ORG Directive and Actual Offsets

Exención de responsabilidades de contenido KB retirado

Este artículo se refiere a productos para los que Microsoft ya no ofrece soporte técnico. Por tanto, el presente artículo se ofrece "tal cual" y no será actualizado.

Summary

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

END END



|---------------test2.asm:
code segment public 'code'
assume cs:code
org 100h

PUBLIC _test2
_test2 PROC

push bp
mov bp, sp

pop bp
ret

_test2 ENDP
code ends
END
Propiedades

Id. de artículo: 39441 - Última revisión: 29/10/2003 - Revisión: 1

Comentarios