The absolute address of any variable is not generally known in an Autocode programme, but it may be obtained by means of a standard function. For example:-
s = addr(A(0,0))
This places the address of A(0,0) into the variable s. The argument may be any variable, real, integer, or complex and the result is an integer giving the absolute address of the storage location allocated to that variable.
Absolute addresses are used in conjunction with array functions (see below) and with the 'storage' functions
integer (integer n) real (integer n) complex (integer n)
These give the contents of the address in question as an integer, real, or complex number. In the last case the real and imaginary parts of the number are assumed to be in n and n+1. The actual parameter may of course be an integer expression e.g., s+k-1. These functions may be employed on the left hand side of an assignment statement as well as in an expression. Thus the pair of instructions
s = addr(a) real(s) = b
are equivalent to
a = b
The declarations of Section 2, define variables and allocate storage space for them. In this section we introduce a declaration which defines variables as the numbers contained in storage locations that have already been allocated. This is of importance in communicating between routines with the addr type of formal parameter and in renaming variables (see below).
An example is
array fn X(s,p)
which defines X(i) as the real number in the storage location whose address is given by s+i*p. Thus it defines a vector X(i) in terms of an origin s and a dimension parameter p.
Array functions may define rectangular arrays with any number of subscripts. For example:-
array fn Y(s,p,q)
defines Y(i,j) ≡ real (s+i*p+j*q)
integer or complex array functions may be defined by prefixing the declaration by integer or complex, (i.e. integer array fn X(s,p)) Array functions may also describe scalars. For example :-
array fn A(s)
defines A to be real (s). In this way, elements of a vector, say, can be given individual names.
The parameters in array functions may lie general integer expressions. As an example, assume that 100 storage locations have keen allocated in some way, and that the starting address is given by the integer variable s1. Then to define the contents of these locations as a vector x(i), one could write
array fn x(s1,1)
x(0) would then correspond to the number in address s1, x(1) to that in s1+1 etc. If it is desired that the first location should correspond to x(1), the declaration would be written
array fn x(s1-1,1)
If we had wanted to define a 10 x 10 matrix, stored row by row rather than a vector, we could have written
array fn A(s1,10,1)
and A(0,0) would correspond to address s1.
array fn A(s1-11,10,1)
would define a matrix in the available space whose first element was A(1,1).
1. If the suffices of arrays are to start from (1,1,---1) rather than (0,0,---0), an appropriate adjustment must be made to the expression giving the origin in the array function declaration.
2. Space redefined by array fn's may still be referred to by its original name.
We illustrate this with an example, suppose we wait to define and allocate storage for pairs of real variables x(i), y(i) so that they are in succesive locations. The array declaration will only define a vector or matrix array stored in the conventional manner, so we adopt the following device
begin integer s array a(1:2000) s = addr(a(1)) array fn x(s-2,2), y(s-1,2) ------ ------ ------
The first pair of numbers could then be referred to either as x(1), y(1) or a(1), a(2), the second by x(2), y(2) or a(3), a(4) etc.
Since the array declaration is for 2000 variables, up to 1000 pairs x(i), y(i) can be accommodated.
As another example, suppose we have defined a matrix A and allocated storage for it by the declaration
array A(1:10,1:10)
and we wish to define the first column of A as a vector, then we could write
array fn y(addr(A(1,1)) - 10,10)
which defines y(i) ≡ real (addr(A(1,1)) - 10 + 10*i) i.e. as the first column of A. Thus y(1) is equivalent to A(1,1), y(2) to A(2,1), - - - -,y(10) to A(10,1).
In the case of complex array functions the user must take into account that a complex number occupies 2 consecutive locations. Thus if s1 is the address of Q(1,1) of a complex array Q(1:10,1:10), then
complex array R(s1-20,20)
defines a vector R(i) whose elements are the first column of Q, i.e., R(1) ≡ Q(1,1)
Storage functions of arbitrary complexity can be obtained by means of store mapping routines. These are essentially function routines which compute an address. For example:-
real map X (integer i,j) result = s+½i*(i-1)+j-1 end
computes the address of the (i,j)th element of a real lower triangular matrix stored by rows starting with X(1,1) at locations. Here s is a non-local quantity, but would probably be local to the routine in which such a statement appeared. Such a function may also be employed on the l.h.s. of an assignment statement. For example:-
X(i-1,j+1) = [EXPR]
In the same way we can also define integer map and complex map routines.
If the map is placed at the end of a program a specification must be given before the routine can be referred to, for example
real map spec X(integer i,j)
We can now complete the list of formal parameter types
Formal parameter type | Corresponding actual parameter |
---|---|
addr | the name of any integer,real or complex variable (including an array element). The address of the variable is handed on as the parameter proper. It is equivalent to an integer parameter in the body of the routine. In fact an addr parameter replaced by x is equivalent to an integer parameter replaced by addr (x) |
real map | the actual parameter is the name of a mapping routine of the specified type |
integer map | |
complex map |