Saturday 17 November 2012

The ORG Directive

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.