UNIT 6.2

 Constant Subscript, Non-zero Start Value for Range, 1-D Array

In this example, we learn how to deal with arrays that begin
at some value other than zero.  Note that we are still using
CONSTANT subscripts.  Next unit, we will learn how  to  deal
with  cases  where the subscript is a variable or expression
such as "I" or "I+J".

Given an array declared:
  A:array[m..n] of integer
that means that the first fullword contains A[m], the second
fullword   contains  A[m+1],  the  third  fullword  contains
A[m+2],  the  second  to last fullword contains  A[n-1]  and
finally, the last fullword contains A[n].

One  can  write  for the ith element of  A,  where  i  is  a
constant, A+(i-m)*4.  Again, i (and m) must be constant.   I
represents the subscript and m represents the initial  value
for the range of subscripts permitted for the array A.

There  are  n-m+1  objects in an array declared  [m..n]  and
hence we write:
A    DC   xxF'0'
   or
A    DS   xxF
where xx is the result of computing the constant expresion n-
m+1.

In our example, we have an array A dimensioned from 4..10.

The item is defined with
A   DC  7F'0'
where 7 represents 10-4+1.

In  our example, A is at location 38 hex in the program.  We
see that the locations of the elements are:

38  A[4]
3C  A[5]
40  A[6]
44  A[7]
48  A[8]
4C  A[9]
50  A[10]


Lines 9 and 10 represent A(5) := 1.
Note  that A+(5-4)*4 represents the location of A(5).  ADDR2
is 3C, the address of A[5].

Lines 12 and 13 represent A(6) := 2.
Note  that A+(6-4)*4 represents the location of A(6).  ADDR2
is 40 on line 13, the address of A[6].

Lines 15 and 16 represent A(7):=3.
Note  that A+(7-4)*4 represents the location of A(7).  ADDR2
is 44 on line 16, the address of A[7].

Last but not least, we compute
  A(4):=A(5)+A(6)+A(7)
On  line 18, we load A(5) into register one.  Note ADDR2  is
3C.
On line 19, we add A(6) to register one.  Note ADDR2 is 40.
One line 20, we add A(7) to register one.  Note ADDR2 is 44.

We  store  it at A(4) in line 21.  We could write for  A(4),
A+(4-4)*4.  But that is equivalent to simply A.  So we write
A in the
  ST 1,A
Note that ADDR2 is 38.
Unit 6.3 -- 1-D array, non-constant subscript

PROG

Move some stuff around in a one-dimensional array

PED

To  learn how to do stuff with a one-dimensional array (non-
constant subscript)

CONCEPTS

To store something into array-name (var)

               LA    regA,array-name     regA has the address of array-name
               L     regB,var
               AR    regB,regB
               AR    regB,regB regB      now  has the   offset   of   array-name
                                         (var)  from  the beginning  of
                                         array-name (in bytes)
               AR    regA,regB regA      has the address of array-name (var)
               L     regC,something      regC has what we want to store
               ST    regC,0(0,regA)      now "something" is stored in array-name (var)

Note: the  two  "L"  instructions can be replaced  with
      other  code  to  get  the  appropriate  value  in   the
      registers

To retrieve something from array-name (var)


          LA      regA,array-name    regA has the address of array-name
          L       regB,var
          AR      regB,regB
          AR      regB,regB          regB now has the offset of array-name
                                     (var) from the beginning  of array-name
                                     (in bytes)
          AR      regA,regB          regA has the address of array-name (var)
          L       regC,0(0,regA)     now regC contains the value of array-
                                     name (var)
          A, S, C, etc. could also be used in the last step

SF

LA   regA,memory location

-puts the address of "memory location" into "regA"


(contrast

L  regA,memory location

which  puts what was in the address of the "memory location"
into   "regA")



offset(regA,regB)

-can be used anywhere a memory location can go:

               "memory location":=
"offset" + contents of "regA" + contents of "regB"

-labels  are  converted  to this format  internally  by  the
assembler

-"offset" is an integer less than 4096

register 0 will be ignored if used for regA or regB


14.html