character JMP .-1 / Else jump back and try again JMP HELLO / Jump back for the next character STRNG, 310 / H 345 / e 354 / l 354 / l 357 / o 254 /, 240 / (space) 367 / w 357 / o 362 / r 354 / l 344 / d 241 / ! 0 / End of string $HELLO /DEFAULT TERMINATOR Subroutines The PDP-8 processor does not implement a stack upon which to store registers or other context when a subroutine is called or an interrupt occurs. (A stack can be implemented in software, as demonstrated in the next section.) Instead, the JMS instruction simply stores the updated PC (pointing past JMS, to the return address) at the effective address and jumps to the effective address plus one. The subroutine returned to its caller using an indirect JMP instruction that addresses the subroutine's first word. For example, here is "Hello, World!" re-written to use a subroutine. When the JMS instruction jumps to the subroutine, it modifies the 0 coded at location OUT1: *10 / Set current assembly origin to address 10, STPTR, STRNG-1 / An auto-increment register (one of eight at 10-17) *200 / Set assembly origin (load address) LOOP, TAD I STPTR / Pre-increment mem location 10, fetch indirect to get the next character of our message SNA / Skip on non-zero AC HLT / Else halt at end of message JMS OUT1 / Write out one character JMP LOOP / And loop back for more OUT1, 0 / Will be replaced by caller's updated PC TSF / Skip if printer ready JMP .-1 / Wait for flag TLS / Send the character in the AC CLA CLL / Clear AC and Link for next pass JMP I OUT1 / Return to caller STRNG, "H / A well-known message "e / "l / NOTE: "l / "o / Strings in PAL-8 and PAL-III were "sixbit" ", / To use ASCII, we spell it out, character by character " / "w / "o / "r / "l / "d / "! / 015 / 012 / 0 / Mark the end of our null-terminated string (.ASCIZ hadn't been invented yet!) The fact that the JMS instruction uses the word just before the code of the subroutine to deposit the return address prevents reentrancy and recursion without additional work by the programmer. It also makes it