[INTEL NAVIGATION HEADER]

Writing Leaf Procedures With ASM960 That Can Be Called From C960 Programs

When writing a leaf procedure in assembly language that can be called from a C program, the following format is recommended:

The first entry point into the leaf procedure myproc is through the label _myproc. The purpose for this entry point is to permit a reference to the leaf procedure via a call, callx or lda. Register g14 is set up to allow a return from a call or callx. Note that in the instruction "lda 0f, g14", the 0f is a forward numeric label and the action of this instruction is to load the address of the instruction at the label 0. Thus, when the leaf procedure has been called, the "bx (g7)" instruction's execution is followed by the return instruction's execution.

The second entry point through the __myproc label is made when accessing the leaf procedure with a bal or balx. In this case, g14 is set up with a BAL return address before entering the leaf procedure.

When compiling a C routine that calls a leaf procedure, the compiler will generate a callj or calljx to the procedure and the linker will change the callj or calljx to a branch and link instruction (bal or balx).

Please note that the .leafproc documentation in the ASM960 User's Guide (for all release 3.0 hosts) contains some errors and omissions. Specifically, the invocation syntax should read:

.leafproc name [, bal_entry]

Although the bal_entry is optional, we recommend that it be used. Otherwise, the "lda 0f, g14" instruction must be omitted from the template above, with the effect that the leaf procedure can then be accessed only by the BAL (or BALX) instruction, it can't be called with CALL or CALLX instructions (you won't be able to return). When the bal_entry is specified, the linker uses it as the entry point when replacing callj or calljx instructions, otherwise the linker uses `name'. If you always supply bal_entry and use the prologue and epilogue as described in this article, you may save yourself some runtime debugging at the expense of a slight increase in code size and symbol table size.



Legal Stuff © 1997 Intel Corporation

Free Web Hosting