1. Gyanastra
  2. Computer Organisation and Architecture
  3. UGC NET: Basic Computer Design and Programming
  4. Instruction Codes Registers and Instruction Set
Free lesson, no account needed 13 min read 19 practice questions after it
Asked in past papers4 times
  • GATE CSE20052004
  • UGC NET20202019

Computer Organisation and Architecture · UGC NET: Basic Computer Design and Programming

Instruction Codes Registers and Instruction Set

Overview

This lesson covers how a processor encodes an instruction, where it keeps the current instruction and data, how it finds the operand through different addressing modes, and how the basic computer instruction set is organised.
It uses the standard Morris Mano basic computer convention: a 16-bit word, 12-bit addresses, and 16-bit instructions.
You must already know binary and hexadecimal conversion, the idea of a register, and how memory words are addressed.
These concepts are directly tested through instruction-format bit calculations, effective-address calculations, hex instruction decoding, and small program traces.

Key concepts

  • Instruction code: a binary pattern that tells the CPU what operation to perform and where the operand is. It normally contains an operation code (opcode), one or more address fields, and addressing-mode bits.
  • Operand: the data on which the instruction acts. It may be in the instruction itself, in a register, or in memory.
  • Effective address (EA): the actual memory address from which the operand is fetched or to which it is stored after the addressing mode is applied.
  • In the basic computer, the 16-bit instruction format is: bit 15 = I (addressing mode), bits 14–12 = 3-bit opcode, bits 11–0 = 12-bit address/operation field.
  • For a memory-reference instruction, I = 0 means direct addressing and I = 1 means indirect addressing.
    Opcode 111 is reserved: with I = 0 it is a register-reference instruction;
    with I = 1 it is an input-output instruction.
  • Basic computer registers: AR Address Register, 12 bits; PC Program Counter, 12 bits; IR Instruction Register, 16 bits; DR Data Register, 16 bits; AC Accumulator, 16 bits; TR Temporary Register, 16 bits; INPR Input Register, 8 bits; OUTR Output Register, 8 bits; SC Sequence Counter, 4 bits.
  • Basic computer memory: 4096 words of 16 bits each, so 12 address bits are enough because 212=40962^{12}=4096.
  • The basic computer has 25 instructions: 7 memory-reference, 12 register-reference, and 6 input-output.
  • Memory-reference opcodes: AND = 000, ADD = 001, LDA = 010, STA = 011, BUN = 100, BSA = 101, ISZ = 110.
  • Register-reference hex codes include CLA = 7800, CLE = 7400, CMA = 7200, CME = 7100, CIR = 7080, CIL = 7040, INC = 7020, SPA = 7010, SNA = 7008, SZA = 7004, SZE = 7002, HLT = 7001.
  • Input-output hex codes include INP = F800, OUT = F400, SKI = F200, SKO = F100, ION = F080, IOF = F040.
  • Immediate addressing: operand is given explicitly in the instruction itself; no memory reference is needed to fetch the operand.
  • Register addressing: operand is in a register named by the instruction.
  • Direct addressing: address field itself is the EA; operand is in memory at that address.
  • Indirect addressing: address field gives the address of a memory location that contains the effective address of the operand.
  • Register indirect addressing: the instruction names a register; that register contains the memory address of the operand. This can reference memory without placing a full memory address in the instruction.
  • Indexed addressing: EA = address field + contents of an index register. It is useful for arrays.
  • Relative addressing: EA = updated PC + signed displacement. It is useful for position-independent code.
  • Base/displacement addressing: EA = displacement + contents of a base register; used for relocation and structured data.
  • Program control instructions change the Program Counter: jump, branch, call, return, skip. Shift instructions such as SHL are arithmetic/logical instructions, not program control instructions.
  • Hardwired control unit: fixed logic gates and decoders; fast but difficult to modify. Microprogrammed control unit: control signals come from a control memory; slower but flexible.

How it works

  1. Fetch: AR is loaded from PC; the memory word at AR is copied to IR; PC is incremented so it points to the next instruction.
  2. Decode: the opcode and the I bit are decoded.
    If the instruction is a memory-reference instruction and I = 1, the CPU performs an indirect memory read: AR is loaded from memory at the address field.
    That value becomes the effective address.
  3. Execute: the operation is performed according to the opcode. For a direct memory-reference instruction, EA is the 12-bit address field itself.
    For an indirect memory-reference instruction, EA is the word fetched from that address field.
  4. Update: AC, flags, memory, or PC is updated depending on the instruction. Then the next instruction is fetched.

