The most common fields found in instruction formats are:
- An operation code field(
opcode) - An
address fieldthat designates a memory address or register. - A mode field (
addressing mode field)
Operations specified by computer instructions are executed on data stored in memory or processor register. Number of address fields in the instruction can vary depending on the internal organization of its registers. There are mainly three type of CPU organizations:
- Single accumulator organization
- General register organization
- Stack organization
Some notations to remember
ADD X # AC <- AC + M[X]
# AC is accumulator register
# M[x] is the word located at address X
ADD R1, R2, R3 # R1 <- R2 + R3
ADD R1, R2 # R1 <- R1 + R2
ADD R1, X # R1 <- R1 + M[X]
MOV R1, R2 # R1 <- R2 (or R2 -> R1) Depending on the assembly style
PUSH X # push the word at address X to the top of the stack
ADD # Perform add on the two items that are on the top of the stack
Three address instructions
- can use each address field to specify either a processor register or memory operand.
Advantage
- It results in short progranwhen evaluating arithmatic expressions.
Disadvantage
- Instructions require too many bits
Example
Let’s evaluate X = (A + B)*(C + D) with three address
ADD R1, A, B # R1 <- M[A] + M[B]
ADD R2, C, D
MUL X, R1, R2 # M[X] <- R1 * R2
Two address instructions
- can use each address field to specify either a processor register or memory operand.
Example
Let’s evaluate X = (A + B)*(C + D) with two address
MOV R1, A
ADD R1, B
MOV R2, C
ADD R2, D
MUL R1, R2
MOV X, R1
One address instructions
- Uses an implied accumulator (AC)
Example
Let’s evaluate X = (A + B)*(C + D) with one address
LOAD A # AC <- M[A]
ADD B
STORE T # M[T] <- AC, here T is the address of a temporary memory location
LOAD C
ADD D
MUL T # AC <- AC * M[T]
STORE X # M[X] <- AC
NOTE
LOAD is used to load data from memory to accumulator.
STORE is used to store the accumulator result in memory.
Both LOAD and STORE are 1-address instructions.
MOV is used to move contents of a register to memory and vice versa or from one register to another
MOV is a 2-address instruction.
Zero address instructions
- A stack organized computer does not use an address field for the instruction
ADDandMUL. PUSH&POPinstructions need an address field to specify the operandTOSstands top of the stack- It’s called
Zero-addressbecause of the absence of an address field in the computational instructions(ADD,MUL).
Example
Let’s evaluate X = (A + B)*(C + D) with Zero address
PUSH A
PUSH B
ADD
PUSH C
PUSH D
ADD
MUL
POP X # M[X] <- TOS