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:
then the lowest byte in the
QSORT address is loaded into the accumulator.
The following modifiers are available for your use:
||Forces a symbol to be considered an 8-bit (zero page) address.|
||The lowest byte in the given 16-bit address.|
||The highest byte in the given 16-bit address.|
||The 8-bit bank portion of the given 24-bit address.|
||The segment 16-bit portion of the given 24-bit address.|
||The lowest byte in the segment of the given 24-bit address.|
||The highest byte in the segment of the given 24-bit address.|
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.
Much existing MOS code depends on the less-than operator
< and the greater-than operator
> as shorthand for the mos16lo() and mos16hi() functions, respectively. This functionality has been added to MOSAsmParser.cpp, so that you can use either representation in your own programs.
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 [email protected] (or similar).