Program Construction

It is good practice to break down a large program into a number of modules

Each of these modules may then be separately coded, compiled and tested. Working modules (standard modules) may then be used and incorporated into other programs.

Advantages of using standard modules when programming..

  • the programmer knows they will work as they have already been tested.
  • it will save programming time as the programmer does not have to write these modules again.
  • workload can be distributed amongst a number of different programmers.
  • object code can be created using one language and used in a program created in a different language.

To create the final program, these compiled modules will need to be linked together without needing to re-compile them. 

When a program is run, a procedure which is to be executed may be loaded into memory by the operating system. It is important that the procedure's code can run properly wherever in memory it is placed. For this reason, code should be compiled using relative and not absolute addresses.

This is why it is better to use labels in assembly language programs. 

MOV fred,10 (put the number 10 in store location labelled 'fred')

...is better than...

MOV 32001,10 (put the number 10 in store location whose address is 32001)

..because the OS can relocate the store location whose label is 'fred' but cannot relocate the store location with address 32001.

Compilers need to create relocatable code - ie code that can be loaded and run anywhere in memory.

This is particularly important in a multi-programming environment where a program may be swapped in and out of memory at a number of different places.

The same principles apply to assembled code for low-level languages.