CSC 382 · Computer Architecture 1
Our notes
2 min readWhat assembly language is
A symbolic form of machine language: each statement usually becomes one machine instruction. Mnemonics replace opcodes (ADD for 0001), labels replace addresses, and the assembler translates.
Statement format
label: opcode operand(s) ; comment
LOOP: ADD COUNT ; add the counter to AC
Directives (pseudo-operations)
Instructions to the assembler, not to the CPU:
- ORG 100: start assembling at address 100.
- DATA, DW, DB, WORD: reserve and initialise storage.
- EQU: give a name to a constant (MAX EQU 50).
- END: end of the source.
Worked example: summing an array (simple accumulator machine)
Sum five numbers stored from address TABLE.
ORG 100
LOAD ZERO
STORE SUM
LOAD N
STORE COUNT
LOOP: LOAD SUM
ADD TABLE(X) ; indexed by X
STORE SUM
INC X
DEC COUNT
JNZ LOOP ; repeat while COUNT is not zero
HALT
N: DATA 5
ZERO: DATA 0
SUM: DATA 0
COUNT: DATA 0
TABLE: DATA 12, 7, 30, 5, 6
After the run SUM = 12 + 7 + 30 + 5 + 6 = 60 (with X starting at 0).
Why learn it
- To understand what compilers produce and why some code is fast.
- For device drivers, boot code, embedded systems with tiny memories, and reverse engineering and security work.
- Some instructions (enable interrupts, special registers) are reachable only from assembly.
Macros
A macro names a group of statements that the assembler copies in wherever it is used, with parameters:
SWAP MACRO A, B → expands to the loads and stores that swap A and B.
Unlike a subroutine, a macro has no call overhead but makes the program longer.
High-level against assembly
| High-level | Assembly | |
|---|---|---|
| Portability | any machine with a compiler | one family of CPU |
| Speed of writing | fast | slow |
| Control of hardware | limited | complete |
| Errors | fewer | more |
Exams usually ask
- Explain the format of assembly statements; distinguish instructions from directives.
- Write a short assembly program (sum, maximum, loop).
- Compare macros with subroutines.
Common mistake
Expecting directives to produce machine code. ORG, EQU and END tell the assembler what to do and generate no instructions; DATA reserves storage.
Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.
No reading links here yet
Our team adds free books, videos and practice for each topic, and opens every link before it goes up.