Fundamentals of the Instruction Set
1. Instruction Format
The Basic Structure of an Instruction
An instruction consists of:
- Operation code: specifies the type of operation
- Address code: specifies the address of the operand
- Instruction length: either fixed or variable
The fields of an instruction:
- Operation code field: encodes the type of operation
- Address field: encodes the address of the operand
- Control field: encodes control information
Fixed-Length Opcode Format
Basic characteristics:
- The length of the operation code is fixed
- It is easy for the hardware to decode
- All instructions have the same length
Example of the format:
Advantages:
- Simple decoding: the hardware implementation is straightforward
- Fast execution: strong parallel processing capability
- Simple control: a uniform instruction cycle
Disadvantages:
- Wasted space: some instructions do not need all the address fields
- Poor flexibility: hard to accommodate complicated instructions
Expanding Opcode Format
Basic characteristics:
- The length of the operation code varies
- It saves storage space
- It supports complicated instructions
Examples of the format:
With a 4-bit opcode, the address field takes 12 bits
With an 8-bit opcode, the address field takes 8 bits
With a 12-bit opcode, the address field takes only 4 bits
Advantages:
- Space efficiency: the instruction space is used thoroughly
- High flexibility: instructions of different complexity are supported
- Good extensibility: new instructions are easy to add
Disadvantages:
- Complicated decoding: the hardware implementation is complex
- Slow execution: multi-level decoding is required
2. Addressing Modes
Basic Concepts
Effective address:
- The actual location in which the operand is stored
- It is computed by the addressing mode
- It affects the efficiency of instruction execution
A classification of addressing modes:
- Data addressing: how the address of an operand is computed
- Instruction addressing: how the address of the next instruction is computed
Immediate Addressing
Basic concepts:
- The operand is contained directly in the instruction
- No memory access is needed
- It executes fastest of all
Format:
Characteristics:
- Advantage: fast execution, no memory access
- Disadvantage: the size of the operand is limited
- Application: constant assignment, immediate arithmetic
Direct Addressing
Basic concepts:
- The address code is the address of the operand
- One memory access is needed
- The range of addresses is limited by the width of the address code
Format:
Characteristics:
- Advantage: simple address calculation
- Disadvantage: the range of addresses is limited
- Application: accessing data at a fixed address
Indirect Addressing
Basic concepts:
- The address code holds the address of the address of the operand
- Two memory accesses are needed
- It supports dynamic address computation
Format:
Characteristics:
- Advantage: supports dynamic addresses
- Disadvantage: two memory accesses are needed
- Application: pointer operations, dynamic addressing
Register Addressing
Basic concepts:
- The operand is in a register
- No memory access is needed
- It executes very quickly
Format:
Characteristics:
- Advantage: fast execution
- Disadvantage: the number of registers is limited
- Application: data that is accessed frequently
Register Indirect Addressing
Basic concepts:
- A register holds the address of the operand
- One memory access is needed
- It supports base addressing
Format:
Characteristics:
- Advantage: supports dynamic addresses
- Disadvantage: a memory access is needed
- Application: array access, pointer operations
Base Addressing
Basic concepts:
- Effective address = base register + address code
- It supports program relocation
- It widens the range of addresses
Format:
Characteristics:
- Advantage: supports program relocation
- Disadvantage: a base register is required
- Application: program loading, address translation
Indexed Addressing
Basic concepts:
- Effective address = index register + address code
- It supports array access
- It makes loop control convenient
Format:
Characteristics:
- Advantage: supports array access
- Disadvantage: an index register is required
- Application: array processing, loop control
Relative Addressing
Basic concepts:
- Effective address = PC + displacement
- It supports program relocation
- The instruction is independent of its position
Format:
Characteristics:
- Advantage: supports program relocation
- Disadvantage: the range of addresses is limited
- Application: jump instructions, branch instructions
3. Instruction Classification
By Function
Data transfer instructions:
- LOAD: from memory into a register
- STORE: from a register into memory
- MOVE: between two registers
- PUSH/POP: stack operations
Arithmetic instructions:
- ADD/SUB: addition and subtraction
- MUL/DIV: multiplication and division
- INC/DEC: increment and decrement
- NEG: negation
Logic instructions:
- AND/OR/XOR: logical operations
- NOT: logical negation
- SHL/SHR: shift operations
- ROL/ROR: rotate operations
Control transfer instructions:
- JMP: unconditional jump
- JZ/JNZ: conditional jump
- CALL/RET: subroutine call and return
- LOOP: loop control
Input and output instructions:
- IN: input operation
- OUT: output operation
- IO: input and output control
By the Number of Operands
Zero-address instructions:
- The operands are implied by the instruction
- Examples: NOP, HALT
One-address instructions:
- One explicit operand, the other is implied
- Examples: INC, DEC, NOT
Two-address instructions:
- Two operands
- Examples: ADD, SUB, MOVE
Three-address instructions:
- Three operands
- Examples: ADD R1, R2, R3
By Instruction Length
Single-byte instructions:
- The instruction is 1 byte long
- The operation is simple and execution is fast
Two-byte instructions:
- The instruction is 2 bytes long
- It contains the operation code and the address code
Multi-byte instructions:
- The instruction is longer than 2 bytes
- It supports complicated operations and long addresses
4. Instruction Set Design
Design Principles
Completeness:
- Support every operation that is needed
- Cover the requirements of the applications
- Make program development easier
Orthogonality:
- The operation codes and the addressing modes are independent of each other
- The number of instructions is reduced
- The encoding efficiency is improved
Symmetry:
- Similar operations use similar formats
- The set is easier to learn and to use
- The design complexity is reduced
Performance Considerations
Instruction density:
- Raise the code density
- Reduce the space needed in memory
- Improve the efficiency of the cache
Execution efficiency:
- Shorten the instruction cycle
- Raise the degree of parallelism
- Optimise the critical path
Compatibility:
- Backwards compatibility
- Support for extensions
- Adaptation to the progress of technology
Exercise 1
Briefly state the difference between the fixed-length opcode format and the expanding opcode format.
Approach: Compare the two formats on the six axes that matter in practice — the length of the operation code, the complexity of the hardware, the speed of execution, the use of the instruction space, the flexibility of the format, and how easy it is to extend the set.
Steps:
- Length of the operation code: with a fixed-length opcode the length of the operation code is fixed; with an expanding opcode the length varies.
- Hardware complexity: a fixed-length opcode decodes simply and the hardware is straightforward; an expanding opcode needs multi-level decoding and a complex hardware implementation.
- Execution efficiency: a fixed-length opcode executes quickly and has strong parallel processing capability; an expanding opcode executes more slowly because multi-level decoding is required.
- Space efficiency: a fixed-length opcode wastes space because some instructions do not need all the address codes; an expanding opcode uses the instruction space efficiently.
- Flexibility: a fixed-length opcode is inflexible and hard to adapt to complicated instructions; an expanding opcode is flexible and supports instructions of different complexity.
- Extensibility: a fixed-length opcode is hard to extend; an expanding opcode is easy to extend, so new instructions can be added without redesigning the format.
Answer: A fixed-length opcode gives a uniform, fast, simple-to-decode format at the cost of wasted encoding space and poor extensibility, while an expanding opcode packs far more instructions into the same space and scales to new instructions at the cost of a slower, more complex decoder. The choice is a trade-off between decode simplicity and encoding density.
Exercise 2
Give an example that shows the difference between direct addressing and indirect addressing.
Approach: Define each mode in terms of the address code, the instruction form, the number of memory accesses, and the address computation, and then run the same instruction over a small memory image to show the different results.
Steps:
- Direct addressing:
- The address code is the address of the operand
- Format:
LOAD R1, [1000] - Meaning: load the data at address 1000 into register R1
- Number of memory accesses: 1
- Address computation: the address code is used directly
- Indirect addressing:
- The address code holds the address of the address of the operand
- Format:
LOAD R1, [[1000]] - Meaning: take the contents of address 1000 as an address, then load the data at that address into register R1
- Number of memory accesses: 2
- Address computation: fetch the address first, then fetch the data
- The worked example: assume the memory holds
- Address 1000: the stored value 2000
- Address 2000: the stored value 42
- Direct addressing:
LOAD R1, [1000]→ R1 = 2000 - Indirect addressing:
LOAD R1, [[1000]]→ R1 = 42
Answer: Direct addressing uses the address code as the address of the operand and costs one memory access, while indirect addressing treats the address code as a pointer to the operand and costs two. In the example the direct form loads 2000 and the indirect form loads 42.
| Term | Abbreviation | Explanation |
|---|---|---|
| Instruction | - | A basic operation that the computer executes |
| Instruction set | - | The complete set of instructions a computer has |
| Instruction format | - | The binary encoding structure of an instruction |
| Operation code | Opcode | The field of an instruction that specifies the type of operation |
| Address code | - | The field of an instruction that specifies the address of the operand |
| Addressing mode | - | The way the address of an operand is found |
| Immediate addressing | - | The operand is contained directly in the instruction |
| Direct addressing | - | The address code is the effective address |
| Indirect addressing | - | The address code points to the effective address |
| Register addressing | - | The operand is in a register |
| Register indirect addressing | - | The effective address is in a register |
| Relative addressing | - | Effective address = PC + displacement |
| Base addressing | - | Effective address = base register + displacement |
| Indexed addressing | - | Effective address = index register + displacement |
| Stack addressing | - | The operand is at the top of the stack |
| Zero-address instruction | - | An instruction with no address code |
| One-address instruction | - | An instruction with one address code |
| Two-address instruction | - | An instruction with two address codes |
| Three-address instruction | - | An instruction with three address codes |
| Instruction word length | - | The number of binary bits in one instruction |
| Expanding opcode | - | An encoding with a variable-length operation code |
| Program counter | PC | Holds the address of the next instruction |
| Instruction register | IR | Holds the instruction currently being executed |
