3.5 Instruction Formats: Three-Address Machines
3.5 Instruction Formats: Three-Address Machines
∗ 2-address instruction
Opcode Operand 1 Operand 2
∗ 1-address instruction
Opcode Operand 1
∗ 0-address instruction
Opcode
∗ Example:
ADD AX, BX ; AX=AX + BX
MOV EAX, EBX ; EAX EBX
One-address machines
∗ In the early machines, when memory was expensive and slow, a special set of registers
was used to provide an input operand as well as to receive the result from the ALU. These
registers are called the accumulators.
∗ Instructions for these machines need to specify only the address of a single operand.
∗ There is no need to store the result in memory: this
– reduces the need for larger memory
– reduces the number of memory accesses ( speeds up the computation)
∗ Examples:
LDA P ; Load accumulator with P
ADD Q ; Add Q to accumulator
STA R ; Store accumulator in R
INC R1 ; Increment register R1 by 1
DEC R1 ; Decrement register R1 by 1
Zero-address machines
∗ Locations of both operands are assumed to be at a default location.
∗ These machines use the stack as the source of the input operands and the result goes back
into the stack.
Solution:
a)
PUSH A ; Push A onto stack
PUSH B ; Push B onto stack
ADD ; Pull the top two items of the stack, add them, and push A+B
on the stack
PUSH C ; Push C onto stack
PUSH D ; Push D onto stack
SUB ; Subtract top two items and push C-D on the stack
MUL ; Multiply top two items on the stack; that is (C-D) and (A+B)
and push the result
POP Z ; Pull the top item of the stack (the result)