Assembly language and addressing modes
| English | Chinese | Pinyin |
|---|---|---|
| machine code | 机器码 | jī qì mǎ |
| assembly language | 汇编语言 | huì biān yǔ yán |
| addressing modes | 寻址方式 | xún zhǐ fāng shì |
| mnemonics | 助记符 | zhù jì fú |
| assembler | 汇编器 | huì biān qì |
| symbol table | 符号表 | fú hào biǎo |
| forward references | 前向引用 | qián xiàng yǐn yòng |
| instruction set | 指令集 | zhǐ lìng jí |
| immediate | 立即寻址 | lì jí xún zhǐ |
| indirect | 间接寻址 | jiàn jiē xún zhǐ |
| indexed | 变址寻址 | biàn zhǐ xún zhǐ |
Talking to the processor
- The CPU runs machine code 机器码 — raw bit patterns.
- Assembly language 汇编语言 is a readable version of it, one instruction at a time.
- We also meet the addressing modes 寻址方式 that say where to find an operand.
Machine code and assembly
- Machine code is bit patterns, specific to one architecture — what the CPU actually runs.
- Assembly language is a readable form with one instruction per machine instruction, written with mnemonics 助记符 like
LDD,ADD,JMP. - An assembler 汇编器 translates assembly into machine code.

A modern CPU: the whole processor is one small chip
Assembly language is:
Assembly uses mnemonics and maps one-to-one to machine code; an assembler translates it.
The two-pass assembler
- A two-pass assembler reads the source twice:
- Pass 1 builds a symbol table 符号表 — recording the address of each label (like
LOOP:); no code yet. - Pass 2 generates the code — and when an instruction refers to a label (
JMP LOOP), it looks the address up in the symbol table. - Two passes are needed to handle forward references 前向引用 (a jump to a label defined later).

An assembler turns mnemonics into machine-code bit patterns
How a two-pass assembler works
Step through it. The assembler reads your code twice: pass 1 just finds where every label lives, so pass 2 can fill in the addresses — that is how a jump to a label defined later still works.
What does pass 1 of a two-pass assembler do?
Pass 1 records where each label is (the symbol table); pass 2 then generates code, using the table to resolve label references.
Put the two-pass assembler's work in order.
Pass 1 finds all the labels first, so pass 2 can resolve even a jump to a label defined later.
Why does the assembler need two passes?
A jump may target a label that appears later in the source; pass 1 finds all labels first so pass 2 can resolve them.
The instruction set 指令集
- A small generic set groups into:
- data movement (
LDD,LDM,STO,MOV), arithmetic (ADD,SUB,INC,DEC), - logic/bit (
AND,OR,XOR,LSL,LSR), compare & branch (CMP,JMP,JPE,JPN), I/O (IN,OUT), andEND. - To trace a program, make a table of the PC, ACC, index register, variables and flags, and update it after each instruction until
END.
Addressing modes
| Mode | Where the operand is | Example |
|---|---|---|
| immediate 立即寻址 | the value is in the instruction | LDM #10 |
| direct | the instruction holds an address; use the value there | LDD 200 |
| indirect 间接寻址 | the address holds another address, which holds the data | LDI 200 |
| indexed 变址寻址 | effective address = address + index register (arrays) | LDX 100 |
| relative | the address is relative to the PC | — |
- Instruction groups include arithmetic operations; the modes of addressing decide how the operand is found.
In immediate addressing (e.g. LDM #10), the operand is:
Immediate addressing uses the literal value in the instruction (here, 10).
Indexed addressing is most useful for:
The effective address is base address + index register, so increasing the index walks through an array.
Match each addressing mode to its meaning.
Immediate = value; direct = address of the value; indirect = address of an address; indexed = base + index.
You've got it
- machine code = bit patterns; assembly = mnemonics, 1:1, translated by an assembler
- a two-pass assembler builds a symbol table (pass 1), then code (pass 2) — to handle forward references
- immediate (value in instruction), direct (address), indirect (address of an address), indexed (address + index register, for arrays)