Skip to main content

Computer Organization

Machine Instructions

Own the fetch–decode–execute cycle and CPU time = IC × CPI × T_clock before diving into cache and pipeline maths.

~3 hrs ~0.5–1 mark · Moderate 10 samples · 10 practice · 10 cards

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.
StyleTypical operandsGATE cue
3-addressRd, Rs1, Rs2RISC-like GPRs
2-addressRd/Rs, Rs2Dest overwritten
1-addressAcc + memory/regAccumulator ISA
0-addressStack 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.

3-address instruction format with opcode Rd Rs1 and Rs2 fields
Name the fields first — opcode vs address vs value is a frequent GATE discriminator.

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
StageWhat happensKey register / unit
FetchRead instruction from memoryPC, IR, MAR/MDR
DecodeInterpret opcode / fieldsControl unit
ExecuteALU / branch / EA calcALU, flags
MemoryLoad/store data if neededMAR, MDR
Write-backStore result / update flagsRegister 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.

Instruction cycle stages fetch decode execute memory write-back with PC IR MAR MDR
Fetch ends with bits in IR; PC held the address — do not swap them in MCQs.

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.

CPU time equation IC times CPI times clock period with speedup note
Convert MHz/GHz before multiplying — unit slips are the #1 NAT error.

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.
TopicRISC-leaningCISC-leaning
Memory opsLoad/store onlyALU ops may use memory
LengthFixed commonVariable common
DecodeSimpleComplex / microcode
RegistersMany GPRsOften 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.

Little-endian versus big-endian byte layout of 0x1234 at address 100
LSB-low for little-endian — sketch the two bytes before picking options.

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.
Exam pattern · 10 questions

GATE sample questions & answers

10 GATE-style MCQs for Machine Instructions with full explanations. Attempt each question before revealing the answer.

Q1 CPU performance equation

CPU time is best expressed as:

  • A) Clock rate × CPI
  • B) IC × CPI × clock cycle time
  • C) IC / CPI
  • D) MIPS × CPI
Show answer & explanation

Answer: B

CPU time = Instruction Count × CPI × T_clock.

Q2 Registers

Which register normally holds the next instruction address?

  • A) IR
  • B) PC
  • C) MDR
  • D) Accumulator only
Show answer & explanation

Answer: B

Program Counter (PC) points to the next instruction.

Q3 Instruction cycle

Instruction fetch primarily uses:

  • A) Only ALU
  • B) PC and memory read into IR
  • C) DMA only
  • D) Cache tag only
Show answer & explanation

Answer: B

Fetch reads Mem[PC] into IR (and updates PC).

Q4 Endianness

Little-endian means:

  • A) MSB at lowest address
  • B) LSB at lowest address
  • C) No byte order
  • D) Only stack grows up
Show answer & explanation

Answer: B

LSB stored at the lower address.

Q5 Speedup

Speedup of a change is:

  • A) T_new / T_old
  • B) T_old / T_new
  • C) CPI only
  • D) Clock only
Show answer & explanation

Answer: B

Speedup = old time / new time.

Q6 RISC vs CISC

RISC designs typically favour:

  • A) Variable-length CISC ops
  • B) Load/store with simpler ops
  • C) Microcode only
  • D) No registers
Show answer & explanation

Answer: B

RISC: simple instructions, load/store architecture.

Q7 Registers

IR stands for:

  • A) Index Register only
  • B) Instruction Register
  • C) Interrupt Router
  • D) I/O Register
Show answer & explanation

Answer: B

Instruction Register holds the fetched instruction.

Q8 Clock

Clock 2 GHz means cycle time:

  • A) 2 ns
  • B) 0.5 ns
  • C) 2 μs
  • D) 500 ns
Show answer & explanation

Answer: B

T = 1/(2×10^9) = 0.5 ns.

Q9 Datapath registers

