Information Technology Reference
In-Depth Information
the operation to be performed is addition. It also indicates that the values to be added
are those stored in registers R 1 and R 2 that the results should be stored in register R 3 .
An example of a three-address instruction that refers to memory locations may take
the form ADD A,B,C. The instruction adds the contents of memory location A to the
contents of memory location B and stores the result in memory location C.
A two-address instruction takes the form operation add-1, add-2. In this form,
each of add-1 and add-2 refers to a register or to a memory location. Consider,
for example, the instruction ADD R 1 ,R 2 . This instruction adds the contents of regis-
ter R 1 to the contents of register R 2 and stores the results in register R 2 . The original
contents of register R 2 are lost due to this operation while the original contents of
register R 1 remain intact. This instruction is equivalent to a three-address instruction
of the form ADD R 1 ,R 2 ,R 2 . A similar instruction that uses memory locations instead
of registers can take the form ADD A,B. In this case, the contents of memory location
A are added to the contents of memory location B and the result is used to override
the original contents of memory location B.
The operation performed by the three-address instruction ADD A,B,C can be per-
formed by the two two-address instructions MOVE B,C and ADD A,C. This is
because the first instruction moves the contents of location B into location C and
the second instruction adds the contents of location A to those of location C (the con-
tents of location B) and stores the result in location C.
A one-address instruction takes the form ADD R 1 . In this case the instruction
implicitly refers to a register, called the Accumulator R acc , such that the contents
of the accumulator is added to the contents of the register R 1 and the results are
stored back into the accumulator R acc . If a memory location is used instead of a reg-
ister then an instruction of the form ADD B is used. In this case, the instruction
adds the content of the accumulator R acc to the content of memory location B and
stores the result back into the accumulator R acc . The instruction ADD R 1 is equival-
ent to the three-address instruction ADDR 1 ,R acc ,R acc or to the two-address instruc-
tion ADDR 1 ,R acc .
Between the two- and the one-address instruction, there can be a one-and-half
address instruction. Consider, for example, the instruction ADD B,R 1 . In this case,
the instruction adds the contents of register R 1 to the contents of memory location
B and stores the result in register R 1 . Owing to the fact that the instruction uses
two types of addressing, that is, a register and a memory location, it is called a
one-and-half-address instruction. This is because register addressing needs a smaller
number of bits than those needed by memory addressing.
It is interesting to indicate that there exist zero-address instructions. These are the
instructions that use stack operation. A stack is a data organization mechanism in
which the last data item stored is the first data item retrieved. Two specific oper-
ations can be performed on a stack. These are the push and the pop operations.
Figure 2.4 illustrates these two operations.
As can be seen, a specific register, called the stack pointer (SP), is used to indicate
the stack location that can be addressed. In the stack push operation, the SP value is
used to indicate the location (called the top of the stack) in which the value (5A) is to
be stored (in this case it is location 1023). After storing (pushing) this value the SP is
Search WWH ::




Custom Search