By the end of this chapter you'll be able to…

  • 1State the execution-time identity and what each term depends on
  • 2Compare three-, two-, one- and zero-address instruction formats
  • 3Translate an expression for a stack machine and count its instructions
  • 4State the defining features of RISC and CISC
  • 5Explain why load-store architecture makes pipelining regular
  • 6Apply Amdahl's law and state its limiting speedup
  • 7Explain why instruction rate is a misleading performance metric
  • 8Write the effective-address formula for each addressing mode
  • 9Count memory accesses for an instruction including its fetch
  • 10Match each addressing mode to the access pattern it serves
  • 11Explain why PC-relative addressing gives position independence
  • 12Handle the program-counter increment convention in a branch target
  • 13Apply a scale factor in indexed addressing
  • 14Compute field widths in an instruction encoding
  • 15Design an expanding-opcode encoding and verify it fits
  • 16State the alignment requirement for a word access
  • 17Distinguish big-endian from little-endian storage
  • 18Explain why the return address must be stacked for recursion
  • 19Describe the contents of an activation record
  • 20Distinguish caller-saved from callee-saved registers
💡
Why this chapter matters in GATE
The instruction set is the contract between hardware and software: it is what a compiler targets and what a processor must implement. Every part of it is a design choice, and the governing identity is that execution time is the product of instruction count, cycles per instruction and clock period. A rich instruction that does more work reduces the instruction count and raises the cycles each instruction takes, while a simple instruction set does the reverse, so neither is obviously better and the whole RISC-versus-CISC argument is really about which term dominates. The second organising fact is that an addressing mode is nothing more than a rule for computing an effective address. Every mode in every instruction set exists because some data-access pattern — a constant, an array element, a pointer chase, a stack frame — was frequent enough that encoding it directly paid for the extra decode complexity. So a question about a mode is answered by writing down its effective-address formula and counting the memory accesses it implies.

Before you start — revise these

🔗
Number Representation & Computer Arithmetic
Signed displacements, word sizes and byte ordering all depend on the representations developed there.
🔗
Programming in C & Recursion
Activation records, parameter passing and the stack discipline are the machine-level view of what recursion does.

Machine Instructions & Addressing Modes

The instruction set is the contract between hardware and software: it is what a compiler targets and what a processor must implement. Everything about it is a design choice, and every choice has a cost somewhere else.

The governing identity is that execution time is the product of three things, and any instruction set decision that improves one usually damages another:

where is the instruction count, the average cycles per instruction, and the clock period.

A rich instruction that does more work reduces the instruction count and raises the cycles each instruction takes. A simple instruction set does the reverse. Neither is obviously better, and the whole RISC-versus-CISC argument is an argument about which term dominates.

The second organising fact is that an addressing mode is just a rule for computing an effective address. Every mode in every instruction set exists because some data-access pattern — a constant, an array element, a pointer chase, a stack frame — was frequent enough that encoding it directly paid for the extra decode complexity.

So the way to answer a question about a mode is to write down its effective-address formula and count the memory accesses it implies.

1. Instruction Formats

Instructions are classified by how many operand addresses they carry explicitly.

FormatExampleComment
Three-addressADD R1, R2, R3Both sources and destination named
Two-addressADD R1, R2Destination doubles as a source
One-addressADD XAccumulator is implicit
Zero-addressADDBoth operands on a stack

Fewer explicit addresses means shorter instructions and more of them, because intermediate values must be moved into the implicit location before each operation.

A zero-address machine evaluates expressions in postfix order, pushing operands and letting each operation consume the top two stack entries. This is why compilers targeting stack machines translate expression trees into postfix directly.

Evaluating takes three arithmetic instructions on a three-address machine and seven instructions on a stack machine — four pushes, two adds and a multiply, plus a pop to store the result.

The trade is instruction count against instruction size, which is exactly the first two terms of the execution-time identity.

2. RISC and CISC

The two philosophies differ in where complexity is placed.

PropertyCISCRISC
Instruction lengthVariableFixed
Memory operandsMost instructionsLoad and store only
Addressing modesManyFew
RegistersFewMany
Control unitMicroprogrammedHardwired
CPIHigher, variableLower, near 1

A load-store architecture is the defining RISC feature: arithmetic instructions operate only on registers, and memory is touched only by explicit loads and stores.

The reason is pipelining. If any instruction might access memory, every pipeline stage must be prepared for a memory delay, and the pipeline becomes hard to keep full. Confining memory access to two instruction types makes the pipeline regular, which is what actually delivers the low CPI.

