Instruction Formats in Computer Architecture

An instruction is a command given to the processor to perform a specific task. The format of these instructions depends on the internal organization of the CPU registers and memory. Based on the number of address fields, instructions are classified into four main types.

1. Three-Address Instructions

These instructions specify two source operands and one destination operand. While they result in very short programs, the instructions themselves are long because they require multiple bits for three addresses.

TEXT
Format: ADD R1, A, B  ; R1 = M[A] + M[B]

2. Two-Address Instructions

This is the most common format in modern commercial computers. One address acts as both a source and the destination. This reduces the instruction length compared to the three-address format.

TEXT
Format: ADD R1, R2     ; R1 = R1 + R2

3. One-Address Instructions

These use an implied register called the **Accumulator (AC)** for all operations. The instruction only needs to specify one memory address or register.

TEXT
Format: ADD X          ; AC = AC + M[X]

4. Zero-Address Instructions

These are found in stack-organized computers. Operands are taken from the top of the stack, and results are pushed back onto the stack. No address is needed for arithmetic operations.

TEXT
Format: ADD            ; TOS = Top of Stack + Next on Stack

Comparison Table

TypeCPU OrganizationInstruction LengthProgram Length
Three-AddressGeneral RegisterLongestShortest
Two-AddressGeneral RegisterMediumMedium
One-AddressAccumulatorShortLong
Zero-AddressStackShortestLongest

Common Mistakes to Avoid

  • Assuming 'Zero-Address' means the computer has no memory addresses (it just doesn't use them in arithmetic instructions).
  • Thinking Three-Address instructions are faster because the program is shorter (they often take more clock cycles to decode).
  • Confusing 'Address' with 'Data' (the address points to where the data is stored).
  • Forgetting that One-Address instructions always overwrite the Accumulator.

Advanced Concepts

  • Variable-length instructions
  • Opcode Encoding
  • Register-to-Memory vs Register-to-Register
  • Instruction Set Orthogonality
  • Expanding Opcodes

Practice Exercises

  • Write the code to evaluate X = (A+B)*(C+D) using One-Address instructions.
  • Explain why RISC processors prefer Register-to-Register (Three-Address) instructions.
  • How many bits are needed for an instruction if the CPU has 16 registers and uses Two-Address format?
  • Identify the destination operand in 'SUB R1, R2' for an x86-based system.

Conclusion

Choosing an instruction format is a balance between hardware complexity and software efficiency. While simple Accumulator systems were common in early computing, modern architectures use a mix of Two and Three-address formats to maximize performance.

Note: Note: Modern x86 processors primarily use a Two-Address format, while ARM (RISC) often uses Three-Address instructions for its ALU operations.