Skip to content
GATEiit

GATE EC · Digital Circuits

Machine instructions and addressing modes

Instruction types and formats, zero- to three-address machines, opcode and field-width calculations including expanding opcodes, and every common addressing mode with its effective address, as GATE EC asks.

Before you start

  • Binary numbers and two's complement →

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

  • Memory organisation →

    Addressing modes are about how the processor forms a memory address; the address width depends on memory size.

  • Logarithms to base 2

    The bits needed to name N items is ⌈log⁡2N⌉.

This topic comes before: ALU, data-path and control unit, Instruction pipelining

Concept notes

1. Machine instructions and the number of addresses

A machine instruction is a binary word the processor decodes and executes. It has an opcode (what to do) and zero or more operand fields (where the data is). The set of all instructions, registers and addressing modes is the instruction set architecture (ISA).

Kinds of instructions: data transfer (LOAD, STORE, MOV, PUSH, POP), arithmetic and logic (ADD, SUB, AND, shifts), control transfer (JUMP, conditional BRANCH, CALL, RETURN) and input/output. Each instruction passes through fetch → decode → operand fetch → execute → write back, and the PC is incremented to the next instruction during fetch.

Machines are classed by how many operand addresses an instruction carries:

Type Example Code for X=(A+B)×C
3-address ADD X, A, B ADD X, A, B; MUL X, X, C (2 instructions)
2-address ADD A, B (A←A+B) MOV X, A; ADD X, B; MUL X, C (3)
1-address (accumulator) ADD A (AC←AC+M[A]) LOAD A; ADD B; MUL C; STORE X (4)
0-address (stack) ADD (pop two, push sum) PUSH A; PUSH B; ADD; PUSH C; MUL; POP X (6)

Fewer addresses give shorter instructions but more of them. A stack machine evaluates the expression in postfix order (AB+C×); only PUSH and POP carry an address.

Load-store (RISC) machines allow memory access only through LOAD and STORE; arithmetic works on registers. CISC machines allow memory operands in arithmetic instructions, with variable-length formats and many modes.

2. Instruction formats and field widths

An instruction word of w bits is split into fields. The rule for every field is

bits needed to name N things=⌈log⁡2N⌉

  • Opcode field for K distinct instructions: ⌈log⁡2K⌉ bits.
  • Register field for R registers: ⌈log⁡2R⌉ bits.
  • Address field for 2m addressable locations: m bits.
  • Mode field for M addressing modes: ⌈log⁡2M⌉ bits.

Whatever is left goes to the immediate or offset field. A k-bit two's complement immediate covers −2k−1 to 2k−1−1.

Expanding opcode. With a fixed word length, instructions with fewer address fields can use the spare bits as extra opcode bits. If the 2-address format has an a-bit opcode and only n2 of the 2a codes are used, each unused code becomes a prefix for 1-address instructions, which gain the bits of one address field (b bits):

n1max⁡=(2a−n2) 2b

The same step repeats for 0-address instructions: unused 1-address codes times 2b. Work level by level: used codes are lost, only free codes expand.

32-bit register-immediate format (32 registers, up to 64 opcodes)opcode6 bits3126Rd5 bits2521Rs5 bits2016immediate / offset16 bits15016-bit expanding opcode: two-address and one-address formatsop4 bits1512address 16 bits116address 26 bits5011114 bits1512ext op6 bits116address6 bits50
Top: a 32-bit register-immediate format with bit positions. Bottom: expanding opcode, where the spare 4-bit code 1111 prefixes a 6-bit extended opcode for one-address instructions.

3. Addressing modes and the effective address

An addressing mode says how the operand field is turned into the operand. The memory address finally used is the effective address (EA). Let A be the address field and R a register.

Mode EA / operand Memory accesses for the operand Typical use
Immediate operand =A itself 0 constants
Register operand =R 0 fast temporaries
Direct (absolute) EA=A 1 global variables
Memory indirect EA=M[A] 2 pointers held in memory
Register indirect EA=R 1 pointers held in a register
Indexed EA=A+Rindex 1 array element A[i] (A = base, register = i)
Base (displacement) EA=Rbase+offset 1 relocatable code, fields of a record, stack frames
PC-relative EA=PC+offset 1 (for data) branches, position-independent code
Auto-increment / decrement EA=R, then R←R±d (or decrement first) 1 stepping through arrays, stack push/pop
Implied operand fixed by the opcode 0 CLC, stack ops, accumulator ops

"Memory accesses" counts those needed to fetch the operand after the instruction itself has been fetched.

