Defining Global Register Variables

6.44.1 Defining Global Register Variables

You can define a global register variable in GNU C like this:

register int *foo asm ("a5");

Here a5 is the name of the register that should be used. Choose a register that is normally saved and restored by function calls on your machine, so that library routines will not clobber it.

Naturally the register name is cpu-dependent, so you need to conditionalize your program according to cpu type. The register a5 is a good choice on a 68000 for a variable of pointer type. On machines with register windows, be sure to choose a “global” register that is not affected magically by the function call mechanism.

In addition, different operating systems on the same CPU may differ in how they name the registers; then you need additional conditionals. For example, some 68000 operating systems call this registe