Unit 6.10 -- 2-D array, row-by-row, upper-left-hand-corner used
SILVER, See section 5.3 specifically
PROG
See the following program's comment lines.
PED
To learn how to process two-dimensional arrays
The entire range is not used
Concepts
B :array[k..m,x..n]
for i=k to p
for j=x to q
process B(i,j)
gets converted to
LA regA,B
FOR LOOP 1 stuff
LR regB,regA
FOR LOOP 2 stuff
process the stuff at memory location 0(0,regB)
add 4 to regB
END OF FOR LOOP 2 stuff
A regA,=A((n-x+1)*4)
END OF FOR LOOP 1 stuff
SF
We can use =A(expr) as a memory location (constant) when we
need to compute some arithmetical expression involving
constants
addresses
21.html
Unit 6.10 -- Two-Dimensional Array, Example 4
In this unit, we discuss the case where not all the
two-dimensional array allocated is used. You will note that
the array, B, is dimensioned k..m,x..n. However the first
do loop goes from k to p and the second goes from x to q.
Presumably p<=m and q<=n.
We maintain two pointers. The first of these is kept in
regA. We call this, the big arrow. It starts off at the
beginning of the first row. Each time through the outer do
loop, it goes down to the beginning of the next row.
The second one is kept in regB. This is the small arrow.
At the beginning of the inner loop, it starts off at the
beginning of the row. Then, each time through the inner
loop, it goes to the next entry in the row.
The LA regA,B initializes the big arrow at the start of the
array, and, hence, the start of the first row. Just before
the end of the outer loop, we add the number of elements in
a row (multiplied by four). This makes the big arrow point
to the first element of the next row down.
To start the little arrow at the beginning the new row, we
do a "LR regB,regA" Then each time through the inner loop,
we increment the little arrow (regB) by four to make it
point to the next entry in the row.
In our example, we have an array that goes from 1 to 10 and
1 to 10. Other than that, the PASCAL code is identical to
that from the previous example. In other words, we want to
set each element of a 3 by 3 square to i+j. However, that
square is defined to be the upper left hand corner of a 10
by 10 array, most of which is empty space.
Register 3 serves as our big arrow, or regA in the template.
We see initialized to the beginning of the array in 16.
Lines 19 through 22 act as the "FOR LOOP1 STUFF" Line 24 is
part of the "FOR LOOP2 STUFF" Note in line 23, the "LR 5,3"
This sets regB equal to regA. Register 3 is "regA" in this
example.
Lines 24 to 27 act as the "FOR LOOP2 STUFF." Then lines 28
through 30 process the stuff at that location, by filling it
with I+J. Then we increment the little arrow (regB) in line
31. Lines 32 to 34 are the "END OF FOR LOOP2 STUFF."
Line 35 increments the big arrow by the size of a row. Note
that we multiply 10*4. 10 is n-x+1 where n is 10 and x is
1. 10 is also the number of integers in a row, which we
multiply by four to get the number of bytes per row.
We add 1 to register one in line 36. This is part of the
"END OF FOR LOOP 1 STUFF."
Lines 37 to 38 finish up the "END OF FOR LOOP 2" stuff.