Indexed and base modes compute the same sum; the difference is intent. In indexed the address field is the large base address and the register holds a small index; in base mode the register holds the base and the field is a small offset.

addrcontent200450300500500700700900MemoryR2 = 200register indirect: EA = R2 = 200LOADR1A = 300instructiondirect: EA = A = 300index reg R2 = 200+indexed:EA = 300 + 200indirectOperand: immediate 300, direct 500, indirect 700, register indirect 450, indexed 700
One LOAD instruction with address field 300 and register R2 = 200, read under different addressing modes against the same memory.

4. PC-relative branches and auto-increment

PC-relative addressing. By the time an instruction executes, the PC already points to the next instruction. So for an instruction at address a that is L bytes long,

target=(a+L)+offset

The offset is a signed number. Some ISAs store the offset in words and shift it left (multiply by 4 for 4-byte instructions) before adding; read the question for this. Because only the distance is stored, the code still works if the whole program is loaded at a different address: it is position independent.

Auto-increment and auto-decrement. (R)+ uses EA=R and then adds the operand size d to R; −(R) first subtracts d and then uses the new R. With a stack growing downwards, PUSH is −(SP) and POP is (SP)+. The step d equals the operand size in bytes (1, 2, 4 or 8) on a byte-addressable machine.

Byte addressing. In a byte-addressable memory, consecutive 32-bit words are at addresses differing by 4. Sequential instruction fetch therefore does PC←PC+4 for 32-bit instructions.

Subroutine call. CALL saves the return address (the updated PC) on the stack or in a link register and loads the PC with the target; RETURN restores it. Recursion needs the stack version.

Mode Advantage Cost
Immediate no memory access limited by field width
Direct simple address field must cover all memory
Indirect large address space from a small field one extra memory access
Register indirect short field, one access register must be loaded first
PC-relative relocatable, short offset only nearby targets

Formulas to remember

Field widthBits to name N opcodes, registers or locations
b=⌈log⁡2N⌉
Immediate field remainingw = instruction length
bimm=w−bop−∑breg−bmode
Two's complement range
−2k−1≤x≤2k−1−1
Expanding opcodea = opcode bits of the longer format, n2 codes used, b = bits freed (one address field)
n1max⁡=(2a−n2) 2b
Indexed / base address
EA=A+R
Memory indirect
EA=M[A]
PC-relative targeta = address of the branch, L = its length in bytes
target=a+L+offset

Common mistakes

  • Adding a PC-relative offset to the address of the branch itself instead of the updated PC (branch address plus instruction length).
  • In expanding-opcode problems, expanding all 2a codes instead of only the unused ones.
  • Counting the instruction fetch in "memory accesses for the operand" when the question asks only for the operand.
  • Taking log⁡2 of a non power of two without rounding up; 45 opcodes need 6 bits, not 5.
  • Confusing memory indirect (EA=M[A], two accesses) with register indirect (EA=R, one access).
  • Forgetting that a k-bit signed immediate reaches only 2k−1−1 on the positive side.

Worked examples

Try each step yourself, then reveal the working.

Example 1: Sizing the immediate field

numerical

A processor has 32-bit instructions and 32 general-purpose registers. A format holds an opcode, two register fields and a signed immediate. If 45 distinct opcodes must be supported, find the maximum immediate width and its range.

  1. Step 1: Find the opcode width.

    Try it on paper first.

Example 2: Expanding opcode

numerical

A machine has 16-bit instructions and 6-bit address fields. Two-address instructions use a 4-bit opcode. If 14 two-address instructions are defined, how many one-address instructions can be defined at most?

  1. Step 1: Count the free 4-bit codes.

    Try it on paper first.

Example 3: Operand under each addressing mode

numerical

An instruction LOAD R1 has address field 300. Register R2 = 200. Memory: M[200]=450, M[300]=500, M[500]=700, M[700]=900. Find the value loaded into R1 for immediate, direct, memory indirect, register indirect (via R2) and indexed (index register R2) modes.

  1. Step 1: Immediate and direct.

    Try it on paper first.

Example 4: PC-relative branch offset

numerical

On a byte-addressable machine with 4-byte instructions, a branch at address 2000 must jump to address 1992. The offset is in bytes and is added to the updated PC. What offset is stored?

  1. Step 1: Find the PC value when the offset is added.

    Try it on paper first.

Previous year questions

1 official GATE EC question on this topic, newest first.

Topic test

9 questions: up to 1 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 EC syllabus; being checked by a reviewer. Updated 2026-11-29. Spotted a mistake? Use Report an issue on any question, or contact us.