CSC213 ยท 2078 ยท 5 marks
What do you mean by instruction format? Explain with an example.
What do you mean by instruction format? Explain with an example. [5]
Quick answer
An instruction format defines the layout or structure of a binary instruction stored in memory. It specifies how the bits of an instruction are divided into different fields, each carrying specific information needed by the CPU to execute that instruction.
Instruction Format
Definition
The simplest way to organize a computer is to have a single processor register called the accumulator, and an instruction format with two parts:
- First part (Opcode field): Specifies the operation to be performed (e.g., ADD, SUB, LOAD, STORE).
- Second part (Address field): Specifies the memory address where the operand is located, i.e., tells the control unit where to find the operand in memory.
General Structure of an Instruction Format
+------------------+----------------------+
| Opcode (bits) | Address (bits) |
+------------------+----------------------+
Example: Basic Computer Instruction Format (16-bit)
In a basic computer, each instruction is 16 bits long, organized as follows:
Bit position: 15 14 13 12 11 10 9 ... 0
+-------+---+---+-------+---+---+-------+
| I | Opcode (3) | Address (12) |
+-------+---+---+-------+---+---+-------+
| Field | Bits | Purpose |
|---|---|---|
| I (Indirect bit) | Bit 15 | Indicates direct (0) or indirect (1) addressing |
| Opcode | Bits 12 to 14 | Specifies the operation (3 bits = 8 possible operations) |
| Address | Bits 0 to 11 | Specifies the memory address of the operand (12 bits = 4096 locations) |
How It Works During Fetch and Decode
According to the fetch-decode cycle:
- T0:
AR <- PC(Address Register gets the Program Counter value) - T1:
IR <- M[AR], PC <- PC + 1(Instruction is fetched from memory into Instruction Register) - T2:
Decode IR(12-14), AR <- IR(0-11), I <- IR(15)(Opcode bits 12-14 are decoded; address bits 0-11 are loaded into AR; indirect bit is noted)
Example Instruction
Suppose a 16-bit instruction is:
0 001 000000000101
^ ^ ^
I Opcode Address (5)
- I = 0 โ Direct addressing
- Opcode = 001 โ Could represent an ADD operation
- Address = 5 โ Operand is located at memory address 5
This means: "Add the value stored at memory location 5 to the accumulator directly."
Summary
Instruction format is essential because it tells the CPU what to do (opcode) and where to find the data (address). The design of the instruction format directly affects the number of operations supported and the size of addressable memory.
Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.