Hardware Reference
In-Depth Information
notation to make it easy to read because the Core i7's standard assembly-language
syntax (MASM) verges on the bizarre, a remnant of the machine's former life as an
8088.
It is worth noting that, in theory, there is another way to do this computation
without using register indirect addressing. The loop could have contained an in-
struction to add A to R1 , such as
ADD R1,A
Then on each iteration of the loop, the instruction itself could be incremented by 4,
so that after one iteration it read
ADD R1,A+4
and so on until it was done.
A program that modifies itself like this is called a self-modifying program.
The idea was thought of by none other than John von Neumann and made sense on
early computers, which did not have register indirect addressing. Nowadays,
self-modifying programs are considered horrible style and hard to understand.
They also cannot be shared among multiple processes at the same time. Fur-
thermore, they will not even work correctly on machines with a split level 1 cache
if the I-cache has no circuitry for doing writebacks (because the designers assumed
that programs do not modify themselves). Lastly, self-modifying programs will
also fail on machines with separate instruction and data spaces. All in all, this is an
idea that has come and (fortunately) gone.
5.4.6 Indexed Addressing
It is frequently useful to be able to reference memory words at a known offset
from a register. We saw some examples with IJVM where local variables are refer-
enced by giving their offset from LV . Addressing memory by giving a register (ex-
plicit or implicit) plus a constant offset is called indexed addressing .
Local variable access in IJVM uses a pointer into memory ( LV ) in a register
plus a small offset in the instruction itself, as shown in Fig. 4-19(a). However, it is
also possible to do it the other way: the memory pointer in the instruction and the
small offset in the register. To see how that works, consider the following calcula-
tion. We have two one-dimensional arrays of 1024 words each, A and B , and we
wish to compute A i AND B i for all the pairs and then OR these 1024 Boolean
products together to see if there is at least one nonzero pair in the set. One ap-
proach would be to put the address of A in one register, the address of B in a sec-
ond register, and then step through them together in lockstep, analogous to what
we did in Fig. 5-17. This way of doing it would certainly work, but it can be done
in a better, more general way, as illustrated in Fig. 5-18.
 
 
Search WWH ::




Custom Search