Runtime
Environment
-
Register
Conventions
5.2
Register
Conventions
Strict conventions associate specific registers
with
specific operations in the
C environment.
If
you plan to interface assembly language routines to a C
program, it
is
important that you understand these register conventions.
5.2.1
Dedicated
Registers
The C environment
reserves
three registers.
Do
not
modify these registers in
any other manner than that described
in
Section 5.3, Function Structure and
Calling Conventions, page 5-8.
SP
A14
(STK)
A13
(FP)
points
to
the top
of
the system stack.
points
to
the program stack.
points
to
the beginning
of
the currently active frame.
In
addition, the C compiler assumes certain information about bits in the status
register. Specifically,
it
assumes that
FS1
(field size
1)
is
32
within
a C func-
tion.
FSO,
however, can
be
changed
in
a function
without
being restored.
5.2.2
Using
Registers
5-6
A function
can
usually
use
registers
AO
through A 12, however:
• When a function
is
called, it must
save
the contents
of
each register that
it
uses;
it must restore these registers before it returns
to
the caller.
Re-
gister A8
is
the only exception; its contents do
not
have to
be
saved or
restored.
•
If
a function returns
an
integer value or a pointer, the value must
be
placed in A8.
The code generator
uses
the
A-file
registers for the
following
purposes:
Expression analysis
Return value/Scratch
User register variables
AO
through
A11
A8
A9,A10,A11,A12,AO,A2,A4,A6
The C compiler doesn't
use
registers
80
through 814.
Expression-analysis registers
are
allocated from high
to
low
registers, based
on availability and current
use.
(All integer expression analysis
uses
32-bit
. math.)
Note:
The compiler constantly tracks the contents
of
registers and attempts
to
reuse register data whenever possible. Therefore,
it
is
inadvisable
to
use
inline assembly language or any other method to modify a register that a
function
is
using.
Use
the
-r
code generator option to produce informa-
tion about register
use.