Hardware Reference
In-Depth Information
MOV R1,#0
; accumulate the OR in R1, initially 0
MOV R2,#0
; R2 = index, i, of current product: A[i] AND B[i]
MOV R3,#4096
; R3 = first index value not to use
LOOP: MOV R4,A(R2)
; R4 = A[i]
AND R4,B(R2)
; R4 = A[i] AND B[i]
OR R1,R4
; OR all the Boolean products into R1
ADD R2,#4
;i=i+4(step in units of 1 word=4bytes)
CMP R2,R3
; are we done yet?
BLT LOOP
; if R2 < R3, we are not done, so continue
Figure 5-18. A generic assembly program for computing the OR of A i AND B i
for two 1024-element arrays.
Operation of this program is straightforward. We need four registers here:
1. R1 — Holds the accumulated OR of the Boolean product terms.
2. R2 — The index, i , that is used to step through the arrays.
3. R3 — The constant 4096, which is the lowest value of i not to use.
4. R4 — A scratch register for holding each product as it is formed.
After initializing the registers, we enter the six-instruction loop. The instruction at
LOOP fetches A i into R4 . The calculation of the source here uses indexed mode.
A register, R2 , and a constant, the address of A , are added together and used to ref-
erence memory. The sum of these two quantities goes to the memory but is not
stored in any user-visible register. The notation
MOV R4,A(R2)
means that the destination uses register mode with R4 as the register and the source
uses indexed mode, with A as the offset and R2 as the register. If A has the value,
say, 124300, the actual machine instruction for this is likely to look something like
the one shown in Fig. 5-19.
MOV
R4
R2
124300
Figure 5-19. A possible representation of MOV R4,A(R2) .
The first time through the loop, R2 is 0 (due to it being initialized that way), so
the memory word addressed is A 0 , at address 124300. This word is loaded into R4 .
The next time though the loop, R2 is 4, so the memory word addressed is A 1 ,at
124304, and so on.
As we promised earlier, here the offset in the instruction itself is the memory
pointer and the value in the register is a small integer that is incremented during the
Search WWH ::




Custom Search