Assembly language is a low-level language where each statement maps to one machine code instruction. It gives direct control of the processor and shows what high-level code really turns into.
Instruction format and addressing modes
An assembly instruction has an opcode and usually an operand. The Cambridge 9618 instruction set uses a single accumulator, ACC, and an index register, IX.
Common instructions:
| Instruction | Meaning |
|---|---|
| LDM #n | Load the number n into ACC (immediate) |
| LDD addr | Load the contents of addr into ACC (direct) |
| LDI addr | Load using the address stored at addr (indirect) |
| LDX addr | Load from addr + IX (indexed) |
| STO addr | Store ACC in addr |
| ADD addr | Add contents of addr to ACC |
| SUB addr | Subtract contents of addr from ACC |
| INC / DEC reg | Add or subtract 1 |
| CMP addr | Compare ACC with contents of addr |
| JMP addr | Jump to addr |
| JPE addr / JPN addr | Jump if last comparison was equal / not equal |
| IN / OUT | Input or output a character |
| END | Stop the program |
Addressing modes: immediate (value is in the instruction), direct (instruction gives the address), indirect (address holds another address), indexed (address plus IX), and relative.
Writing a program
Labels name addresses so you do not count them by hand. This program adds 5 and 7 and stores the result:
LDM #5
ADD value
STO result
END
value: 7
result: 0
Here ADD value adds the number stored in memory at value to ACC. Stored data is declared after END.
A loop that counts from 0 to 4:
LDM #0
STO count
loop: LDD count
INC ACC
STO count
CMP limit
JPN loop
END
count: 0
limit: 5
CMP sets a flag; JPN jumps back to loop while the values are not equal. Tracing it with a table of ACC and count per step is a standard exam task.
Assemblers
An assembler translates assembly into machine code. A two-pass assembler reads the program once to build a table of label addresses, then a second time to produce the machine code with the real addresses filled in. Assembly is used for device drivers, embedded systems and speed-critical code, but it is hard to write, not portable between processor types, and slow to develop.
Check your understanding
What does LDM #5 do?
- Loads the contents of address 5
- Loads the value 5 into ACC
- Stores 5 in memory
- Jumps to address 5
Answer: Loads the value 5 into ACC. The # marks an immediate value.
Which addressing mode adds IX to the operand address?
- Immediate
- Direct
- Indexed
- Indirect
Answer: Indexed. It is useful for stepping through arrays.
What is the job of an assembler?
- Run the program line by line
- Translate assembly language into machine code
- Compress files
- Debug the CPU
Answer: Translate assembly language into machine code. It also resolves labels to addresses.
Why is assembly language not portable?
- It only uses letters
- Its instructions are specific to one processor family
- It cannot use memory
- It has no loops
Answer: Its instructions are specific to one processor family. Each CPU has its own instruction set.
