Modifiers
When writing MOS assembly code, it's often necessary to refer to a specific byte or short within a larger address, when the exact address is not known until code relaxation or linking. For example, code may need to refer to the low byte of a 16-bit function address:
LDA [the lowest byte in the 16-bit address of QSORT]
However, the address of QSORT
may not be exactly known, until your program has had relaxation and/or linking applied to it. Therefore, the lowest byte of QSORT
won't be known until then as well.
In LLVM land, that operator is referred to as a modifier. The llvm-mos project supports some MOS-specific modifiers, to refer to a specific part of a larger address. If QSORT
refers to a 16-bit address:
LDA #mos16lo(QSORT)
then the lowest byte in the QSORT
address is loaded into the accumulator. Alternatively, a shorthand can be used in the form of:
LDA #<QSORT
The following modifiers are available for your use:
Modifier | Short modifier | Description |
---|---|---|
mos8() |
< |
Forces a symbol to be considered an 8-bit (zero page) address. |
mos16() |
! |
Forces a symbol to be considered a 16-bit (absolute) address. |
mos16lo() |
#< |
The lowest byte in the given 16-bit address. |
mos16hi() |
#> |
The highest byte in the given 16-bit address. |
mos24() |
> |
Forces a symbol to be considered a 24-bit (long) address. |
mos24bank() |
#^ |
The 8-bit bank portion of the given 24-bit address. |
mos24segment() |
The segment 16-bit portion of the given 24-bit address. | |
mos24segmentlo() |
The lowest byte in the segment of the given 24-bit address. | |
mos24segmenthi() |
The highest byte in the segment of the given 24-bit address. |
The short modifiers follow the WDC standard as set out in the 65C816 datasheet.
The assembly parser tries to be smart about what kinds of modifiers can be used for what purposes. For example, mos24segment()
returns a 16-bit address, so you can't do LDA #mos24segment(QSORT)
because the immediate LDA instruction only accepts 8-bit values.
All MOS processors are little endian, so the lowest byte appears at the zeroth position in a 16-bit address.
The above syntax for modifiers only works inside assembly language instructions. If you need to use modifiers in assembly directives, the syntax is instead: .byte address@mos16hi
(or similar).