Basic computer memory-reference semantics:

  • AND X: AC←AC∧M[X]AC \leftarrow AC \land M[X]
  • ADD X: AC←AC+M[X]AC \leftarrow AC + M[X]
  • LDA X: AC←M[X]AC \leftarrow M[X]
  • STA X: M[X]←ACM[X] \leftarrow AC
  • BUN X: PC←XPC \leftarrow X
  • BSA X: M[X]←PCM[X] \leftarrow PC, then PC←X+1PC \leftarrow X+1. This stores the return address in the first word of the subroutine and starts execution at the next word.
  • ISZ X: M[X]←M[X]+1M[X] \leftarrow M[X]+1; if the new value is zero, skip the next instruction by incrementing PC once more.

Register-reference and input-output instructions use the 12-bit field as a one-hot operation code. For example, 7200 has I = 0, opcode 111, and bit 9 set, so it is CMA. F200 has I = 1, opcode 111, and bit 9 set, so it is SKI. The I bit is the primary discriminator between register-reference and I/O instructions.

Figure. Notice that the I bit selects a direct or indirect effective address before execute, and the cycle ends by updating AC, flags, or PC before fetching the next instruction.

Formulas

  • Address bits for NN addressable words: a=⌈log⁡2N⌉a=\lceil \log_2 N \rceil.
  • Address bits for byte-addressable memory of capacity 2m2^m KB: a=m+10a=m+10 because 2m KB=2m+102^m \text{ KB}=2^{m+10} bytes.
  • Opcode bits for 2n2^n operations: nn bits. For kk operations: ⌈log⁡2k⌉\lceil \log_2 k \rceil.
  • Register-code bits for RR registers: ⌈log⁡2R⌉\lceil \log_2 R \rceil.
  • Mode bits for MM addressing modes: ⌈log⁡2M⌉\lceil \log_2 M \rceil.
  • Instruction length: L=opcode bits+mode bits+register bits+address bits for all address fieldsL=\text{opcode bits}+\text{mode bits}+\text{register bits}+\text{address bits for all address fields}.
  • Direct EA: EA=AEA=A.
  • Indirect EA: EA=M[A]EA=M[A], where AA is the address field.
  • Register indirect EA: EA=[R]EA=[R], where [R][R] means contents of register RR.
  • Indexed EA: EA=A+[R]EA=A+[R].
  • Relative EA: EA=PC+AEA=PC+A, where PCPC is the updated PC pointing to the next instruction after fetch.
  • Base register EA: EA=A+[BR]EA=A+[BR].

Worked examples

Example 1: Effective address for four modes.
An instruction is at address 600, its address field is 350, register R2 contains 120, memory word 350 contains 900, and after the instruction and its address word are fetched PC = 602. Find the EA for direct, indirect, indexed with R2, register indirect with R2, and relative modes.

  • Direct: EA=A=350EA=A=350.
  • Indirect: EA=M[350]=900EA=M[350]=900.
  • Indexed with R2: EA=A+[R2]=350+120=470EA=A+[R2]=350+120=470.
  • Register indirect with R2: EA=[R2]=120EA=[R2]=120.
  • Relative: EA=PC+A=602+350=952EA=PC+A=602+350=952.

The key trap is that relative addressing uses the updated PC, not the instruction address 600.

Example 2: Instruction bit allocation.
A computer has 128K words of 32 bits each. One instruction uses an opcode, a 1-bit direct/indirect mode field, a register field for 32 registers, and one address field. Find the number of bits in each field.

Memory has 128K=128×1024=27×210=217128K=128\times1024=2^7\times2^{10}=2^{17} words, so address field = 17 bits.
32 registers need log⁡232=5\log_2 32=5 bits.
Two addressing modes need 1 bit.
Total bits = 32.
Opcode bits = 32−17−5−1=932-17-5-1=9.
So the fields are: opcode 9, mode 1, register 5, address 17. Check: 9+1+5+17=329+1+5+17=32.

Example 3: Decode basic computer hex instructions.
Decode the following 16-bit instructions using the basic computer format.

Hex codeBinary splitMeaning
7200I = 0, opcode 111, bit 9 = 1CMA
F200I = 1, opcode 111, bit 9 = 1SKI
4005I = 0, opcode 100, address 005BUN direct to 005
7002I = 0, opcode 111, bit 1 = 1SZE
A00BI = 1, opcode 010, address 00BLDA indirect through 00B
7800I = 0, opcode 111, bit 11 = 1CLA
F800I = 1, opcode 111, bit 11 = 1INP

Remember that 0xF800 is an input-output instruction, not a register-reference instruction, because the I bit is 1.

Example 4: Trace a small basic computer program.
Locations and contents:
100: CLA
101: ADD 105
102: INC
103: STA 106
104: HLT
105: 1234H
106: 0000H

Trace:
100 CLA makes AC = 0000H.
101 ADD 105 makes AC = 0000H + 1234H = 1234H.
102 INC makes AC = 1235H.
103 STA 106 stores 1235H into memory location 106.
104 HLT stops.
Final accumulator content = 1235H.

Example 5: BSA return address.
A BSA instruction is at address 0100H, and its effective address is 0200H; the subroutine starts at 0201H. What is stored in the memory word at 0200H?

