OFFSET <expression>
None
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.
The following listing shows how the OFFSET directive can be used to access an element of a structure.
6 6 OFFSET 0 7 7 000000 ID: DS.B 1 8 8 000001 COUNT: DS.W 1 9 9 000003 VALUE: DS.L 1 10 10 0000 0007 SIZE: EQU * 11 11 12 12 DataSec: SECTION 13 13 000000 Struct: DS.B SIZE 14 14 15 15 CodeSec: SECTION 16 16 entry: 17 17 000003 CE xxxx LDX #Struct 18 18 000006 8600 LDA #0 19 19 000008 6A00 STA ID, X 20 20 00000A 6201 INC COUNT, X 21 21 00000C 42 INCA 22 22 00000D 6A03 STA 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.
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.