Using the toc

The TOC is created with certain conventions.

To use the TOC, you must follow certain conventions:

  • General-Purpose Register 2 always contains a pointer to the TOC.
  • All references from the .text section of an assembler program to .data or the .bss sections must occur via the TOC.

The TOC register (General-Purpose Register 2) is set up by the system when a program is invoked. It must be maintained by any code written. The TOC register provides module context so that any routines in the module can access data items.

The second of these conventions allows the .text and .data sections to be easily loaded into different locations in memory. By following this convention, you can assure that the only parts of the module to need relocating are the TOC entries.