Fixed-length instructions matter for the same reason: the next instruction's address is known without decoding the current one, so fetching can proceed in parallel with decoding.

The historical argument for CISC was code density, which mattered when memory was expensive and compilers were weak. Both conditions changed, which is why modern high-performance designs are RISC-like internally even when they present a CISC instruction set externally.

Amdahl's law formalises why optimising the wrong component is wasted effort. If a fraction of the execution time is improved by a factor , the overall speedup is

The limit as grows without bound is , so a component occupying 40 per cent of the time can never yield more than a 1.67 times speedup however completely it is eliminated.

This is why the fraction of time matters rather than the fraction of instructions, and why measuring before optimising is the standing advice.

Raw instruction rate is a misleading metric for the same reason. Comparing two machines by millions of instructions per second is meaningless across different instruction sets, because a CISC instruction and a RISC instruction do different amounts of work, and only total execution time on a real program is comparable.

3. Addressing Modes

Each mode is defined by how the effective address is computed from the instruction's fields and the processor's registers.

ModeEffective addressMemory accesses for the operand
ImmediateOperand is in the instruction0
RegisterOperand is in a register0
Direct (absolute)The address field itself1
Register indirectContents of a register1
IndirectContents of the memory word named2
IndexedBase address plus index register1
Base-plus-offsetBase register plus displacement1
PC-relativeProgram counter plus displacement1
AutoincrementRegister contents, then register incremented1

Counting memory accesses is what most questions actually test. Immediate and register modes touch memory zero times for the operand; indirect touches it twice, once to fetch the pointer and once to fetch the datum.

Note that these counts exclude the instruction fetch itself, which every instruction requires. A question asking for total memory accesses must add it.

Each mode exists for a recognisable access pattern.

Immediate suits constants. Register suits values already in flight. Direct suits a fixed global variable. Register indirect suits a pointer. Indexed suits array traversal, since the index register is incremented while the base stays fixed. Base-plus-offset suits a structure field or a stack-frame local, since the offset is fixed at compile time while the base varies at run time.

PC-relative addressing is what makes code position-independent. A branch encoded as a displacement from the current program counter works wherever the code is loaded, which is why it is the standard mode for branches and why shared libraries rely on it.

Autoincrement and autodecrement modes exist because stepping through an array and pushing onto a stack are both extremely common, and folding the update into the access saves an instruction each time.

4. Effective Address Computation

The reliable procedure is to write the formula, then substitute.

For indexed mode with base and index register , the effective address is , and for a scaled version it is where is the element size.

The scale factor is what makes array indexing work in bytes, since incrementing an index by 1 must advance the address by the size of one element.

For base-plus-offset, the effective address is with a signed displacement encoded in the instruction. Sign matters: a negative displacement addresses a local below the frame pointer, which is where local variables usually live.

For PC-relative, the effective address is the updated program counter plus the displacement. The subtlety is which value the program counter holds, since most machines increment it during fetch, so the displacement is relative to the next instruction rather than the current one.

That off-by-one is a standard exam trap, and the instruction set's convention must be read from the question rather than assumed.

5. Instruction Encoding

An instruction word is divided into fields, and the widths must add up.

For a machine with a 32-bit instruction, 4 bits of opcode, 3 register fields of 5 bits each and the rest as an immediate, the immediate field is bits.

With opcode bits, at most distinct opcodes exist, but that limit can be exceeded by expanding opcodes.

An expanding opcode uses a reserved pattern to indicate that further opcode bits follow, borrowing them from an operand field. Instructions with fewer operands can therefore afford longer opcodes, which is exactly how a format supports many zero-operand instructions alongside a few three-operand ones.

The counting question that follows is standard: given a fixed instruction width and a required number of instructions at each operand count, decide whether an encoding exists. The method is to compute how many bit patterns each group consumes and check that the total does not exceed the available space.

Alignment and endianness are the other encoding facts examined. A word-aligned access requires the address to be a multiple of the word size, and an unaligned access either costs extra cycles or faults, depending on the machine.

Big-endian stores the most significant byte at the lowest address; little-endian stores the least significant byte there. Neither is better, but a program that writes a word and reads back individual bytes will observe the difference, which is why network protocols specify a byte order explicitly.

6. Subroutines and the Stack

A subroutine call must save the return address and then transfer control.

Where the return address is saved determines whether recursion is possible. Saving it in a fixed memory location or a dedicated register means a second call overwrites the first, so recursion fails. Saving it on a stack means each call gets its own slot, and recursion works naturally.

The stack also carries the activation record: parameters, saved registers, local variables and the return address. The frame pointer gives a stable base from which locals are addressed by fixed offsets, which is precisely the base-plus-offset mode.

