Assembly Language (Copy)
Cheat Sheet: A Level Computer Science – Assembly Language, Machine Code & Addressing Modes
1. Relationship Between Assembly Language and Machine Code
| Assembly Language | Machine Code |
|---|---|
Human-readable mnemonics (e.g., LDM #5) |
Binary-coded instructions (e.g., 0001 0101) |
| Easier to read and write | Executed directly by the CPU |
| One-to-one mapping with machine instructions | Directly manipulates hardware |
- Assembler: Converts assembly language to machine code.
- Each instruction in assembly corresponds to a specific binary opcode and operands.
2. Two-Pass Assembler Process
Pass 1:
- Scans the program to:
- Collect labels and their corresponding addresses
- Builds a symbol table
Pass 2:
- Converts instructions to machine code:
- Uses symbol table for label resolution
- Replaces symbolic addresses with actual addresses
3. Instruction Groups
| Group | Examples |
|---|---|
| Data Movement | LDM, LDD, LDI, LDX, LDR, MOV, STO |
| Input/Output | IN, OUT |
| Arithmetic | ADD, SUB, INC, DEC |
| Compare | CMP, CMI |
| Unconditional Jump | JMP |
| Conditional Jump | JPE, JPN |
4. Addressing Modes
| Mode | Syntax | Description |
|---|---|---|
| Immediate | #n, Bn, &n |
Operand is the actual value. E.g., LDM #5 loads 5 directly into ACC |
| Direct | <address> |
Address points directly to the memory location. E.g., LDD 100 loads data from address 100 |
| Indirect | <address> |
Address points to another address. E.g., LDI 100 uses value at address 100 as pointer |
| Indexed | <address> + IX |
Final address = <address> + contents of Index Register. E.g., LDX TABLE |
| Relative | (used with jumps) | Address offset from current instruction (not explicitly used in this assembly set) |
5. Common Assembly Instructions
| Opcode | Function |
|---|---|
LDM #n |
Load value n directly to ACC |
LDD addr |
Load from address addr to ACC |
LDI addr |
Load from the address stored at addr |
LDX addr |
Load from address addr + IX |
LDR #n |
Load value n to IX |
MOV IX |
Copy ACC to IX |
STO addr |
Store ACC at address addr |
ADD addr/#n/Bn/&n |
Add to ACC from address or immediate |
SUB addr/#n/Bn/&n |
Subtract from ACC from address or immediate |
INC ACC/IX |
Increment register by 1 |
DEC ACC/IX |
Decrement register by 1 |
JMP addr |
Unconditional jump to address |
CMP addr/#n |
Compare ACC with value from address or immediate |
CMI addr |
Indirect compare using pointer at addr |
JPE addr |
Jump if compare is True |
JPN addr |
Jump if compare is False |
IN |
Take keyboard input (ASCII) into ACC |
OUT |
Output character in ACC |
END |
Terminate program |
6. Tracing Assembly Programs
- Step through line-by-line
- Track changes to:
- PC (Program Counter)
- ACC (Accumulator)
- IX (Index Register)
- Memory
- Update values as instructions execute
- Interpret results based on compare and jump conditions
7. Symbols and Notation
| Symbol | Meaning |
|---|---|
#n |
Denary literal (immediate) |
Bn |
Binary literal |
&n |
Hexadecimal literal |
ACC |
Accumulator |
IX |
Index Register |
<address> |
Absolute or symbolic memory address |
