AQA 7517, section 4.7.3.3
Instruction set
A processor instruction set is the complete list of machine code instructions that a particular processor can understand and carry out. It includes operations such as load, store, add, subtract, compare, branch and halt.
An instruction set is processor specific. A program in machine code written for one family of processor (for example Intel x86) can't run on a different one (such as ARM), because each has its own instruction set, with different binary codes and different instructions.
This is why low-level programs aren't portable (4.6.2.1), and why programs must be compiled separately for each type of processor.
Parts of an instruction
Each instruction is a binary pattern made of two parts.
- The opcode (operation code) says what operation to do (add, load, branch...).
- One or more operands give the data for the operation: a value, a memory address or a register.
A simple model
In the model used for exam questions, the addressing mode is part of the opcode bits. The opcode defines both the basic machine operation and the addressing mode (see 4.7.3.4). Students aren't expected to define an opcode, only to interpret it in the context of the question.
Example: an 8-bit instruction is split into:
- 4 bits for the opcode: 3 bits for the basic operation (such as ADD) and 1 bit for the addressing mode;
- 4 bits for the operand.
With 4 bits for the opcode, there are different opcodes possible.
If the question gives the codes:
| Operation bits | Operation |
|---|---|
| 001 | ADD |
| 010 | LOAD |
| 011 | STORE |
| Mode bit | Addressing mode |
|---|---|
| 0 | Immediate |
| 1 | Direct |
then the instruction 0010 0101 can be interpreted as:
- opcode
0010= operation001(ADD) + mode0(immediate); - operand
0101= 5; - so it means ADD the value 5.
The instruction 0011 0101 has the same operation, but mode 1 (direct), so it means ADD the value stored at address 5.
How many instructions can there be?
The number of different opcodes is . The operand size limits the values or addresses an instruction can refer to: a 4-bit operand can only give a value from 0 to 15, or address 16 locations.
| Opcode bits | Operand bits | Instruction length | Opcodes possible | Operand range |
|---|---|---|---|---|
| 4 | 4 | 8 | 16 | 0 to 15 |
| 6 | 10 | 16 | 64 | 0 to 1023 |
| 8 | 24 | 32 | 256 | 0 to 16 777 215 |
There's a trade-off: more opcode bits give more operations, but leave fewer bits for the operand.
Worked example
Task: an instruction is 12 bits long: 5 bits opcode and 7 bits operand. (a) How many different opcodes are possible? (b) What is the largest value or address that the operand can hold? (c) Why could the same program not run on a different processor family?
- (a) opcodes.
- (b) .
- (c) Different processors have different instruction sets: the same binary pattern may mean different operations, or may not exist. The program would have to be translated again for the other processor.
Exam tip: an instruction is an opcode plus operand(s). If a question gives you the bit allocation, use it. The number of possible opcodes is for opcode bits. Interpret the operand using the addressing mode given.
Check yourself
What is an instruction set?
The complete list of machine code instructions that a particular processor can execute.
What are the two parts of a machine code instruction?
An opcode (the operation) and one or more operands (the value, memory address or register to use).
An opcode has 6 bits. How many different opcodes are there?
.
Why can't machine code written for one processor run on another family of processor?
An instruction set is processor specific, so the binary instructions mean different things (or don't exist) on a different processor.