Register saving is split by convention into caller-saved and callee-saved sets. A caller-saved register may be destroyed by a call, so the caller preserves it if needed across the call. A callee-saved register must be restored by the subroutine before returning.

The split exists to reduce total saves: a caller that does not need a value across the call saves nothing, and a callee that does not use a register saves nothing.

7. Worked Examples

Example 1. A machine has 32-bit instructions with an 8-bit opcode. Instructions may address memory using a 24-bit direct address. How many distinct instructions can the machine encode, and what is the addressable memory size?

The opcode is 8 bits, so at most distinct instructions.

The address field is 24 bits, so distinct addresses are reachable, which is 16 mega-locations.

If each location holds one byte, that is 16 MB of addressable memory. If each holds a 32-bit word, it is 64 MB.

The unit matters and the question must state it, since "addressable memory" is ambiguous between byte-addressable and word-addressable machines. This ambiguity is deliberate in many exam stems, and the safe move is to state the assumption in the answer.

Example 2. Instruction LOAD R1, (R2) uses register indirect mode. How many memory accesses does executing it require in total?

Count the instruction fetch first, which every instruction needs: 1 access.

Now the operand. Register indirect means the effective address is the contents of R2, which is already in a register and needs no memory access to obtain.

Fetching the operand from that address costs 1 access.

The total is 2 memory accesses.

Compare with LOAD R1, @X, full indirect mode. That costs 1 for the instruction fetch, 1 to read the pointer stored at X, and 1 to read the datum, giving 3 accesses in total.

And LOAD R1, #5, immediate mode, costs only the 1 instruction fetch, since the operand travels inside the instruction itself.

Example 3. A program has 40 per cent load-store instructions, 40 per cent ALU instructions and 20 per cent branches, with CPIs of 4, 1 and 3 respectively. Find the average CPI, and the speedup if load-store CPI is reduced to 2.

Average CPI is the weighted sum of the individual CPIs.

With load-store CPI reduced to 2:

The speedup is the ratio of execution times, and since instruction count and clock period are unchanged, it is the ratio of CPIs.

Speedup , about 44 per cent faster.

Note what the arithmetic shows: load-store instructions are only 40 per cent of the count but contributed 1.6 of the 2.6 average CPI, so they dominated the time. Optimising the component with the largest share of time, not the largest share of count, is what Amdahl's law formalises.

Example 4. An instruction set has 16-bit instructions and needs 14 three-address instructions, 30 two-address instructions and 45 zero-address instructions, with 4-bit address fields. Does an encoding exist?

Work from the largest operand count downward, tracking how much opcode space remains.

A three-address instruction uses 12 bits for its three 4-bit address fields, leaving 4 bits of opcode. Four bits give 16 patterns, and 14 are needed, so 2 patterns remain unused.

Those 2 remaining patterns expand. Each covers a 4-bit field that is now free, so together they supply two-address opcodes. Thirty are needed, leaving 2 spare.

Those 2 expand again over another 4-bit field, supplying one-address opcodes. None are needed, so all 32 remain.

Each of those 32 expands over the final 4-bit field, supplying zero-address opcodes. Only 45 are needed.

The encoding exists comfortably. The method generalises: at each level, multiply the unused patterns by to get the space available at the next level.

Example 5. A branch instruction at address 2000 uses PC-relative addressing with a displacement of . Where does it branch to, on a machine with 4-byte instructions that increments the program counter during fetch?

The program counter is incremented during fetch, so by the time the displacement is applied it holds the address of the next instruction, which is .

The effective address is .

The branch targets address 1996.

Had the machine applied the displacement to the current instruction's address instead, the target would have been 1992. The two differ by exactly one instruction length, and which convention applies must be read from the question.

The reason PC-relative is used here at all is position independence: if the whole block of code were loaded 1000 bytes higher, the branch would still reach the right place, because the displacement encodes a distance rather than a location.

Example 6. Why does saving the return address in a dedicated register prevent recursion, and how does a stack fix it?

A subroutine call must record where to resume. If that address goes into a single dedicated register, then a second call made before the first returns overwrites it.

Concretely, if routine calls itself, the inner call stores its return address over the outer call's, and when the inner call returns, control goes back correctly, but the outer call's return address is gone. The outer return then jumps to the wrong place.

A stack fixes this because each call pushes its own return address and each return pops the matching one. The last-in-first-out discipline of the stack matches the nesting discipline of calls exactly, which is why the two are inseparable.

The same reasoning extends beyond the return address. Parameters, saved registers and local variables all need per-invocation copies for recursion to work, which is why they are grouped into an activation record pushed on entry and popped on exit.