During fetch, PC becomes 0101H, the address of the instruction after BSA. BSA stores PC into M[EA], so M[0200H]←0101HM[0200H] \leftarrow 0101H, then PC←0201HPC \leftarrow 0201H. Thus the return address stored is 0101H.

Comparison

Addressing modes

ModeWhere operand isEA or operand ruleExtra memory reference for operandTypical trap
ImmediateIn instructionOperand = address field0Address field is data, not address
RegisterIn registerOperand = [R]0Instruction names register, not memory
DirectIn memoryEA = A1Address field is the EA
IndirectIn memoryEA = M[A]2Address field points to address of operand
Register indirectIn memoryEA = [R]1Instruction contains register number, not full address
IndexedIn memoryEA = A + [R]1Add index register to address field
RelativeIn memoryEA = PC + A1Use updated PC
Base registerIn memoryEA = A + [BR]1Base register supplies relocation base

Basic computer instruction groups

GroupOpcode bitsI bitUse of 12-bit fieldExamples
Memory-reference000 to 1100 direct, 1 indirectAddressAND, ADD, LDA, STA, BUN, BSA, ISZ
Register-reference1110One-hot register operationCLA, CMA, INC, SZA, HLT
Input-output1111One-hot I/O operationINP, OUT, SKI, SKO, ION, IOF

Hardwired vs microprogrammed control

FeatureHardwired controlMicroprogrammed control
ImplementationFixed logic gates and decodersControl memory stores microinstructions
SpeedFasterSlower
FlexibilityDifficult to changeEasy to modify
Exam pointCan be optimised for fast operationUses control word sequencing

Revision summary

  • Basic computer instruction: 1 bit I + 3 bits opcode + 12 bits address = 16 bits.
  • 4096 words need 12 address bits; 512K words need 19 bits; 256K words need 18 bits; 128K words need 17 bits.
  • Direct addressing: address field = EA. Indirect addressing: address field points to the word holding EA.
  • Indirect mode needs two memory references to fetch the operand: one for the address, one for the operand.
  • Register indirect can reference memory without a full memory address in the instruction.
  • Indexed EA = address field + index register. Relative EA = updated PC + displacement.
  • Opcode 111 with I = 0 is register-reference; opcode 111 with I = 1 is input-output.
  • CLA = 7800, CMA = 7200, INC = 7020, HLT = 7001, INP = F800, SKI = F200.
  • BSA stores the return address at the subroutine’s first word and jumps to the next word.
  • ISZ increments memory and skips the next instruction when the result becomes zero.
  • Hardwired control is fast; microprogrammed control is flexible.
  • Check the I bit before decoding any instruction beginning with hex 7 or F.

Previous-year exam insights

  • Matching addressing modes with effective addresses is common: compute direct, indirect, indexed, register-indirect, and relative one by one; do not mix the address field with the register value.
  • Mode-identification questions use wording clues: “operand explicitly in instruction” = immediate; “address in a register” = register indirect; “constant added to register” = indexed; “PC plus displacement” = relative.
  • Instruction-format numerical questions ask for opcode, mode, register, and address bits.
    Convert memory capacity to address bits first, then subtract all known fields from the word size.
  • Basic computer hex decoding questions test the 16-bit split: top bit is I, next three bits are opcode, remaining 12 bits are address or one-hot operation code.
  • Program-trace questions require following CLA, ADD, INC, STA, LDA, CMA, AND, BUN, HLT, BSA, and ISZ exactly; write the accumulator and memory values after each line.
  • Statement-type questions often combine hardwired control speed with the extra memory reference needed by indirect addressing; both are standard textbook facts.
  • A frequent trap is using the instruction address instead of the updated PC in relative addressing, or treating register indirect as direct addressing.
  • Another trap is miscounting memory: 512K words is 2192^{19} words, while 2m2^m KB byte-addressable memory needs m+10m+10 address bits.

Practice at PARIKSHA

You are ready for the PARIKSHA tests of this sub-topic when you can:

  • Decode any 16-bit basic computer instruction into I bit, opcode, and address/operation field.
  • Compute effective addresses for direct, indirect, register, register indirect, indexed, relative, and base modes.
  • Calculate opcode, mode, register, and address field sizes from memory capacity, register count, and word length.
  • Explain why register indirect addressing can reference memory without a full address in the instruction.
  • Explain why indirect addressing needs an extra memory reference to fetch the operand.
  • List the basic computer registers with their sizes and functions.
  • Trace a short basic computer program using memory-reference and register-reference instructions.
  • State the exact behaviour of BUN, BSA, and ISZ, including return-address storage and skip-on-zero.
  • Distinguish memory-reference, register-reference, and I/O instructions directly from their hex codes.
  • Compare hardwired and microprogrammed control, and avoid the common direct/indirect and PC-update traps.

Attempt the PARIKSHA sub-topic test first, then the subject test.

Pages 1–2 of 2