Chapter Contents |
Previous |
Next |
Communication with Assembler Programs |
The C Run-Time Anchor Block |
Some of the fields in the CRAB can be conveniently used in an assembler routine. Note especially the fields in Useful CRAB Fields.
Label |
---|
CRABZERO |
CRABDBL1 |
CRAB2P31 |
CRABUNMO |
CRABDWK |
CRABINTI |
CRABNEGI |
CRABEOST |
CRAB16M |
CRABTAUT |
CRABUSR1 |
CRABUSR2 |
CRABUSR3 |
CRABTUSR |
The uses of the CRAB constant fields such as CRABINT1
are obvious. An explanation of the use of the
double
to
int
(and
int
to
double
) conversion fields
is beyond the scope of this discussion, but an examination of the generated
code for such conversions (via an OMD listing) shows how the conversions are
performed. Similarly, the generated code for a built-in
strlen
function call shows the use of the translation table addressed by CRABEOST.
The work area at label CRABTAUT is used by the compiler for functions with
small automatic storage requirements and can be used by any C function.
Keep in mind the following concerning the CRAB:
The CENTRY and CEXIT Assembler Macros |
In a program that runs with the
=optimize
or
=minimal
run-time linkage option, assembler routines
must use the CENTRY and CEXIT macros if they call C functions.
When you use CENTRY and CEXIT, you must supply a CSECT
statement before the first entry point; conventionally, the CSECT name should
be the name of the first entry point, followed by the
@
operator. (You can use some other name without adverse consequences if the
name is not the same as another external name in the load module.) Programs
that use CENTRY and CEXIT should also issue the CREGS macro to define symbolic
registers and should copy the members CRAB and DSA to obtain mappings of these
C run-time control blocks. Assembler functions that use CENTRY and CEXIT should
ensure that general register 12 addresses the CRAB when entering and exiting
the function (unless the CENTRY INDEP=YES parameter is used).
This is the form of a call to the CENTRY macro:
label CENTRY DSA=dsa-size, BASE=base-reg, FNM=function-name, STATIC=NO/YES, INDEP=NO/YES, LASTREG=last-reg
auto
variables. Specify DSA=0 to avoid
allocation of a DSA. DSA=0 can be used only for routines that
indep
form of function linkage is required. INDEP=NO is the default. INDEP=YES
is required if the assembler routine can be called from a routine that does
not preserve the C execution framework pointer normally contained in register
12. The INDEP=YES linkage is less efficient than the INDEP=NO linkage and
requires that L$UPREP be linked with the routine that uses the CENTRY macro.
Refer to Using the indep Option for Interlanguage Communication for more information.
label CEXIT RC=return-info/(reg), DSA=YES/0, INDEP=NO/YES, LASTREG=last-reg
The keyword parameters are described below:
Alternately, RC=(reg) specifies
a register containing the return value. If RC is omitted, no value is returned
unless the assembler routine is declared as returning
double
.
In this case, do not use the RC keyword; instead load the return value into
floating-point register 0 before issuing the call to CEXIT.
The CREGS Macro and the CRAB and DSA DSECTs |
The CRAB DSECT should be copied because it is required for the proper expansion of CENTRY and CEXIT.
The DSA DSECT can be copied to obtain a map of the standard
part of the DSA. After the standard part of the DSA, you can define additional
DSA fields and then use the EQU operator to compute a total DSA size for use
in CENTRY. The additional fields can be used as automatic variables. For
an example of defining
auto
variables in an assembler function,
see Defining Auto Variables in the DSA.
Defining Auto Variables in the DSA
function body COPY DSA TEMPVAR DS F auto int variable SHORTX DS H auto short variable STR1 DS CL40 auto array of char DSALEN EQU *-DSA compute total length of DSA END
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.