Mark Smotherman. Last updated July 2017.
The PDP-11 is a popular 16-bit minicomputer architecture introduced in 1970. It uses eight 16-bit registers with a dedicated stack pointer and PC mapped onto the last two registers. Addressing modes included autoincrement and autodecrement that are specifically designed for ease of implementing stacks.
sp (r6) - stack pointer
pc (r7) - program counter
jsr register,target - push register; register <- PC; PC <- target
rts register - PC <- register; pop register
If the specified register is r7 (the PC), then the PC is pushed and popped.
! in-line parameters with r5 as linkage register
...
jsr r5,subr1
.word parm1
.word parm2
...
! parameters passed on stack
...
mov parm1,-(sp)
mov parm2,-(sp)
jsr pc,subr2
add #4,sp ! adjust stack to remove parameters
...
! subroutine called with in-line parameters
subr1:
mov r1,-(sp) ! save r1 contents on stack
mov r2,-(sp) ! save r2 contents on stack
mov (r5)+,r1 ! copy parameter 1 into r1
mov (r5)+,r2 ! copy parameter 2 into r2
... body of subroutine ...
mov (sp)+,r2 ! restore r2 contents from stack
mov (sp)+,r1 ! restore r1 contents from stack
rts r5 ! return to instruction following parms
! subroutine called with parameters on stack
subr2:
mov r1,-(sp) ! save r1 contents on stack
mov r2,-(sp) ! save r2 contents on stack
mov 8(sp),r1 ! copy parameter 1 into r1
mov 6(sp),r2 ! copy parameter 2 into r2
... body of subroutine ...
mov (sp)+,r2 ! restore r2 contents from stack
mov (sp)+,r1 ! restore r1 contents from stack
rts pc ! return to instruction following jsr
[History of subroutines page] [Mark's homepage] [CPSC homepage] [Clemson Univ. homepage]
mark@cs.clemson.edu