Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
PDP-8
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Examples== The following examples show code in PDP-8 [[assembly language]] as one might write for the PAL-III assembler. ===Comparing two numbers=== The following piece of code shows what is needed just to compare two numbers: <pre> /Compare numbers in memory at OPD1 and OPD2 CLA CLL /Must start with 0 in AC and link TAD OPD1 /Load first operand into AC (by adding it to 0); link is still clear CIA /Complement, then increment AC, negating it TAD OPD2 /AC now has OPD2-OPD1; if OPD2≥OPD1, sum overflows and link is set SZL /Skip if link is clear JMP OP2GT /Jump somewhere in the case that OPD2≥OPD1; /Otherwise, fall through to code below. </pre> As shown, much of the text of a typical PDP-8 program focuses not on the author's intended algorithm but on low-level mechanics. An additional readability problem is that in conditional jumps such as the one shown above, the conditional instruction (which skips around the JMP) highlights the opposite of the condition of interest. ===String output=== This complete PDP-8 assembly language program outputs [["Hello, World!" program|"Hello, world!"]] to the teleprinter. <pre> *10 / Set current assembly origin to address 10, STPTR, STRNG-1 / An auto-increment register (one of eight at 10-17) *200 / Set current assembly origin to program text area HELLO, CLA CLL / Clear AC and Link again (needed when we loop back from tls) TAD I Z STPTR / Get next character, indirect via PRE-auto-increment address from the zero page SNA / Skip if non-zero (not end of string) HLT / Else halt on zero (end of string) TLS / Output the character in the AC to the teleprinter TSF / Skip if teleprinter ready for 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 </pre> ===Subroutines=== The PDP-8 processor does not implement a [[stack (abstract data type)|stack]] upon which to store registers or other [[context (computing)|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: <pre> *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!) </pre> The fact that the JMS instruction uses the word just before the code of the subroutine to deposit the [[return address (computing)|return address]] prevents [[reentrant (subroutine)|reentrancy]] and [[recursion]] without additional work by the programmer. It also makes it difficult to use [[read-only memory|ROM]] with the PDP-8 because read-write return-address storage is commingled with read-only code storage in the address space. Programs intended to be placed into ROMs approach this problem in several ways: *They copy themselves to read-write memory before execution, or *They are placed into special ROM cards that provide a few words of read/write memory, accessed indirectly through the use of a thirteenth flag bit in each ROM word. *They avoid the use of subroutines; or use code such as the following, instead of the JMS instruction, to put the return address in read-write memory: <pre> JUMPL, DCA TEMP / Deposit the accumulator in some temporary location TAD JUMPL+3 / Load the return address into the accumulator: hard coded JMP SUBRO / Go to the subroutine, and have it handle jumping back (to JUMPL+3) </pre> The use of the JMS instruction makes debugging difficult. If a programmer makes the mistake of having a subroutine call itself, directly or by an intermediate subroutine, then the return address for the outer call is destroyed by the return address of the subsequent call, leading to an infinite loop. If one module is coded with an incorrect or obsolete address for a subroutine, it would not just fail to execute the entire code sequence of the subroutine, it might modify a word of the subroutine's code, depositing a return address that the processor might interpret as an instruction during a subsequent correct call to the subroutine. Both types of error might become evident during the execution of code that was written correctly. ===Software stack=== Though the PDP-8 does not have a hardware [[stack (abstract data type)|stack]], stacks can be implemented in software.<ref> Mark Smotherman. [http://people.cs.clemson.edu/~mark/subroutines/pdp8.html "DEC PDP-8 Subroutines"]. 2002. </ref> Here are example PUSH and POP subroutines, simplified to omit issues such as testing for stack overflow and underflow: <pre> *100 /make routines accessible for next example PUSH, 0 DCA DATA CLA CMA / -1 TAD SP DCA SP TAD DATA DCA I SP JMP I PUSH /Return POP, 0 CLA CLL TAD I SP ISZ SP JMP I POP DATA, 0 SP, 0 </pre> And here is "Hello World" with this "stack" implemented, and "OUT" subroutine: <pre> *200 MAIN, CLA CLL /Set the message pointer TAD (MESSG /To the beginning of the message (literal) DCA SP LOOP, JMS POP SNA /Stop execution if zero HLT JMS OUT /Otherwise, output a character JMP LOOP MESSG, "H "e "l "l "o ", " "w "o "r "l "d "! 015 012 0 OUT, 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 OUT / Return to caller </pre> ===Linked list=== Another possible subroutine for the PDP-8 is a linked list. <pre> GETN, 0 /Gets the number pointed to and moves the pointer CLA CLL /Clear accumulator TAD I PTR /Gets the number pointed to DCA TEMP /Save current value ISZ PTR /Increment pointer TAD I PTR /Get next address DCA PTR /Put in pointer JMP I GETN /return PTR, 0 TEMP, 0 </pre>
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
PDP-8
(section)
Add topic