Summary

Execution time is instruction count times cycles per instruction times clock period, and instruction set choices trade these against each other.

Fewer explicit operand addresses means shorter instructions and more of them; a stack machine evaluates expressions in postfix order.

RISC is defined by load-store architecture, fixed-length instructions and a hardwired control unit, all of which exist to make pipelining regular. CISC bought code density with variable-length instructions and memory operands.

An addressing mode is a rule for computing an effective address, and each exists for a recognisable pattern: immediate for constants, indexed for arrays, base-plus-offset for stack locals and structure fields, PC-relative for position-independent branches.

Counting memory accesses is what most mode questions test: immediate and register cost zero for the operand, direct and register indirect cost one, full indirect costs two, and the instruction fetch is always extra.

PC-relative displacements are usually relative to the next instruction, because the program counter is incremented during fetch.

Field widths must add up, and expanding opcodes borrow bits from operand fields, with unused patterns at each level multiplying by the freed field width.

Alignment requires addresses to be multiples of the access size; endianness decides which byte of a word sits at the lowest address.

Saving the return address on a stack rather than in a register is what makes recursion possible, and the activation record extends the same reasoning to parameters, locals and saved registers.

Key formulas & results

Everything to memorise for the exam hall, in one card. Screenshot this for revision.

The organising tool
AN ADDRESSING MODE IS A RULE FOR COMPUTING AN EFFECTIVE ADDRESS. WRITE THE FORMULA, THEN COUNT THE MEMORY ACCESSES IT IMPLIES.
EVERY MODE EXISTS BECAUSE SOME ACCESS PATTERN WAS FREQUENT ENOUGH THAT ENCODING IT DIRECTLY PAID FOR THE EXTRA DECODE COMPLEXITY.
Execution time
T = IC TIMES CPI TIMES T_clock, WHERE IC IS INSTRUCTION COUNT AND CPI IS AVERAGE CYCLES PER INSTRUCTION.
ANY INSTRUCTION SET DECISION THAT IMPROVES ONE TERM USUALLY DAMAGES ANOTHER, WHICH IS THE ENTIRE RISC VERSUS CISC ARGUMENT.
Instruction formats
THREE-ADDRESS NAMES BOTH SOURCES AND THE DESTINATION. TWO-ADDRESS REUSES THE DESTINATION AS A SOURCE. ONE-ADDRESS USES AN IMPLICIT ACCUMULATOR. ZERO-ADDRESS USES A STACK.
FEWER EXPLICIT ADDRESSES MEANS SHORTER INSTRUCTIONS AND MORE OF THEM, WHICH IS THE FIRST TWO TERMS OF THE EXECUTION-TIME IDENTITY IN TENSION.
Stack machine evaluation
A ZERO-ADDRESS MACHINE EVALUATES EXPRESSIONS IN POSTFIX ORDER, PUSHING OPERANDS AND LETTING EACH OPERATION CONSUME THE TOP TWO STACK ENTRIES.
(A + B) TIMES (C + D) TAKES THREE ARITHMETIC INSTRUCTIONS ON A THREE-ADDRESS MACHINE AND SEVEN ON A STACK MACHINE PLUS A POP.
RISC versus CISC
RISC: FIXED LENGTH, LOAD-STORE ONLY, FEW MODES, MANY REGISTERS, HARDWIRED CONTROL, CPI NEAR 1. CISC: VARIABLE LENGTH, MEMORY OPERANDS, MANY MODES, MICROPROGRAMMED CONTROL, HIGHER CPI.
LOAD-STORE ARCHITECTURE IS THE DEFINING RISC FEATURE, BECAUSE CONFINING MEMORY ACCESS TO TWO INSTRUCTION TYPES IS WHAT MAKES THE PIPELINE REGULAR.
Amdahl's law
S = 1 DIVIDED BY ((1 - f) + f/s), WHERE f IS THE FRACTION OF TIME IMPROVED AND s THE IMPROVEMENT FACTOR.
THE LIMIT AS s GROWS IS 1/(1-f), SO A COMPONENT OCCUPYING 40 PER CENT OF THE TIME CAN NEVER YIELD MORE THAN A 1.67 TIMES SPEEDUP.
Why instruction rate misleads
COMPARING MACHINES BY MILLIONS OF INSTRUCTIONS PER SECOND IS MEANINGLESS ACROSS DIFFERENT INSTRUCTION SETS.
A CISC INSTRUCTION AND A RISC INSTRUCTION DO DIFFERENT AMOUNTS OF WORK, SO ONLY TOTAL EXECUTION TIME ON A REAL PROGRAM IS COMPARABLE.
Addressing modes and their effective addresses
IMMEDIATE: OPERAND IN THE INSTRUCTION. REGISTER: OPERAND IN A REGISTER. DIRECT: THE ADDRESS FIELD ITSELF. REGISTER INDIRECT: CONTENTS OF A REGISTER. INDIRECT: CONTENTS OF THE MEMORY WORD NAMED.
INDEXED IS BASE PLUS INDEX REGISTER. BASE-PLUS-OFFSET IS BASE REGISTER PLUS DISPLACEMENT. PC-RELATIVE IS PROGRAM COUNTER PLUS DISPLACEMENT.
Memory access counts
FOR THE OPERAND ALONE: IMMEDIATE AND REGISTER COST 0, DIRECT AND REGISTER INDIRECT COST 1, FULL INDIRECT COSTS 2.
THESE COUNTS EXCLUDE THE INSTRUCTION FETCH, WHICH EVERY INSTRUCTION REQUIRES. A QUESTION ASKING FOR TOTAL ACCESSES MUST ADD IT.
Which pattern each mode serves
IMMEDIATE FOR CONSTANTS, REGISTER FOR VALUES IN FLIGHT, DIRECT FOR A FIXED GLOBAL, REGISTER INDIRECT FOR A POINTER, INDEXED FOR ARRAY TRAVERSAL, BASE-PLUS-OFFSET FOR A STACK LOCAL OR STRUCTURE FIELD.
AUTOINCREMENT AND AUTODECREMENT EXIST BECAUSE STEPPING THROUGH AN ARRAY AND PUSHING ONTO A STACK ARE COMMON ENOUGH THAT FOLDING THE UPDATE IN SAVES AN INSTRUCTION EACH TIME.
PC-relative addressing
THE EFFECTIVE ADDRESS IS THE UPDATED PROGRAM COUNTER PLUS THE DISPLACEMENT, MAKING THE CODE POSITION-INDEPENDENT.
MOST MACHINES INCREMENT THE PROGRAM COUNTER DURING FETCH, SO THE DISPLACEMENT IS RELATIVE TO THE NEXT INSTRUCTION. THIS OFF-BY-ONE IS A STANDARD TRAP.
Scaled indexing
THE EFFECTIVE ADDRESS IS BASE PLUS INDEX TIMES SCALE, WHERE THE SCALE IS THE ELEMENT SIZE.
THE SCALE IS WHAT MAKES ARRAY INDEXING WORK IN BYTES, SINCE INCREMENTING AN INDEX BY 1 MUST ADVANCE THE ADDRESS BY ONE ELEMENT.
Field widths
THE FIELDS OF AN INSTRUCTION WORD MUST SUM TO ITS WIDTH. WITH k OPCODE BITS, AT MOST 2^k DISTINCT OPCODES EXIST.
FOR A 32-BIT INSTRUCTION WITH 4 OPCODE BITS AND THREE 5-BIT REGISTER FIELDS, THE IMMEDIATE FIELD IS 32 MINUS 4 MINUS 15, WHICH IS 13 BITS.
Expanding opcodes
A RESERVED OPCODE PATTERN INDICATES THAT FURTHER OPCODE BITS FOLLOW, BORROWED FROM AN OPERAND FIELD.
AT EACH LEVEL, MULTIPLY THE UNUSED PATTERNS BY 2 TO THE FIELD WIDTH TO GET THE SPACE AVAILABLE AT THE NEXT LEVEL. FEWER OPERANDS AFFORD LONGER OPCODES.
Alignment
A WORD-ALIGNED ACCESS REQUIRES THE ADDRESS TO BE A MULTIPLE OF THE WORD SIZE.
AN UNALIGNED ACCESS EITHER COSTS EXTRA CYCLES OR FAULTS, DEPENDING ON THE MACHINE, WHICH IS WHY COMPILERS PAD STRUCTURE FIELDS.
Endianness
BIG-ENDIAN STORES THE MOST SIGNIFICANT BYTE AT THE LOWEST ADDRESS; LITTLE-ENDIAN STORES THE LEAST SIGNIFICANT BYTE THERE.
NEITHER IS BETTER, BUT A PROGRAM THAT WRITES A WORD AND READS BACK INDIVIDUAL BYTES WILL SEE THE DIFFERENCE, WHICH IS WHY NETWORK PROTOCOLS SPECIFY A BYTE ORDER.
Return addresses and recursion
SAVING THE RETURN ADDRESS IN A FIXED LOCATION OR DEDICATED REGISTER MEANS A SECOND CALL OVERWRITES THE FIRST, SO RECURSION FAILS. A STACK GIVES EACH CALL ITS OWN SLOT.
THE LAST-IN-FIRST-OUT DISCIPLINE OF A STACK MATCHES THE NESTING DISCIPLINE OF CALLS EXACTLY, WHICH IS WHY THE TWO ARE INSEPARABLE.
Activation records
THE FRAME HOLDS PARAMETERS, SAVED REGISTERS, LOCAL VARIABLES AND THE RETURN ADDRESS, WITH THE FRAME POINTER GIVING A STABLE BASE.
LOCALS ARE ADDRESSED BY FIXED OFFSETS FROM THE FRAME POINTER, WHICH IS PRECISELY THE BASE-PLUS-OFFSET ADDRESSING MODE.
Register saving conventions
A CALLER-SAVED REGISTER MAY BE DESTROYED BY A CALL, SO THE CALLER PRESERVES IT IF NEEDED. A CALLEE-SAVED REGISTER MUST BE RESTORED BY THE SUBROUTINE.
THE SPLIT EXISTS TO REDUCE TOTAL SAVES: A CALLER NOT NEEDING A VALUE ACROSS THE CALL SAVES NOTHING, AND A CALLEE NOT USING A REGISTER SAVES NOTHING.
⚠️

