Contact us Heritage collections Image license terms
HOME ACL Associates Technology Literature Applications Society Software revisited
Further reading □ PrefaceContents1 Introduction2 The basic language3 Storage and block structure of programs4 Routines5 Data I/O6 Monitor printing and fault diagnosis7 Presentation of complete programs8 Complex arithmetic9 Store Mapping10 The use of machine instructions11 Permanent routines □ Appendices and indices □ A1 Phrase structure notationA2 Standard functions and permanent routinesA3 DelimitersA4 Monitored faultsA5 Numerical equivalents of symbols
ACD C&A INF CCD CISD Archives Contact us Heritage archives Image license terms

Search

   
ACLLiteratureAtlas manualsAtlas Autocode :: ATLAS AUTOCODE REFERENCE MANUAL
ACLLiteratureAtlas manualsAtlas Autocode :: ATLAS AUTOCODE REFERENCE MANUAL
ACL ACD C&A INF CCD CISD Archives
Further reading

Preface
Contents
1 Introduction
2 The basic language
3 Storage and block structure of programs
4 Routines
5 Data I/O
6 Monitor printing and fault diagnosis
7 Presentation of complete programs
8 Complex arithmetic
9 Store Mapping
10 The use of machine instructions
11 Permanent routines
Appendices and indices
A1 Phrase structure notation
A2 Standard functions and permanent routines
A3 Delimiters
A4 Monitored faults
A5 Numerical equivalents of symbols

3 Storage Allocation and Block Structure of Programs

3.1 The Stack

In order to illustrate the principles of storage allocation, we assume the following simplified picture of the data store (the stack), a fuller description being given in the section on the use of machine instructions.

Cells in Use Available Cells St

Each cell or location represents a 48 bit word in the computer store and can be used to hold either a real or an integer variable. At any time during the running of a program, the stack pointer, St, points to the next available location i.e. it contains the address of the next free word. In the examples that follow, shaded areas represent locations which hold information essential to the program, such as array dimensions and origins, and are not of importance in the context of this section. Each area may in fact consist of several locations. Cells which are allocated to variables are indicated by the presence of the name given to the variable.

3.2 Storage Allocation Declarations

The declarations which allocate storage space are

 
real integer array integer array
         

and to illustrate the stack mechanism we consider the following example:

 
begin 
real   a, b, c; integer i, max
array A(1:2,1:2), x(1:3)

After the above declarations the stack picture would be as below

St1 a b c i max A(1,1) A(1,2) A(2,1) A(2,2) x(1) x(2) x(3) St2

St1 is the position of St before begin and St2 its position after the declarations. Any further declaration advances St by an appropriate amount, likewise any activity initiated by the instructions in the body of the block causes St to be advanced(either explicity or implicity) still further. Finally when end or end of program is reached, then St reverts to St1.

Variables declared by real and integer are called fixed variables, because the amount of storage space required can be determined at compiler time. Array declarations, however, may have general integer expressions as the parameters and hence have dynamic significance. For example one might have a declaration such as

 
array A,B(1:m, 1:n),x(1:n)

In this case the space allocated will depend on the computed values of m and n and cannot be determined at compiler time. The stack pointer St is thus advanced in several stages following the initial step which reserves space for all the fixed variables.

3.3 Block Structure of Programs

This is illustrated by the following example:-

 
begin 
real a,b,c
a = 1; b = 2
c = a+b
  begin 
  real a,b,d
  a = 2; d = 1
  b = c
  c = 4
  end
a = a+b+c
end
         

The stack picture associated with the above block is given below:

St1 a 1 b 2 c 3 a 4 b 5 d 6 St2 St3

Before the first begin St is at St1, and moves to St2 on entering the outer block. After the second begin St is at St3 and reverts to St2 when end is reached. At the second end, corresponding to the first begin, St assumes its original position, St1.

In the diagram, positions 1, 2, 3 correspond to the declarations of the outer block, and 4, 5, 6 to those of the inner block. After the instruction c = a+b, the value 3 is left in position 3; while the instructions of the inner block leave the values 2, 1, 3, 4 in the positions 4, 6, 5, 3 respectively. The last instruction of the outer block leaves the value 7 in position 1.

Thus the variables a, b of the inner block do not conflict with a, b of the outer block, while a reference to c in the inner block is taken to refer to the variable of that name declared in the outer block. We say that a,b are local names to the inner block and c is a non-local name. We also note that the information stored in the variables of the inner block is lost when the block is left, and that we could not refer in the outer block to a variable declared in the inner block.

Futher details of the structure of programs will be given in the section on routines, and for the present the following notes on blocks will be sufficient.

  1. Blocks may contain any number of sub-blocks and blocks may be nested to any depth.
  2. Names declared in a block take on their declared meaning in the block and in any sub-blocks unless redeclared in the sub-block.
  3. Labels are local to a block and transfers of control are only possible between statements of the same block.
  4. The outermost block of a program is terminated by end of program, which causes the process of compiling to be terminated and transfers control to the first instruction of the program.

A simple and common use of block structure arises when reading arrays from tape, each array being preceded by its dimensions. For example:-

 
   begin 
   integer m,n
1: read(m,n)
     begin 
     array A(1:m,1:n)
     ---
     ---
     end
   ->1
   end
         

If the begin and end defining the sub-block were not included, then the stack pointer would be advanced further each time a new array was read, without ever being reset, and this could be very wasteful of storage space, particularly for very large values of m and n.

⇑ Top of page
© Chilton Computing and UKRI Science and Technology Facilities Council webmaster@chilton-computing.org.uk
Our thanks to UKRI Science and Technology Facilities Council for hosting this site