MAR/MDR are mainly used for:

  • A) Branch prediction
  • B) Memory address / data buffering
  • C) Only I/O ports
  • D) Pipeline forwarding
Show answer & explanation

Answer: B

Memory Address Register / Memory Data Register interface memory.

Q10 CPI

CPI means:

  • A) Cycles per instruction
  • B) Clocks per interrupt
  • C) Cache per instruction
  • D) Code path index
Show answer & explanation

Answer: A

Average clock cycles per instruction.

Topic drill · 10 questions

10 practice questions — Machine Instructions

Extra page-specific practice beyond the GATE samples. Attempt all 10, then reveal answers to check your reasoning.

P1

IC=2×10^6, CPI=1.5, clock=500 MHz. CPU time is:

  • A) 3 ms
  • B) 6 ms
  • C) 1.5 ms
  • D) 60 ms
Show answer & explanation

Answer: B) 6 ms

T=2e6 × 1.5 × (1/5e8)=0.006 s = 6 ms.

P2

If CPI halves and clock unchanged, CPU time:

  • A) Doubles
  • B) Halves
  • C) Unchanged
  • D) Becomes zero
Show answer & explanation

Answer: B) Halves

Time proportional to CPI.

P3

Opcode field primarily selects:

  • A) Only register names
  • B) Operation to perform
  • C) Cache size
  • D) Disk block
Show answer & explanation

Answer: B) Operation to perform

Opcode encodes the operation.

P4

Write-back stage typically updates:

  • A) Only PC
  • B) Destination register / flags
  • C) Only disk
  • D) Only TLB always
Show answer & explanation

Answer: B) Destination register / flags

Results written to the register file (and flags as needed).

P5

Fixed-length instructions help:

  • A) Variable decode complexity
  • B) Simpler fetch alignment in pipelines
  • C) Larger microcode only
  • D) No PC
Show answer & explanation

Answer: B) Simpler fetch alignment in pipelines

Uniform size eases fetch/decode.

P6

Flags (Z,N,C,V) are set mainly by:

  • A) Cache tags
  • B) ALU results
  • C) DMA length
  • D) Disk geometry
Show answer & explanation

Answer: B) ALU results

Status flags reflect ALU outcomes.

P7

Dynamic instruction count means:

  • A) Lines of source code
  • B) Instructions executed at run time
  • C) Static binary size only
  • D) Number of registers
Show answer & explanation

Answer: B) Instructions executed at run time

IC is the executed count.

P8

1 ns clock cycle ↔ frequency:

  • A) 1 MHz
  • B) 100 MHz
  • C) 1 GHz
  • D) 10 GHz
Show answer & explanation

Answer: C) 1 GHz

f = 1/T = 10^9 Hz.

P9

CISC relative to RISC typically has:

  • A) Only load/store ops
  • B) Richer, more complex instructions
  • C) No memory ops
  • D) No branching
Show answer & explanation

Answer: B) Richer, more complex instructions

CISC packs more work per instruction.

P10

Accumulator architecture emphasizes:

  • A) Many GPRs equally
  • B) One implicit accumulator operand
  • C) Only stack machines
  • D) No ALU
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.

Quick revision · 10 cards

10 flashcards — Machine Instructions

Hover a card to reveal the answer with a 3D flip. On touch devices, tap the card or use Show answer.

Q1 What is the CPU performance equation for program execution time?
Q2 What does the Program Counter (PC) hold during normal sequential execution?
Q3 What happens in the fetch stage of the instruction cycle?
Q4 What does little-endian byte ordering mean for a multi-byte value in memory?
Q5 How is speedup defined when a change reduces execution time from T_old to T_new?
Q6 What are two hallmark features of a RISC-style ISA at GATE depth?
Q7 What does the Instruction Register (IR) store?
Q8 If the clock frequency is 1 GHz, what is the clock cycle time T_clock?
Q9 What is the difference between MAR and MDR in a simple CPU datapath?
Q10 What does CPI stand for, and what does it measure?