Traps GATE sets — and how to dodge them

These are the exact option-traps and misreads that cost marks under negative marking.

WATCH OUT
Omitting the instruction fetch when counting memory accesses
Every instruction requires at least one memory access to fetch it. A register-indirect load costs 2 accesses in total: one for the fetch and one for the operand, not 1.
WATCH OUT
Confusing register indirect with full indirect
Register indirect takes the address from a register, costing one operand access. Full indirect takes the address from a memory word named by the instruction, costing two: one for the pointer and one for the datum.
WATCH OUT
Applying a PC-relative displacement to the current instruction's address
Most machines increment the program counter during fetch, so the displacement is measured from the next instruction. The two conventions differ by exactly one instruction length, and the question must state which applies.
WATCH OUT
Forgetting the scale factor in indexed addressing
An index counts elements while an address counts bytes, so the effective address is base plus index times element size. Omitting the scale addresses the wrong element for anything larger than a byte.
WATCH OUT
Comparing machines by instruction rate
Instructions per second is meaningless across instruction sets, since a CISC instruction does more work than a RISC one. Only total execution time on the same real program is a valid comparison.
WATCH OUT
Optimising the component with the largest instruction count
Amdahl's law depends on the fraction of time, not of instructions. A class making up 40 per cent of instructions but 60 per cent of cycles is the one worth optimising, and the ceiling on speedup follows from its time share.
WATCH OUT
Assuming a fixed-length instruction set is merely a stylistic choice
Fixed length means the next instruction's address is known without decoding the current one, so fetch and decode can overlap. This is what makes a regular pipeline possible and is why RISC adopted it.
WATCH OUT
Computing opcode space without accounting for expansion
Unused patterns at one operand level expand over the freed operand field at the next. Multiply the unused count by 2 to the field width at each level rather than assuming a flat opcode limit.
WATCH OUT
Treating addressable memory size as unambiguous
A 24-bit address field gives 2 to the 24 locations, but whether that is 16 MB or 64 MB depends on whether the machine is byte-addressable or word-addressable. State the assumption explicitly.
WATCH OUT
Assuming endianness affects word-level operations
It does not; a word written and read as a word is unaffected. The difference appears only when a multi-byte value is accessed byte by byte, which is why network protocols specify a byte order.
WATCH OUT
Saving the return address in a dedicated register and expecting recursion to work
The second call overwrites the first return address, so the outer call returns to the wrong place. Recursion requires a per-invocation slot, which is exactly what a stack provides.
WATCH OUT
Assuming a callee must save every register it uses
The convention splits registers into caller-saved and callee-saved sets precisely to avoid unnecessary saves. A caller-saved register used only within the callee needs no saving at all.

