Upload 4
Upload 4
* A computer will usually has a variety of instruction code formats. It is the function of
control unit within the CPU to interpret each instruction code and provide the necessary
control functions needed to process the instruction.
* The bits of the instruction are divided into groups called fields. The most common
fields found in instruction formats are:
1. An operand code field that specifies a memory address to be performed.
2. An address field that designates a memory address or a processor register.
3. A mode field that specifies the way the operand or the effective address is determined.
* Computers with stack organization would have PUSH and POP instructions which
require an address field. Thus the instruction PUSH X will push the word at address
X to the top of the stack. The stack pointer is updated automatically. Operation-type
instructions do not need an address field in stack-organized computers. This is because
the operation is performed on the two items that are on top of the stack. The instruction
ADD in a stack computer consists of an operation code only with no address field. This
operation has the effect of popping the two top numbers from the stack, adding the
numbers, and pushing the sum into the stack. There is no need to specify operands with
an address field since all operands are implied to be in the stack.
Example-1:
Evaluate the following arithmetic statement X = ( A + B ) * ( C + D ) using zero,
one, two or three address instructions.
* Three-Address instructions:
Computer with three-address instruction formats can use each address field to specify
either a processor register or a memory operand.
* Two-Address instructions:
Two-address instructions are the most common in commercial computers. Here again
each address field can specify either a processor register or a memory word.
* One-Address instructions:
One-address instructions use an implied accumulator (AC) register for all data
manipulation. All operations are done between the AC register and a memory operand.
LOAD A // AC ← M[A]
ADD B // AC ← AC + M[B]
STORE T // M[T] ← AC
LOAD C // AC ← M[C]
ADD D // AC ← AC + M[D]
MUL T // AC ← AC * M[T]
STORE X // M[X] ← AC
* Zero-Address instructions:
A stack-organized computer does not use an address field for the instructions ADD and
MUL. The PUSH and POP instructions, however, need an address field to specify the
operand that communicates with the stack.
=> ( A + B ) * ( C + D ) postfix notation => AB + CD + *
PUSH A // TOS ← A
PUSH B // TOS ← B
ADD // TOS ← A + B
PUSH C // TOS ← C
PUSH D // TOS ← D
ADD // TOS ← C + D
MUL // TOS ← (C+D) * (A+B)
POP X // M[X] ← TOS
Addressing mode:
The operation field of an instruction specifies the operation to be performed. This
operation must be executed on some data stored in computer registers or memory words.
The way the operands are chosen during program execution is dependent on the
addressing mode of the instruction. The addressing mode specifies a rule for interpreting
or modifying the address field of the instruction before the operand is actually referenced.
• EA = A + R
• Good for accessing array.
- ADD -- Pop top two items from stack, add, push the result
onto stack.
Summary of addressing mode