Hardware Reference
In-Depth Information
calculation. This form requires an offset field in the instruction large enough to
hold an address, of course, so it is less efficient than doing it the other way; howev-
er, it is nevertheless frequently the best way.
5.4.7 Based-Indexed Addressing
Some machines have an addressing mode in which the memory address is
computed by adding up two registers plus an (optional) offset. Sometimes this
mode is called based-indexed addressing . One of the registers is the base and the
other is the index. Such a mode would have been useful here. Outside the loop we
could have put the address of A in R5 and the address of B in R6 . Then we could
have replaced the instruction at LOOP and its successor with
LOOP:
MOV R4,(R2+R5)
AND R4,(R2+R6)
If there were an addressing mode for indirecting through the sum of two registers
with no offset, that would be ideal. Alternatively, even an instruction with an 8-bit
offset would have been an improvement over the original code since we could set
both offsets to 0. If, however, the offsets are always 32 bits, then we have not
gained anything by using this mode. In practice, however, machines that have this
mode usually have a form with an 8-bit or 16-bit offset.
5.4.8 Stack Addressing
We have already noted that making machine instructions as short as possible is
highly desirable. The ultimate limit in reducing address lengths is having no ad-
dresses at all. As we saw in Chap. 4, zero-address instructions, such as IADD , are
possible in conjunction with a stack.
In this section we will look at stack ad-
dressing more closely.
Reverse Polish Notation
It is an ancient tradition in mathematics to put the operator between the oper-
ands, as in x
. The form with the op-
erator ''in'' between the operands is called infix notation. The form with the oper-
ator after the operands is called postfix or reverse Polish notation , after the Polish
logician J. Lukasiewicz (1958), who studied the properties of this notation.
Reverse Polish notation has a number of advantages over infix for expressing
algebraic formulas. First, any formula can be expressed without parentheses. Sec-
ond, it is convenient for evaluating formulas on computers with stacks. Third, infix
operators have precedence, which is arbitrary and undesirable. For example, we
+
y , rather than after the operands, as in xy
+
 
 
 
Search WWH ::




Custom Search