HPlogo HP Assembler Reference Manual: HP 9000 Computers > Chapter 7 Programming Examples

4. Demonstrating the Procedure Calling Convention

» 

Technical documentation

Complete book in PDF

 » Table of Contents

 » Index

A C program calls an assembly language program to test if .ENTER and .LEAVE are working correctly. The assembly language program checks to see if the C program has passed the value zero in arg0. The assembly language program then returns the value -9 in ret0 to the calling program.

You need to compile this assembly listing using cc. The registers ret0 and arg0 are declared within /usr/lib/pcc_prefix.s, which is automatically included when you give the C compiler an assembly file.

To remove the dependency on pcc_prefix.s, replace all occurrences of ret0 with %r28 and arg0 with %r26.

C Program Listing

#include <stdio.h>
int errorcount = 0;
main ()
{
int toterr = 0;
printf("TESTING FEATURE 000");
fflush(stdout);
if( feat000(000) != -9 ) ++errorcount;
printf(" %d errors\\n",errorcount);
toterr += errorcount;
errorcount = 0;
}

Assembly Program Listing

; Assembler Module that passes results back to C driver module
myfeat .EQU 000
success .EQU -9

.CODE
.IMPORT errorcount,DATA
.SUBSPA $CODE$
.EXPORT feat000,ENTRY

.PROC
.CALLINFO
feat000 .ENTER
LDI 0,ret0
COMIB,<> myfeat,arg0,exit
NOP
LDI success,ret0
exit .LEAVE
.PROCEND
.END
© 1998 Hewlett-Packard Development Company, L.P.