Skip to content
GATEiit

GATE CSE · Computer Organization and Architecture

Instruction set and addressing modes

Instruction formats, opcode and field-width counting (including expanding opcodes), addressing modes and their effective addresses, PC-relative branches and byte ordering, as GATE asks them.

Before you start

  • Binary and two's complement →

    Field widths are powers of two and branch offsets are signed two's complement numbers.

  • Pointers and arrays in C →

    Indirect, indexed and auto-increment modes are how pointers and array loops are compiled.

  • Logarithms base 2

    A field that must name n things needs ⌈log⁡2n⌉ bits.

This topic comes before: Design of control unit: hardwired and microprogrammed, Instruction pipelining and pipeline hazards, Programming in C

Concept notes

1. Instruction formats and the number of addresses

An instruction is an opcode (which operation) followed by operand fields (registers, memory addresses or constants). The instruction set architecture (ISA) is the set of instructions, formats, registers and addressing modes the programmer sees.

Format Example Meaning
3-address ADD R1, R2, R3 R1←R2+R3
2-address ADD R1, R2 R1←R1+R2 (one source is overwritten)
1-address ADD X AC←AC+M[X] (accumulator machine)
0-address ADD pop two values, push their sum (stack machine)

Fewer addresses mean shorter instructions but more instructions per program.

RISC vs CISC

RISC CISC
Instruction length fixed variable
Memory access only LOAD/STORE (load-store architecture) many instructions can use memory operands
Addressing modes few many
Registers many general-purpose fewer
Control unit usually hardwired often microprogrammed
Pipelining easy harder

A field that must name one of n registers needs ⌈log⁡2n⌉ bits. A memory address field for 2m addressable units needs m bits. Whatever is left in a fixed-length instruction is the opcode, and k opcode bits allow at most 2k distinct opcodes.

OpcodeRdRsImmediate / offset8 bits6 bits6 bits12 bits32-bit instruction, 64 registers
A register-immediate format: 8 + 6 + 6 + 12 = 32 bits, so at most 2^8 = 256 opcodes

2. Expanding opcodes

With expanding opcodes, instructions that need fewer address fields reuse the spare bits as extra opcode bits. Instruction length stays fixed.

Method for a w-bit instruction with a-bit address fields:

  1. Two-address instructions have a k=w−2a bit opcode, so 2k patterns. Suppose x are used.
  2. Each of the 2k−x unused patterns becomes a prefix. Appending one a-bit field gives 2a one-address opcodes per prefix: at most (2k−x)⋅2a one-address instructions.
  3. If y one-address instructions are used, at most ((2k−x)2a−y)⋅2a zero-address instructions remain.

A quick check: every instruction type uses up part of the 2w bit patterns. A two-address opcode uses 22a patterns, a one-address opcode 2a, a zero-address opcode 1. So x⋅22a+y⋅2a+z≤2w. This inequality is the fastest way to answer “is this design possible?” questions.

GATE also asks the reverse: given the counts, find the minimum instruction length. Try the smallest w that satisfies the inequality and also leaves at least one opcode bit for the longest format.

3. Addressing modes

The effective address (EA) is the memory address where the operand finally sits. In the table, A is the address field and R a register. “Memory references” counts accesses needed to get the operand, after the instruction is fetched.

Mode Operand / EA Memory refs Typical use
Immediate operand =A 0 constants
Register operand =R 0 fast temporaries
Direct (absolute) EA=A 1 global variables
Memory indirect EA=M[A] 2 pointers stored in memory
Register indirect EA=R 1 pointer held in a register
Indexed EA=A+Rindex 1 array element, A = array start
Base (displacement) EA=Rbase+d 1 locals on the stack, struct fields, relocation
PC-relative EA=PC+d 1 branches, position-independent code
Auto-increment EA=R, then R←R+s 1 walking through an array, stack pop
Auto-decrement R←R−s, then EA=R 1 stack push

Here s is the operand size in addressable units (4 for a 32-bit word on a byte-addressed machine).

Indexed and base modes compute the same sum. The difference is intent: in indexed the instruction holds the array's start and the register the index; in base the register holds the start and the instruction a small offset.

4. PC-relative branches and byte ordering

By the time an instruction executes, the PC has already been incremented during fetch. So for a PC-relative branch target=(address of branch+instruction size)+offset. The offset is a signed two's complement number. A k-bit offset reaches −2k−1 to 2k−1−1 units from the updated PC. If the offset counts words rather than bytes, multiply it by the word size first.

Byte ordering. A multi-byte value at address a occupies a,a+1,…

  • Big endian: the most significant byte goes at the lowest address.
  • Little endian: the least significant byte goes at the lowest address.

For 0x12345678 stored at 100:

Address 100 101 102 103
Big endian 12 34 56 78
Little endian 78 56 34 12

Alignment. A 4-byte word is aligned when its address is a multiple of 4. Aligned access needs one memory cycle; a misaligned word may need two.

Formulas to remember

Bits to name one of n items
⌈log⁡2n⌉
Opcode countk = opcode bits
opcodes≤2k
Expanding opcode budgetx two-address, y one-address, z zero-address instructions; w-bit instruction, a-bit address fields
x 22a+y 2a+z≤2w
PC-relative target
target=PCbranch+size+offset
Signed k-bit offset range
−2k−1≤d≤2k−1−1

Common mistakes

  • Adding the offset to the branch's own address; the PC already points to the next instruction.
  • Forgetting to scale a word offset by the word size on a byte-addressed machine.
  • Counting the instruction fetch when the question asks only for operand memory references.
  • Using log⁡2n without the ceiling: 40 registers need 6 bits, not 5.32.
  • In auto-decrement, using the old register value; pre-decrement changes the register before forming the address.

Worked examples

Try each step yourself, then reveal the working.

Example 1: Maximum number of opcodes

numerical

A processor has 32-bit fixed-length instructions and 64 general-purpose registers. One format holds an opcode, two register fields and a 12-bit immediate. What is the largest number of distinct opcodes this format allows?

  1. Step 1: How many bits does one register field need?

    Try it on paper first.

Example 2: Expanding opcode: how many zero-address instructions?

numerical

Instructions are 12 bits and every address field is 4 bits. There are 14 two-address instructions and 30 one-address instructions. What is the maximum number of zero-address instructions?

  1. Step 1: How many opcode patterns do two-address instructions have?

    Try it on paper first.

Example 3: Operand fetched under five addressing modes

numerical

A LOAD instruction has address field A=500 and uses register R1 = 200. Memory holds M[200] = 600, M[500] = 800, M[700] = 900, M[800] = 300. Find the value loaded under immediate, direct, memory indirect, register indirect (R1) and indexed (A + R1) addressing.

  1. Step 1: Immediate and direct first.

    Try it on paper first.

Example 4: Pick the addressing mode

conceptual

Name the natural addressing mode for: (a) adding the constant 1 to a register, (b) reading a[i] inside a loop where i is in a register, (c) a branch that must work wherever the program is loaded, (d) pushing onto a stack that grows downwards.

  1. Step 1: Which modes need no address at all?

    Try it on paper first.

Previous year questions

15 official GATE CSE questions on this topic, newest first.

Practise these 15 PYQs →

Topic test

10 questions: up to 4 official PYQs and original practice questions, with GATE marking (MCQ wrong answers lose marks). Score 60% or more to pass. A new set is drawn each time.

Mark as mastered

Loading your progress…

My revision notes

Notes written by the GATEiit team against the official GATE CSE syllabus; being checked by a reviewer. Updated 2026-11-21. Spotted a mistake? Use Report an issue on any question, or contact us.