47/317
3 - Programming a microcontroller
quantity production, the microcontroller includes a masked ROM programmed by the device
manufacturer and that cannot be altered afterwards.
3.1.2.1 Assembly language
Assembly language is merely a set of mnemonics that duplicates each instruction in a more
legible way, to help writing the programs. Machine language is just a series of numbers that
obeys a certain code to indicate to the core which instruction to execute and which data to use.
Assembly language provides acronyms that are easier to remember. The following example
shows an excerpt from an assembly listing. The first two columns show numeric data, which
represent the addresses of the instructions and the machine-language code. The Source line
column shows the machine code in mnemonic language. It is obvious that, provided one has
learned that
ld
means the instruction Load, and that, of the two operands of this instruction,
the destination operand comes first, it is easy to understand the first lines of source code as
documented in the comment column:
Loc
Obj. code
Source line
Comment
------ ---------
-----------
-------------
000000 A6FF
ld A, #$FF
; load accumulator with immediate
data FF (hex)
000002 AE64
ld X, #100
; load X register with value 100
000004 F7
loop: ld (X), A
; load location pointed to by X
with contents of A
000005 5A
dec X
; decrement X register
000006 26FC
jrne loop
; jump to label loop if X not equal
to zero
This short program is a loop that fills memory addresses 100 to 1 (decimal) inclusive with the
value FF hex.
Programming in assembly language involves using a text editor to write a text file that obeys
the syntax and conventions of the specific assembler that is to be used. It should be noted that
assembly language is not standardized in any way, for two reasons:
The instruction set changes from one processor to another
For a specific processor or microcontroller, software tool sets from different suppliers each
have their own syntax, although two source files written for two different tool sets may seem
very close.
Thus, to write an assembly language source file, the programmer must first know which proc-
essor or microcontroller will be chosen for his project, then which software tool set he will use.
Then, he has to learn both the characteristics of the processor's instruction set (instruction
types, addressing modes, etc.) and the specific syntax of the assembler he will use.