Computer ArchitectureUnit 210 min read
Instruction Set Architecture (ISA) & Instruction Formats: Design, Types & Real-World Use
Unit 2 of Computer Architecture explores how computers execute instructions through ISA design, instruction formats, addressing modes, and their impact on performance. Learn how CPUs decode commands, how data moves, and how modern processors (like those in eSewa or Ncell apps) use these principles to run efficiently.
TAKEAWAYS:
- ISA defines how software interacts with hardware via instructions, formats, and addressing modes.
- Instruction formats (fixed vs. variable length) affect CPU efficiency and complexity.
- Addressing modes (immediate, direct, indirect) determine how operands are accessed.
- Real-world systems (e.g., WhatsApp’s encryption, Ncell’s billing) rely on ISA for speed and security.
- RISC vs. CISC trade-offs explain why smartphones use ARM (RISC) while PCs use x86 (CISC).
- Instruction cycles (fetch-decode-execute) are the heartbeat of CPU operation.
1. What is Instruction Set Architecture (ISA)?
ISA is the contract between hardware and software. It defines:
- The instructions a CPU can execute (e.g.,
ADD,LOAD,JUMP). - The data types it supports (e.g., 8-bit, 16-bit, 32-bit integers).
- The registers available (e.g.,
PC,SP,AX). - The memory addressing methods (e.g., direct, indirect).
Why it matters: Without ISA, programs couldn’t run—it’s the "language" CPUs understand. For example, when you send money via eSewa, the app’s code is compiled into ISA-specific instructions for your phone’s CPU.
classDiagram
class ISA {
+Instructions: ADD, SUB, LOAD, STORE, JUMP
+Data Types: 8/16/32/64-bit integers, floats
+Registers: PC, SP, AX, BX, etc.
+Addressing Modes: Immediate, Direct, Indirect, etc.
}
class CPU {
<<hardware>>
Executes ISA instructions
}
class Program {
<<software>>
Written in high-level code, compiled to ISA
}
Program --> ISA : Compiled To
ISA --> CPU : Executed By2. Instruction Formats: How CPUs Understand Commands
Instructions are encoded in binary but follow a structured format. Two main types:
A. Fixed-Length Instructions (e.g., RISC)
- All instructions occupy the same number of bits (e.g., 32 bits).
- Simplifies decoding (CPU knows where each field starts).
- Example: ARM ISA (used in smartphones) uses 32-bit fixed-length instructions.
B. Variable-Length Instructions (e.g., CISC)
- Instructions vary in size (e.g., 1–15 bytes in x86).
- Allows complex operations in one instruction (e.g.,
MUL AX, BX). - Example: x86 ISA (used in PCs) supports variable-length instructions.
Comparison Table:
| Feature | Fixed-Length (RISC) | Variable-Length (CISC) |
|---|---|---|
| Instruction Size | Uniform (e.g., 32-bit) | Varies (1–15 bytes) |
| Decoding | Faster (simple logic) | Slower (complex parsing) |
| Complexity | Simpler CPU design | More complex CPU |
| Example ISA | ARM, MIPS | x86, x86-64 |
| Use Case | Mobile (low power) | Desktop (flexibility) |
Worked Example: Decoding an ARM Instruction
Consider the ARM instruction:
ADD R1, R2, R3 (Adds R2 and R3, stores result in R1).
In binary (32-bit fixed format):
31-28 | 27-25 | 24-21 | 20-16 | 15-12 | 11-8 | 7-4 | 3-0
-------------------------------------------
0101 | 000 | 001 | 010 | 011 | 000 | 0001
- Opcode (28-24):
010100=ADD - Dest (15-12):
0010=R2 - Src1 (11-8):
011=R3 - Src2 (7-4):
0001=R1
3. Addressing Modes: How CPUs Find Data
Addressing modes determine how operands are specified in an instruction. Common types:
| Mode | Example Instruction | How It Works | Use Case |
|---|---|---|---|
| Immediate | ADD R1, #5 |
Operand is part of the instruction (e.g., #5 means literal 5). |
Constants, loops. |
| Direct | LOAD R1, [0x1000] |
Operand is a memory address (e.g., 0x1000). |
Accessing specific memory. |
| Indirect | LOAD R1, [R2] |
Operand is the content of a register (e.g., R2 holds an address). |
Pointers, dynamic memory access. |
| Register | ADD R1, R2, R3 |
Operands are registers (e.g., R2 + R3 → R1). |
Fast arithmetic. |
| Register Indirect | LOAD R1, [R2, #4] |
Operand is R2 + offset (e.g., R2 + 4). |
Array access. |
| Base + Index | LOAD R1, [R3, R4, #2] |
Operand is R3 + R4 + offset. |
Multi-dimensional arrays. |
Real-World Example: WhatsApp Encryption When WhatsApp encrypts messages, it uses register indirect addressing to:
- Load a key from memory into a register (
LOAD R1, [R5]). - XOR the message with the key (
XOR R1, R1, [R6]). This is faster than direct memory access because registers are closer to the CPU.
stateDiagram-v2
[*] --> Fetch: Instruction from PC
Fetch --> Decode: Opcode + Operands
Decode --> AddressCalc: Determine operand location
AddressCalc --> ReadOperand: From register/memory
ReadOperand --> Execute: Perform operation
Execute --> WriteBack: Store result
WriteBack --> [*]
state AddressCalc {
[*] --> Immediate: Operand is literal
[*] --> Direct: Operand is memory[addr]
[*] --> Indirect: Operand is memory[reg]
[*] --> Register: Operand is reg
}4. Instruction Cycle: The CPU’s Execution Loop
The instruction cycle is how a CPU fetches, decodes, and executes instructions. Steps:
- Fetch: Get the next instruction from memory (address in
PC). - Decode: Determine the instruction type (e.g.,
ADD,JUMP). - Execute: Perform the operation (e.g., arithmetic, memory access).
- Writeback: Store the result (if needed).
With Interrupts (Real-World Example: Ncell Billing System) When a user tops up via Ncell’s app, the CPU handles:
- Normal cycle: Process payment.
- Interrupt: If the SIM card is removed, the CPU jumps to an interrupt handler to log the error.
sequenceDiagram
participant CPU
participant Memory
participant InterruptController
CPU->>Memory: Fetch (PC = 0x1000)
Memory-->>CPU: Instruction (ADD R1, R2, R3)
CPU->>CPU: Decode (ADD)
CPU->>Memory: Read R2, R3
Memory-->>CPU: Values (5, 3)
CPU->>CPU: Execute (5 + 3 = 8)
CPU->>Memory: Write R1 (8)
InterruptController->>CPU: SIM Removed (Interrupt)
CPU->>InterruptController: Acknowledge
CPU->>Memory: Fetch (Interrupt Handler)5. Instruction Types: What CPUs Can Do
Instructions are categorized by function:
| Type | Example (ARM/x86) | Purpose |
|---|---|---|
| Data Transfer | MOV R1, R2, LOAD |
Move data between registers/memory. |
| Arithmetic/Logic | ADD, SUB, AND, OR |
Perform math/logic operations. |
| Control Flow | JMP, CMP, BEQ |
Change execution path (branches, loops). |
| I/O | IN, OUT (x86) |
Read/write from ports (e.g., keyboard, screen). |
| System | HALT, INT |
Manage CPU state (e.g., interrupts, shutdown). |
Worked Example: Calculating Loan Interest (Nepal Bank) A bank’s system uses:
; Load principal (P), rate (R), time (T)
LOAD R1, [P] ; R1 = 100,000 (NPR)
LOAD R2, [R] ; R2 = 5 (5%)
LOAD R3, [T] ; R3 = 1 (year)
; Calculate interest: I = P * R * T / 100
MUL R4, R1, R2 ; R4 = 100,000 * 5 = 500,000
MUL R5, R4, R3 ; R5 = 500,000 * 1 = 500,000
MOV R6, #100 ; R6 = 100
DIV R7, R5, R6 ; R7 = 500,000 / 100 = 5,000 (interest)
STORE [I], R7 ; Save to memory
6. Real-World Applications
A. eSewa: Secure Transactions
- Uses cryptographic instructions (e.g.,
AES-ENCRYPT) in fixed-length ISA (ARM). - Addressing modes: Indirect addressing to load keys from secure memory.
B. Pathao: Ride Matching
- Control flow: Branches (
JMP) to handle ride requests vs. cancellations. - Data transfer:
LOAD/STOREfor GPS coordinates.
C. NTC: Traffic Light Control
- Interrupts: Sensors trigger CPU to switch lights (
INT→JMPto handler). - Timers:
TIMER_LOADinstructions manage green/red durations.
Exam Tip
ISA vs. Microarchitecture:
- ISA = what instructions exist (e.g.,
ADD). - Microarchitecture = how they’re implemented (e.g., pipelining).
- Exam trick: Questions often ask for ISA examples (e.g., "List 3 ARM instructions").
- ISA = what instructions exist (e.g.,
Instruction Formats:
- Draw a 32-bit ARM instruction and label fields (opcode, registers).
- Compare fixed (RISC) vs. variable (CISC) in a table.
Addressing Modes:
- Memorize 5 modes and give one example each (e.g.,
LOAD R1, [R2]for indirect). - Common mistake: Confusing direct (
LOAD [addr]) vs. indirect (LOAD [reg]).
- Memorize 5 modes and give one example each (e.g.,
Instruction Cycle:
- Draw the state diagram with interrupts (fetch-decode-execute-writeback).
- Explain PC (Program Counter) updates in jumps.
Real-World Links:
- Tie eSewa/Khalti to encryption instructions.
- Tie Ncell billing to arithmetic/logic instructions.
- Tie traffic lights to interrupts and timers.
Final Checklist for Full Marks: ✅ Define ISA and its components (instructions, registers, addressing). ✅ Compare fixed vs. variable-length instructions with examples. ✅ Explain 5 addressing modes with ARM/x86 examples. ✅ Draw the instruction cycle (with interrupts). ✅ Link to real systems (eSewa, Ncell, Pathao). ✅ Solve a worked example (e.g., loan calculation in assembly).
Based on the TU BSc CSIT syllabus for Computer Architecture (CSC213), unit 2.
Discussion
Loading…