Exam-pattern practice

PYQ-style questions with full solutions. Work through them as a readiness check — mark yourself honestly and get your gap report at the end.

Readiness check

Are you exam-ready for Machine Instructions & Addressing Modes?

9 problems from this chapter. Try each one, reveal the worked solution, mark yourself honestly — get your gap report at the end.

9 questions~6 min

5-minute revision

The whole chapter, distilled. Read this the night before the exam.

  • Execution time is IC times CPI times clock period.
  • Fewer operand addresses means shorter but more numerous instructions.
  • A stack machine evaluates postfix.
  • RISC is defined by load-store architecture.
  • Load-store exists to make the pipeline regular.
  • Fixed length lets fetch and decode overlap.
  • CISC bought code density with variable-length instructions.
  • Amdahl's law limits speedup to 1/(1-f).
  • Optimise by fraction of time, not of instructions.
  • Instruction rate is meaningless across instruction sets.
  • Immediate costs 0 operand accesses.
  • Register costs 0 operand accesses.
  • Direct and register indirect cost 1.
  • Full indirect costs 2.
  • Always add the instruction fetch.
  • Indexed suits array traversal.
  • Base-plus-offset suits stack locals and structure fields.
  • PC-relative gives position independence.
  • The PC usually holds the next instruction's address.
  • Scaled indexing multiplies the index by the element size.
  • Field widths must sum to the instruction width.
  • k opcode bits give at most 2 to the k opcodes.
  • Expanding opcodes borrow bits from operand fields.
  • Unused patterns times 2 to the field width gives the next level's space.
  • Alignment requires an address that is a multiple of the size.
  • Big-endian puts the most significant byte lowest.
  • Endianness shows only on byte-level access to a word.
  • A dedicated return register alone breaks recursion.
  • A stack gives each call its own return slot.
  • An activation record holds parameters, locals and saved registers.
  • The frame pointer is the base for base-plus-offset locals.
  • Caller-saved registers may be destroyed by a call.
  • Callee-saved registers must be restored before returning.

