Probably the easiest way to describe the syntax of the assembly language is to give an example:
* HC11 example program
org $f800 * tell the assembler to start generating code at $f800
fred
ldaa #$12 * load $12 into accumulator A
george inca * add one to A
staa $24 * store A out to address $24
bra george * infinite loop
end fred * tell assembler to stop here
OK, so what do we see here?
Let's look at some of the lines of example program in more detail:
* HC11 example program
* must be in the first
column.
org $f800 * tell the assembler to start generating code at $f800
$f800. This is the beginning of the
on-chip EEPROM.
fred
ldaa #$12 * load $12 into accumulator A
# means) and to load
$12 into the A accumulator.
george inca * add one to A
george, while
the instruction is inca. This instruction takes no
operands.
staa $24 * store A out to address $24
$24 — this is called direct
addressing. Note: this is the single most confusing part of
the syntax of assembly language programming: in high level
languages, whether we use direct or immediate addressing is
determined by context. In assembly code, we have to say which we
mean! An astonishing number of bugs are caused by doing a load with
direct addressing when immediate was desired.
bra george * infinite loop
for loops: we have to
implement them by hand.
end fred * tell assembler to stop here
Last time, we looked at an instruction, and saw how to decode and
execute it. This time, let's look at how to assemble an
instruction. We'll use the staa $24 as an
example.
staa is on page 19 of
the Reference Guide, and Page 579 of the Reference Manual. In both
cases, you can see that the op code is 97, and the op
code is one byte of address. So the instruction assembles to 97 24.