The PDP-11 MARK instruction was intended to be used as part of the standard PDP-11 subroutine return convention. MARK
facilitated the stack clean up procedures involved in subroutine exit.
To use it, the caller would put the MARK
instruction on the stack:
MOV R5,-(SP) ;place old R5 on stack
MOV P1,-(SP) ;place N parameters
MOV P2,-(SP) ;on the stack to be
;used there by the
;subroutine
MOV PN,-(SP)
MOV #MARKN,-(SP) ;places the instruction
;MARK N on the stack
MOV SP,R5 ;set up address at MARK N instruction
JSR PC,SUB ;jump to subroutine
At this point the stack is as follows:
OLD R5
P1
...
PN
MARK N
OLD PC
The subroutine would execute normally and return using the RTS R5
instruction. This causes the contents of R5
to be placed in the PC
which then results in the execution of the instruction MARK N
. The contents of the old PC
are placed in R5
.
MARK N
causes: (1) the stack pointer to be adjusted to point to the old R5
value; (2) the value now in R5
(the old PC
) to be placed on the PC
; and (3) contents of the old R5
to be popped into R5
thus completing the return from subroutine.
The MARK
instruction seems unique in several aspects:
- It appears to be the only PDP-11 instruction which used the register R5 implicitly. Thus, similarly to the PC (R7) and SP(R6), R5 should have had a mnemonic name. Had it?
- It can only be used meaningfully when put on the stack (Now we know that an executable stack is a bad idea, but that was then).
From my recollection, the PDP-11 C/UNIX calling conventions did not use the MARK
instruction; calling special subroutines CSAV/CRET instead.
In what PDP-11 OS or programming environment was it actually used?
Were there other instruction set architectures with instructions designed specifically for use on the stack? Is it known who came up with the idea?