GATE question blueprint

How this topic is asked, tier by tier — so you can prep to the pattern.

Typical weightage: Computer Organization contributes roughly 7-9 of the 72 core-CS marks; instruction formats and addressing modes supply 1-2 of those

Question styleMarks eachTypical countWhat it tests
Addressing modes1~1Effective address formulas and which pattern each mode serves
Memory access counting2~1Total accesses including the instruction fetch, across immediate, direct and indirect
Instruction formats2~1Operand counts, stack evaluation and instruction-count comparison
Expanding opcodes2~1Feasibility of an encoding given field widths and instruction requirements
Performance2~1Average CPI, speedup and Amdahl's law
PC-relative addressing2~1Branch target computation and the program-counter increment convention
Subroutines1~1Return address storage, recursion and register saving conventions
RISC and CISC1~1Defining features and why load-store enables pipelining

Exam-hall strategy

Battle-tested tips from mentors and toppers for this topic under the sectional clock.

  1. Write the effective-address formula before counting anything.
  2. Always include the instruction fetch in a memory access count.
  3. Read the question for whether the machine is byte- or word-addressable.
  4. Check the PC-increment convention before computing a branch target.
  5. For performance questions, convert instruction fractions into time fractions first.
  6. For expanding opcodes, multiply unused patterns by 2 to the freed field width at each level.
  7. Access counts and opcode counts are commonly set as NAT, which carries no negative marking, so never leave one blank.
  8. For 1-mark and 2-mark MCQs, negative marking is -1/3 and -2/3, so guess only after eliminating an option.
  9. GATE gives a single freely-navigable 180-minute window, so flag a long encoding-feasibility item and return to it.

Beyond the exam

Where this skill shows up in the job you're competing for — and in life.

Reading disassembly during debugging

Recognising base-plus-offset addressing off a frame pointer is what lets you identify which local variable an instruction touches.

Deciding what to optimise

Amdahl's law applied to a profile is the arithmetic that stops a team from spending weeks on a routine consuming three per cent of runtime.

Writing position-independent code

PC-relative addressing is why a shared library can be loaded at any address without relocating every branch inside it.

Serialising data across machines

Endianness is why a structure written to a file or socket on one architecture may read back scrambled on another unless a byte order is specified.

Where else this topic is tested

Prepare once, score in every exam that asks it.

GATE DALow overlap — computer organization is not a major component of that paper
UGC NET Computer ScienceHigh overlap — addressing modes, instruction formats and RISC versus CISC are examined as direct recall
ISRO / BARC / DRDO computer science papersVery high overlap — memory access counting, expanding opcodes and effective address computation are recurring MCQ topics

Questions aspirants ask

Pulled from the Q&A community and mentor sessions.

