.title call Call (Fortran) subroutine from C .ident /000002/ ; ; ;+ ; ; Index Call (Fortran) subroutine from C ; ; Usage ; ; return_value = call(routine, count, &arg1, ... &argN); ; extern int routine(); /* PDP-11 function name */ ; int count; /* Number of arguments */ ; ; Description ; ; C Library user-callable interface between C programs and ; subroutines which follow the standard PDP11 calling sequence. ; Note that call() saves and restores registers r2-r5. ; ; The arguments are as follows: ; ; routine The name of the PDP11 routine to ; be called. ; ; count The number of arguments in the ; calling sequence. ; ; arg1 The first argument. ; ; For example: ; ; extern int sort(); ; int data_to_sort[NDATA]; ; int ndata = NDATA; ; ; call(sort, 2, &data_to_sort, &ndata); ; ; Note that, if the called function returns some other datatype ; such as a long, the routine and call() must be correctly declared: ; ; long call(); ; long myfun(); ; long larg; ; long result; ; ; result = call(myfun, 1, &larg); ; ; If call() is being used to return several different datatypes, ; type coersion may be effective: ; ; int call(); ; long myfun(); ; long larg; ; long result; ; ; result = (long)call(myfun, 1, &larg); ; ; Bugs: ; ; WARNING: watch out for trouble if the PDP-11 routine does ; any I/O. Floating-point data return has not been implemented. ; ;- ; Edit history ; ; 01 MM Original ; 02 MM Save registers 2-5 first. ; .psect c$code CALL:: MOV R5,-(SP) ; Remember environment MOV SP,R5 ; r5 -> stack CMP (R5)+,(R5)+ ; R5 -> Routine address MOV R4,-(SP) ; Save ;02 + MOV R3,-(SP) ; registers MOV R2,-(SP) ; r2 - r4 ;02 - JSR PC,@(R5)+ ; Call routine with arglist MOV (SP)+,R2 ; Restore ;02 + MOV (SP)+,R3 ; registers MOV (SP)+,R4 ; r2 - r4 ;02 - MOV (SP)+,R5 ; Restore environment RTS PC ; And exit .END