Machine code is just binary, which is hard for people to write and read. Assembly language replaces each binary opcode with a short mnemonic and lets you name memory locations with labels. Learn the 9618 instruction set, its groups, and how a two-pass assembler turns it into machine code.
Machine code is the binary instructions a processor executes directly. Assembly language is a low-level language that uses mnemonics (such as LDD and ADD) for opcodes and labels for addresses; each assembly instruction usually translates into one machine code instruction, and both are specific to one processor's instruction set. An assembler translates it. A two-pass assembler needs two passes because of forward references: pass 1 reads the code, allocates addresses and builds a symbol table of labels and their addresses; pass 2 uses the symbol table and the opcode table to generate the object code.
Load a program in the lab and run it: each line is one instruction, made of an opcode and (usually) an operand. That is exactly one machine code instruction.
Assembly language is not machine code. It must still be translated, by an assembler, before the processor can execute it.
These are the instructions you will meet in 9618 assembly questions, as printed in the syllabus. All questions assume one general purpose register, the accumulator (ACC); IX is the index register. Learn which group each instruction belongs to.
| Group | Opcode and operand | Explanation |
|---|---|---|
| Data movement | LDM #n | Immediate addressing. Load the number n to ACC |
| LDD <address> | Direct addressing. Load the contents of the location at the given address to ACC | |
| LDI <address> | Indirect addressing. The address to be used is at the given address. Load the contents of this second address to ACC | |
| LDX <address> | Indexed addressing. Form the address from <address> + the contents of the index register. Copy the contents of this calculated address to ACC | |
| LDR #n | Immediate addressing. Load the number n to IX | |
| MOV <register> | Move the contents of the accumulator to the given register (IX) | |
| STO <address> | Store the contents of ACC at the given address | |
| Input and output | IN | Key in a character and store its ASCII value in ACC |
| OUT | Output to the screen the character whose ASCII value is stored in ACC | |
| Arithmetic | ADD <address> | Add the contents of the given address to the ACC |
| ADD #n/Bn/&n | Add the number n to the ACC | |
| SUB <address> | Subtract the contents of the given address from the ACC | |
| SUB #n/Bn/&n | Subtract the number n from the ACC | |
| INC <register> | Add 1 to the contents of the register (ACC or IX) | |
| DEC <register> | Subtract 1 from the contents of the register (ACC or IX) | |
| Unconditional jump | JMP <address> | Jump to the given address |
| Conditional jump | JPE <address> | Following a compare instruction, jump to <address> if the compare was True |
| JPN <address> | Following a compare instruction, jump to <address> if the compare was False | |
| Compare | CMP <address> | Compare the contents of ACC with the contents of <address> |
| CMP #n | Compare the contents of ACC with number n | |
| CMI <address> | Indirect addressing. The address to be used is at the given address. Compare the contents of ACC with the contents of this second address | |
| Other | END | Return control to the operating system |
A label is written before an instruction or a data item, followed by a colon, for example LOOP: LDD COUNT or COUNT: 4. <address> can be an absolute address (such as 112) or a symbolic address (a label such as COUNT). The bit manipulation instructions (AND, OR, XOR, LSL, LSR) are covered in the last lesson of this topic.
CMP only compares: it does not change the accumulator. It sets the result that the next JPE or JPN uses.
Four quick checks. Each correct answer earns XP and records this skill on your profile.
What is the relationship between assembly language and machine code?
In the lab, which group does JPN belong to?
What does pass 1 of a two-pass assembler produce?
What does the instruction OUT do?
A label can be used before the line where it is defined (a forward reference). On a single read, the assembler would not yet know that label's address, so it reads the program twice.
| Pass 1 | Pass 2 |
|---|---|
| Reads the source code one line at a time. Removes comments and white space. Allocates an address to each line, using a location counter. Adds each label to the symbol table with its address; a label that is used before it is defined is added and its address filled in when the definition is reached. | Reads the source code one line at a time again. Looks up each opcode in the opcode table to get its binary code. Replaces each symbolic address with its absolute address from the symbol table. Generates the object code (machine code) and reports any errors, such as a label that was never defined. |
100 START: LDM #0 101 STO TOTAL 102 LOOP: LDD TOTAL 103 ADD NUM 104 STO TOTAL 105 LDD COUNT 106 DEC ACC 107 STO COUNT 108 CMP #0 109 JPN LOOP 110 END 111 NUM: 5 112 COUNT: 4 113 TOTAL: 0
Do not say pass 1 "translates" the program. Pass 1 builds the symbol table; the object code is generated in pass 2.
Unlocks once the four checks above are done. Worth more XP, written to AS Paper 1 and Paper 2 standard.
Why does an assembler need two passes?
Which instruction is in the data movement group?
Which task is carried out during pass 2?
What does LDR #5 do?
This skill is now recorded on your profile. Keep the chain going.