13

Some subroutine calls on PDP-11 machines would be coded with the arguments appearing immediately after JSR or EMT instruction, something like this (apologies for not knowing the exact MACRO syntax):

    jsr r5,WRITE_STRING
    .byte 'This is some string'.'0'
continue:
    ; do stuff
    rts pc

WRITE_STRING:
    movb (r5)+,r0
    beq  done
    .PRINT r0
    br   WRITE_STRING
done:
    inc r5
    bic #1,r5
    jmp (r5)

The jsr instruction sets r5 to point to the beginning of an ASCIZ string that is located in-line in the code, right after the jsr. The WRITE_STRING subroutine then reads the bytes pointed to by r5 and prints them out until the terminating zero is found. r5 is then aligned property, and control is returned to the caller with jmp (r5).

There were variants of this calling conventions; for instance the arguments could be indirect, in which case pointers to the actual arguments would be inlined in code, rather than the arguments themselves.

Was there a name for this in-line argument technique?

3
  • For common cases where code size would be more important than execution speed, including most uses variadic arguments, it would seem like code size could often have been reduced by having a generic "call function" function that would process encoded information stored immediately after the call itself which would describe the function and its arguments, reducing the size of code needed to supply them to the caller.
    – supercat
    Mar 7, 2019 at 17:22
  • Note that on systems using split I/D address spaces, this calling convention may not work as expected, because the argument fetches will come from the Data space rather than from the Instruction space.
    – Ken Gober
    Mar 7, 2019 at 23:25
  • It was certainly not a technique that showed up in RSX-11M kernel code, which generally favoured arguments in registers, with a strong emphasis on the argument being naturally in the right register anyway (e.g., everyone expected a UCB address in R5). Mar 10, 2019 at 12:53

3 Answers 3

9

The older PDP-8 did similar.  It had only one register to speak of (the accumulator), so a subroutine that took several parameters would typically provide a set of values and/or pointers to values immediately after the call instruction (JMS).  The called routine would increment the return address to access parameters, and finally to return to the caller just after the parameter block.

This text describes the parameter passing as "in-line": https://people.cs.clemson.edu/~mark/subroutines/pdp8.html.

The PDP-8 handbook "Introduction to Programming", January 1969, page 3-19, item #6 describes it simply with the following:

The second number to be multiplied is brought into the subroutine by the TAD I MULT instruction since it is stored in the location specified by the address that the JMS instruction automatically stores in the first location of the subroutine [i.e. the return address]This is a common technique for transferring information to a subroutine.

The first instruction of a subroutine was where the return address is stored by the JMS instruction.  Thus, this word was used to pick up parameters as well as to return to the function's caller.  The PDP-8 had fixed size instructions and data words of 12-bits (word addressing only); it also supported a memory indirect addressing mode, and a memory increment operation, so this approach worked fairly well.

1
  • For languages where parameters are passed by reference, and variables are statically assigned (=have fixed virtual addresses), that approach may be considered "natural". Code the "call" instruction followed by the addresses of the actual-parameters; easy. This probably suits early Fortran on the -11, but as noted, split I/D breaks that. To answer the question though: I knew of no name except "inline arguments". Mar 8, 2019 at 0:32
5

I do not know any specific name here. It was usually called a 'Parameter List'.

It may be due to the fact that this way was more or less the standard handling on many early systems supporting subroutine calls - way before any PDP-11, or PDP at all was designed. The need of special names usually only arises when additional methods come into use.

Its inherent benefit is that no additional parameter register is needed, as the return address is stored in the link register, which can then double as a parameter list pointer, only to be advanced while processing, and at the end holding the return address (after the parameter list) (*1). For mainframe systems it was the standard calling convention.

Using the stack for return address handling is a rather new development - compared with parameter passing - but even then it was used quite a lot. Just think the way OS calls (*2) are made in Apple ProDOS.


*1 - In fact, it wouldn't at all be weird to think of it as a stack pointer to access (and pop) the parameters - and when all parameters are removed it holds the return address.

*2 - MLI or Machine Language Interface in ProDOS lingo. Here the JSR to $BF00, the ProDOS entry point, is followed by a byte defining the function call and a word holding the address of a parameter block for this function.

3

In the DEC book FPMP-11 USER'S MANUAL DEC-11-NFPMA-C-D from 1972 they describe J5RR Mode.

from page 3-10

3.3.2 J5RR Mode

J5RR Mode is the calling convention used by most of the FORTRAN library functions. J5RR mode calls are of the form

JSR   R5,subroutine  

All argument addresses are placed in a list following the subprogram call. The generalized standard sequence is:

   .GLOBL SUBR  
   JSR  R5,SUBR  
   BR   XX  
   A  
   B  
   .  
   .  
   .  
   Z  
XX:  

Where A, B...Z are argument addresses.

This is distinct from the form called polish mode where data are pushed on the stack and the call is followed by addresses of routines.

MOV   C+2,-(SP)  
MOV   C,-(SP)  
MOV   B+2,-(SP)  
MOV   B,-(SP)  
MOV   A+2,-(SP)  
MOV   A,-(SP)  
JSR   R4,$POLSH  
.WORD  $ADR   ;ADD A TO B  
.WORD  $MLR   ;MULTIPLY SUM BY C  
.WORD  .+2    ;LEAVE POLISH MODE  

If the number of parameter words might be variable in the J5RR mode the branch low byte is the count of parameter words actually present.

So JSR R5 followed by addresses of data is J5RR and JSR R4 followed by addresses of code routines is polish. I have seem polish used other places but this is the only place I recall seeing J5RR.

Null terminated ASCII strings are different.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .