Unit 6.1 -- Constant Subscripts, Range Starting at Zero, 1-D
arrays

PROG

Program just moves some numbers in an array around

PED

learn  how  to  use  one-dimensional  arrays  with  constant
subscripts and whose beginning subscript is 0.

CONCEPTS

For an array A defined as follows:

A:array[0..n] of integer;

A+i*4 is the memory location of A(i)
      where "i" is a constant


A  DC n+1F'0'           <-- allocates memory for the array A

SF


A+arithmetic expression

-designates a memory location so many bytes from the address
of A

ONLY works if have only constants in arithmetic expression


label DC nnF'0'

-creates "nn" four-byte entries
 each containing zero
-"label" refers to the first of the memory locations

SF

One  can  use  arithmetic on constants (or absolute  values)
when determining the offset from the label representing  the
array's memory location.

12.html
             Arrays and Array Processing Statements

Unit 6.1 -- Constant Subscripts, Range Starting at Zero, 1-D Arr
ay

Arrays  are  stored in the computer as a contiguous  set  of
memory  locations.  Thus an array dimensioned  "array[0..10]
of  integer" is stored as eleven fullwords.  Remember,  that
each  integer takes four bytes.  (Note also that 0..n  means
that there are n+1 objects in the array.)

Looking at our example, we see that A is declared with:
  A DC 11F'0;
This is the equivalent of our PASCAL:
  A: ARRAY[0..10]

This  creates a block of storage with 11 fullwords.  We also
see  from  the  listing that this block  of  storage  is  at
location 28 hex.  (20028 hex after the program is loaded.)

The locations of the elements are as follows.

28  A[0]
2C  A[1]
30  A[2]
34  A[3]
38  A[4]
3C  A[5]
40  A[6]
44  A[7]
48  A[8]
4C  A[9]
50  A[10]

At 54 is the next location, the constant one (F1).

Simple  inspection reveals that A+i*4 gives the  address  of
the  ith  element  for each of these locations.   (The  four
comes  from the fact that there are four bytes per integer.)
Note that A here stands for the address of the first byte of
A (28 hex) and not the contents of any element of A.

In assembler, one can write the form A+i*4 as long as "i" is
a  constant.   The  ASSEMBLER can  perform  arithmetic  with
ASSEMBLER-time  values  such as the address  of  things  (or
things  defined with EQU) and not with the values  that  may
eventually be in any box.

Lines 10 and 11 compute:
  A(1):=1
Register one is loaded with 1 and then assigned into  A+1*4.
The  1  comes from the subscript and 4 comes from  the  fact
that there are four bytes per integer.

Lines 13 and 14 compute:
  A(2):=2
Register one is loaded with 2 and then assigned into  A+2*4.
The two in A+2*4 comes from the subscript.

Lines 16 and 17 compute:
  A(3):=3
Register  one  is loaded with three and then  assigned  into
A+3*4.  The three in A+3*4 again comes frm the subscript.

You  can see which address that each of the stores is  using
by inspecting the ADDR2 column.  In line 11, the ADR2 column
is  2C which is location of A(1) as per the table above.  In
line  14, ADDR2 column contains 00030, the location of  A(2)
and  in line 17, ADDR2 contains 34 which is the location  of
A(3).

Last, we inspect the code to compute:
  A(4):=A(2)+A(3)
This  is  done in lines 19 to 21.  In line 19,  we  load  up
A(2).   Note  the  ADDR2 column contains  30  which  is  the
location of A(2).
In  line 20, A(3) is added.  Here, the ADDR2 column  is  34.
And lastly, this is stored into A(3).  ADDR2 is 38.
Unit  6.2  -- Constant Subscript, Non-zero Start  Value  for
Range, 1-D arrays

PROG

Again, program just moves some numbers around in an array

PED

learn  how  to  use  one-dimensional  arrays  with  constant
subscripts
However, beginning subscript is not necessarily zero

CONCEPTS

For an array A defined as follows

var A:array[m..n] of integer;

A+(i-m)*4 is the memory location of A(i)
     when "i" is a constant


A   DC n-m+1F'0'     <-- allocates memory for the array A

SF

none

13.html