6. The Assembler

BBC BASIC for the ATOM includes a two-pass assembler using standard 6502 mnemonics. This is similar to the ATOM BASIC assembler in many ways. The following brief description assumes the user is familiar with it.

A section of assembler is introduced in BASIC between [ and ]. The [ is often followed by an OPT statement, which controls the assembler listing and error messages (see under keyword OPT). P% is used as the pseudo-program counter and holds the address to which the code is assembled. It should be set accordingly for each pass, for example:

10 DIMMC%l00
20 FORI%=OTO3STEP3
30 P%=MC%
40 [OPTI%
50 assembler statements
60 ]
70 NEXT I%

The same rules apply to the names of labels and symbols as to BASIC variables. To define a label, it should be preceded by '.', and it should be separated from the following instruction or further label by one or more spaces. The '. ' is not used when the label appears in operand context. There are no EQ or DST operations and the symbol-defining functions of these are handled by BASIC assignments outside the assembler section. The instruction mnemonics are the standard three-letter 6502 ones (as in the ATOM assembler). The form of the operand field following the instruction mnemonic indicates the addressing mode as follows:

Operand
Field
Addressing
Mode
blank implied
A accumulator
#b immediate
d absolute
d,X absolute indexed by X
d,Y absolute indexed by Y
(d) absolute indirect
(d),Y indexed indirect
(d,X) indirect indexed

The symbols b and d represent legal expressions in BASIC which are evaluated during assembly to provide the operand value. The expression b must yield a value between 0 and 255 or an error is generated. The expression d can do so, in which case a zero-page instruction will be assembled if appropriate and available. There is no mechanism for explicitly selecting zero-page or absolute instructions. Note that if errors are suppressed during the first pass, the value of P% will be assembled in place of any undefined operand. When assembling other than to zero-page, symbols in expressions referring to zero-page should be defined before they are used so that the assembler can use zero-page instructions on the first pass.

More than one statement can be put on a line by separating them with ': ' . Beware of using ':' in string constants in expressions, e.g. #ASC":" - this will confuse the assembler. The \ character introduces a comment up to the next ':' character.

Next Chapter