Computer Organization
Machine Instructions
Own the fetch–decode–execute cycle and CPU time = IC × CPI × T_clock before diving into cache and pipeline maths.
GATE CSE machine instructions — formats, instruction cycle, registers, endianness, CPU time equation, RISC/CISC, with samples and drills.
Learning outcomes
- Describe instruction formats and the full instruction cycle with key registers
- Name PC, IR, MAR/MDR, GPRs, and status flags and state what each holds
- Apply the CPU performance equation and speedup in NATs without unit mistakes
- Contrast RISC/CISC, accumulator vs GPR machines, and endianness at GATE depth
What an instruction is
- An instruction is a binary word the CPU fetches and executes. It always has an opcode (what to do) and usually operand fields (registers, immediates, or address fields).
- Instruction format = layout of fields inside the word. GATE cares that you can name fields and know which field is the address vs the value.
- Fixed-length formats (common in RISC): every instruction is the same size → easy fetch alignment and pipelining. Variable-length formats (common in CISC): denser code, harder decode.
- Number of addresses in the format: 3-address (R1 ← R2 op R3), 2-address (dest also a source), 1-address (accumulator machines), 0-address (stack machines).
- Opcode width limits how many distinct operations the ISA can encode; wider opcodes or escape prefixes appear in CISC designs.
| Style | Typical operands | GATE cue |
|---|---|---|
| 3-address | Rd, Rs1, Rs2 | RISC-like GPRs |
| 2-address | Rd/Rs, Rs2 | Dest overwritten |
| 1-address | Acc + memory/reg | Accumulator ISA |
| 0-address | Stack top(s) | Push/pop ALU |
Worked example
Problem. Why do many RISC ISAs prefer fixed 32-bit instructions?
Solution. Uniform size simplifies fetch (PC += 4), decode, and pipeline stage balance; variable length needs alignment logic and multi-cycle fetch for long ops.
Instruction cycle & key registers
- Classic cycle: fetch → decode → execute → (memory access) → write-back. Multi-cycle CPUs spend one or more clocks per step; pipelined CPUs overlap steps across instructions.
- Fetch: place PC on the address bus, read Mem[PC] into IR, then advance PC to the next instruction (often PC ← PC + instruction_size).
- Decode: control unit interprets opcode/fields and sets up datapath muxes, ALU op, and register enables.
- Execute: ALU computes, or a branch target is calculated, or an effective address is formed.
- Memory / write-back: load/store uses MAR/MDR; results (and flags) are written to the register file.
- PC = next instruction address. IR = current instruction bits. MAR = memory address for a data/instruction access. MDR (or MBR) = data to/from memory. Flags (Z, N, C, V) reflect ALU outcomes for branches.
Formulas to remember
-
After fetch (fixed size S): PC ← PC + S -
Fetch uses Mem[PC] → IR
| Stage | What happens | Key register / unit |
|---|---|---|
| Fetch | Read instruction from memory | PC, IR, MAR/MDR |
| Decode | Interpret opcode / fields | Control unit |
| Execute | ALU / branch / EA calc | ALU, flags |
| Memory | Load/store data if needed | MAR, MDR |
| Write-back | Store result / update flags | Register file |
Worked example
Problem. During fetch, which register ends up holding the instruction bits?
Solution. IR (Instruction Register). PC held the address; after a successful fetch IR holds the word.
CPU performance equation
- CPU time = IC × CPI × T_clock. IC = dynamic instruction count (how many instructions actually executed). CPI = average cycles per instruction. T_clock = clock cycle time.
- Clock frequency f = 1 / T_clock. If the clock is 2 GHz, T_clock = 0.5 ns. Always convert MHz/GHz before multiplying.
- Improving any factor helps: fewer instructions (better compiler/ISA), lower CPI (better pipeline/cache), or faster clock (technology) — but raising clock can raise CPI if the pipeline deepens.
- Speedup = T_old / T_new. If a change cuts time from 10 s to 4 s, speedup = 2.5×.
- MIPS ≈ clock_rate / (CPI × 10^6) is a rough throughput metric. GATE distractors often offer MIPS when the stem asks for CPU time — recompute with IC×CPI×T_clock.
- Weighted CPI: if classes of instructions have different CPIs, CPI_avg = Σ (freq_i × CPI_i).
Formulas to remember
-
CPU time = IC × CPI × T_clock -
T_clock = 1 / f -
Speedup = T_old / T_new -
MIPS ≈ f / (CPI × 10^6) (rough) -
CPI_avg = Σ (fraction_i × CPI_i)
Worked example
Problem. IC=10^6, CPI=2, clock=1 GHz. CPU time?
Solution. T_clock = 1 ns = 10^{−9} s. Time = 10^6 × 2 × 10^{−9} = 2×10^{−3} s = 2 ms.
RISC, CISC, endianness & architectures
- RISC: simple ops, load/store (memory only via load/store), many GPRs, often fixed-length instructions — easier pipelines.
- CISC: richer/complex instructions that may touch memory as operands, variable length, historically microcoded — denser assembly, harder decode.
- Accumulator architecture: one implicit accumulator operand; fewer address bits in the instruction, more memory traffic.
- Endianness: little-endian stores the least-significant byte at the lowest address; big-endian stores the MSB at the lowest address. GATE multi-byte layout questions hinge on this.
- Word vs byte addressable: GATE usually assumes byte-addressable memory unless the stem says otherwise — that affects how PC increments and how addresses count.
| Topic | RISC-leaning | CISC-leaning |
|---|---|---|
| Memory ops | Load/store only | ALU ops may use memory |
| Length | Fixed common | Variable common |
| Decode | Simple | Complex / microcode |
| Registers | Many GPRs | Often fewer / special |
Worked example
Problem. Store 0x1234 as a 16-bit little-endian value at address 100. What is Mem[100]?
Solution. LSB first: Mem[100]=0x34, Mem[101]=0x12.
GATE exam tricks — instructions
- If options mix MIPS and CPU time, recompute with IC×CPI×T_clock — MIPS distractors are common.
- “After fetch” usually means PC already points to the next instruction — critical for PC-relative addressing later.
- Fixed-length instructions simplify pipeline fetch; variable-length complicates alignment MCQs.
- IC is dynamic (loops count repeatedly). Static code size ≠ IC.
- Halving CPI halves CPU time if IC and clock stay fixed — proportional reasoning is a frequent NAT.
- Endian trap: “lowest address” means the smallest numeric address, not “leftmost in the printed hex word”.
- Flags are set by ALU/compare results, not by the cache or PC alone.
Worked example
Problem. Clock doubles and CPI is unchanged. What happens to CPU time?
Solution. T_clock halves ⇒ CPU time halves (IC fixed).
Exam tips
- Write CPU time = IC × CPI × T_clock before plugging numbers.
- Convert MHz/GHz to cycle time carefully (T = 1/f).
- Endian questions: track the lowest address byte.
- State whether PC is pre- or post-fetch when a later mode question needs it.
- Dynamic IC ≠ number of lines in the source file.
10 GATE-style MCQs for Machine Instructions with full explanations. Attempt each question before revealing the answer.
CPU time is best expressed as:
Show answer & explanation
Answer: B
CPU time = Instruction Count × CPI × T_clock.
Which register normally holds the next instruction address?
Show answer & explanation
Answer: B
Program Counter (PC) points to the next instruction.
Instruction fetch primarily uses:
Show answer & explanation
Answer: B
Fetch reads Mem[PC] into IR (and updates PC).
Little-endian means:
Show answer & explanation
Answer: B
LSB stored at the lower address.
Speedup of a change is:
Show answer & explanation
Answer: B
Speedup = old time / new time.
RISC designs typically favour:
Show answer & explanation
Answer: B
RISC: simple instructions, load/store architecture.
IR stands for:
Show answer & explanation
Answer: B
Instruction Register holds the fetched instruction.
Clock 2 GHz means cycle time:
Show answer & explanation
Answer: B
T = 1/(2×10^9) = 0.5 ns.
MAR/MDR are mainly used for:
Show answer & explanation
Answer: B
Memory Address Register / Memory Data Register interface memory.
CPI means:
Show answer & explanation
Answer: A
Average clock cycles per instruction.
Extra page-specific practice beyond the GATE samples. Attempt all 10, then reveal answers to check your reasoning.
IC=2×10^6, CPI=1.5, clock=500 MHz. CPU time is:
Show answer & explanation
Answer: B) 6 ms
T=2e6 × 1.5 × (1/5e8)=0.006 s = 6 ms.
If CPI halves and clock unchanged, CPU time:
Show answer & explanation
Answer: B) Halves
Time proportional to CPI.
Opcode field primarily selects:
Show answer & explanation
Answer: B) Operation to perform
Opcode encodes the operation.
Write-back stage typically updates:
Show answer & explanation
Answer: B) Destination register / flags
Results written to the register file (and flags as needed).
Fixed-length instructions help:
Show answer & explanation
Answer: B) Simpler fetch alignment in pipelines
Uniform size eases fetch/decode.
Flags (Z,N,C,V) are set mainly by:
Show answer & explanation
Answer: B) ALU results
Status flags reflect ALU outcomes.
Dynamic instruction count means:
Show answer & explanation
Answer: B) Instructions executed at run time
IC is the executed count.
1 ns clock cycle ↔ frequency:
Show answer & explanation
Answer: C) 1 GHz
f = 1/T = 10^9 Hz.
CISC relative to RISC typically has:
Show answer & explanation
Answer: B) Richer, more complex instructions
CISC packs more work per instruction.
Accumulator architecture emphasizes:
Show answer & explanation
Answer: B) One implicit accumulator operand
Classic accumulator machines use ACC as implicit operand.
Topic FAQs
What is IC in the performance equation?
Instruction Count — how many instructions the program executes (dynamic count, including loop iterations).
Does higher MIPS always mean a faster machine for my program?
Not necessarily. MIPS ignores workload mix; IC×CPI×T_clock on your program is the reliable comparison.
What does the Instruction Register (IR) hold?
The bits of the instruction currently being decoded/executed after fetch.
Why do pipelines prefer fixed-length instructions?
Uniform size makes next-PC calculation and fetch alignment simple every cycle.
Hover a card to reveal the answer with a 3D flip. On touch devices, tap the card or use Show answer.