OFFSET - Create absolute symbols

Syntax
  OFFSET <expression>
  
  
Synonym

None

Description

The OFFSET directive declares an offset section and initializes the location counter to the value specified in <expression>. The <expression> must be absolute and may not contain references to external, undefined or forward defined labels.

Example

The following listing shows how the OFFSET directive can be used to access an element of a structure.

Listing: Example assembly source code

  Abs. Rel.   Loc    Obj. code   Source line
 ----- ----   ------ ---------   -----------

    1    1                               OFFSET 0

    2    2   000000             ID:      DS.B   1

    3    3   000001             COUNT:   DS.W   1

    4    4   000003             VALUE:   DS.L   1

    5    5          0000 0007   SIZE:    EQU   *

    6    6

    7    7                      DataSec: SECTION

    8    8   000000             Struct:  DS.B  SIZE

    9    9

   10   10                      CodeSec: SECTION

   11   11                      entry:

   12   12   000000 98xx xxxx            LD X, #Struct

   13   13   000004 9600 0000            LD D6, #0

         000008 00

   14   14   000009 C640                 ST D6,(ID, X)

   15   15   00000B 9C41                 INC.B (COUNT, X)

   16   16   00000D 36                   INC D6

   17   17   00000E C643                 ST D6,(VALUE, X)

When a statement affecting the location counter other than EVEN, LONGEVEN, ALIGN, or DS is encountered after the OFFSET directive, the offset section is ended. The preceding section is activated again, and the location counter is restored to the next available location in this section. The following listing shows the example where the location counter is changed.

Listing: Example where the location counter is changed

    7    7                      ConstSec: SECTION
    8    8   000000 11          cst1:     DC.B  $11

    9    9   000001 13          cst2:     DC.B  $13

   10   10

   11   11                                OFFSET 0

   12   12   000000             ID:       DS.B   1

   13   13   000001             COUNT:    DS.W   1

   14   14   000003             VALUE:    DS.L   1

   15   15          0000 0007   SIZE:     EQU   *

   16   16

   17   17   000002 22          cst3:     DC.B  $22

In the example above, the cst3 symbol, defined after the OFFSET directive, defines a constant byte value. This symbol is appended to the section ConstSec, which precedes the OFFSET directive.