Because it is the property that actually delivers the low cycles-per-instruction figure, and fixed-length encoding is a supporting decision rather than the goal. Consider what happens in a pipeline when any instruction might reference memory. Every stage must be prepared for a variable-length memory delay, since a cache miss can stall an instruction for tens of cycles at an unpredictable point. Operand fetch, execution and writeback all become conditional on memory availability, and the control logic to handle every combination grows quickly. Confining memory access to load and store instructions means exactly one pipeline stage deals with memory, and every other instruction has a predictable, uniform path through the pipeline. That regularity is what allows one instruction to issue per cycle in the common case. Fixed-length instructions support this by making the address of the next instruction known without decoding the current one, so fetch can run ahead of decode. Variable-length encoding forces a partial decode before the next fetch address is known, which serialises two stages that would otherwise overlap. Both properties therefore serve the same end. The historical evidence is that modern x86 implementations, which must accept a variable-length CISC instruction set for compatibility, decode instructions internally into fixed-length register-to-register operations and run those through a RISC-style pipeline, paying the decode cost once at the front.

Count in three parts and never skip the first. The instruction fetch always costs at least one access, and on a variable-length machine a long instruction may cost more than one word fetch. Then count the accesses needed to obtain the effective address: zero for immediate, register, direct, register indirect, indexed and base-plus-offset, because those addresses come from the instruction or from registers; one for full indirect, because the pointer itself lives in memory. Then count the accesses needed to touch the operand at that address: zero for immediate and register, since the operand is not in memory at all; one for everything else. Finally add one more if the instruction writes a result back to memory rather than to a register. Applying this to the standard cases gives a progression worth memorising as a check: an immediate operand instruction costs 1 access in total, a direct or register-indirect load costs 2, and a full indirect load costs 3. A read-modify-write to memory with direct addressing costs 3 as well, being one fetch, one read and one write. The most common error is treating the instruction fetch as somehow not counting, which understates every answer by exactly one, and the second most common is confusing register indirect with full indirect, which understates full indirect by one.

Because it puts a hard ceiling on what any single improvement can achieve, and that ceiling is set by the part you did not improve. If a fraction f of execution time is sped up by a factor s, the overall speedup is one divided by the quantity one minus f plus f over s. Letting s go to infinity gives one divided by one minus f, which is the best possible outcome even if the improved part becomes instantaneous. So a component consuming 40 per cent of the time can never yield more than a 1.67 times speedup, and a component consuming 10 per cent can never yield more than 1.11. The critical practical point is that f is a fraction of time, not of instruction count. A floating-point instruction class making up a quarter of the instructions but taking eight cycles each against two for everything else consumes well over half the cycles, so it is the right target even though it is a minority of instructions. Conversely, an instruction class that is very frequent but already fast contributes little time and is not worth optimising. This is why performance work begins with measurement rather than intuition, and why the answer to any speedup question should be cross-checked by computing the time fraction explicitly rather than reading the instruction mix.

Each exists because a specific access pattern was common enough that encoding it directly saved more than the decode complexity cost. Immediate serves constants, which appear in a large fraction of instructions. Register serves values already in flight, which after register allocation is the great majority of operands. Direct serves a fixed global variable whose address is known at link time. Register indirect serves a pointer, which is how any dynamically allocated structure is reached. Indexed serves array traversal, where the base stays fixed and the index register advances, and scaled indexing extends it so the index counts elements while the address counts bytes. Base-plus-offset serves two patterns at once: a local variable at a fixed offset from the frame pointer, and a structure field at a fixed offset from an object pointer. PC-relative serves branches and makes code position-independent, which is what shared libraries depend on. Autoincrement folds a pointer update into an access, saving an instruction in tight loops. In a modern load-store architecture the list is much shorter, typically just immediate, register, base-plus-offset and PC-relative, because those four cover almost everything a compiler generates and each additional mode costs decode complexity in every instruction. The examinable content, though, is the full list, since questions are usually about counting accesses and computing effective addresses rather than about which modes a real machine provides.

A per-invocation slot, which is what nesting requires. When a subroutine calls another before returning, two return addresses must coexist. A single dedicated register or fixed memory location holds one, so the second call destroys the first and the outer call eventually returns to the wrong place. A stack holds as many as the nesting depth requires, and the last-in-first-out discipline matches the nesting discipline of calls exactly: the most recently made call is always the first to return. That match is not a coincidence but the reason the structure is used. The same argument extends past the return address. Parameters, local variables and callee-saved registers all need separate copies per invocation, or a recursive call would overwrite its parent's data, so they are grouped into an activation record pushed on entry and popped on exit. The frame pointer gives a stable base within that record so that locals can be reached by fixed compile-time offsets, which is exactly the base-plus-offset addressing mode. Real machines with a link register combine the two approaches. The link register makes a leaf call cheap, since a subroutine that calls nothing never has its link register overwritten and can return without touching memory. Only a non-leaf subroutine pushes the link register as part of its frame, so the cost is paid where it is genuinely needed.
Header Logo