/////////////////////////////////////// PAL8-V10A NO DATE PAGE 1 ///////////////////////////////////////////////////////////////////// // // Program Interrupt Demonstration Program // INTRODUCTION TO PROGRAMMING 1968 p. 5-32 // // The program presented in Figures 5-16A through 5-16F is a dem- // onstration program to run on the program interrupt facility. It contains // a bit rotating program, the speed and direction of which is determined // by the switch register settings. (This same program is presented in // Exercise 10 of Chapter 3.) The foreground program is the ordering // program which was given in Figure 5-14. This program has the capac- // ity to accept 4-digit positive octal input from the Teletype keyboard, // automatically terminating each 4-digit number with a carriage return // and line feed. Upon receipt of a typed dollar sign ($) , the program will // place the data in increasing order, and type the ordered data on the // printer. The program will not accept negative numbers or nonoctal // digits. // // The example is useful as a demonstration and illustration of the // power of program interrupt as the computer will seem to be perform- // ing two tasks at the same time. The programmer knows that this is not // possible and that the two tasks are sharing the computer time; how- // ever, the appearance indicates simultaneous actions. // // When an interrupt request occurs, locations 0, 1, and 2 of page 0 // provide the storage for the program counter and the jump to the service // routine. // // The constants which are stored on page 0 include four "software // switches" to record the conditions within the running program. MODE // is used to specify the input or output status of the running program. // SW1 is used to signal the input of the first digit of a new number (0) // or the input of successive digits of a continuing number ( 1 ) . SW2 is // used to control the input and output of data by separating each number // with a carriage return and line feed. SW3 is used to bypass the output // mode and allow the typing of carriage returns, line feeds, and question // marks (to denote errors of input) during the input of data. // // Other constants include pointers which permit off-page jumps to // routines elsewhere in memory. The constant BUFF is a pointer to the // storage area for the packed input numbers. It contains END which is // defined as END = . in the last line of Figure 5-16F. Thus, the buffer // is all of memory following the last instruction. // // NOTE: characters input with KRS via OS/8 do not have bit 8 set. JW 2019 // K212 K215 K260 and QUEST have been modified to 12 15 60 and 77. // M260 and MDOLAR have been modified from 7520 and 7534 to 7720 and 7734. // For pdp-8 bare metal assembled with 'palbart' assemble conditionally // with IFDEF DUBL - defined in palbart and not in PAL8. ///////////////////////////////////////////////////////////////////// /////////////////////////////////////// PAL8-V10A NO DATE PAGE 2 0200 *200 /NEXT INSTRUCTIONS INITIALIZE THE PROGRAM. /FURTHER INITIALIZATION DONE BY RESTART. 00200 6002 START, IOF /INTERRUPT OFF DURING INITIALIZATION. 00201 7300 CLA CLL 00202 3050 DCA MODE 00203 3051 DCA SW1 00204 3052 DCA SW2 00205 3053 DCA SW3 00206 1063 TAD BUFF 00207 3064 DCA BUFFPT 00210 3100 DCA AMOUNT 00211 6001 ION /ROTATE SUB-PROGRAM BEGINS HERE. 00212 7320 ROTATE, CLA CLL CML 00213 3240 BEGIN, DCA SAVEAC 00214 7004 RAL 00215 3241 DCA SAVEL 00216 1242 TAD K7000 /ALWAYS SET BITS 0, 1 AND 2. 00217 7404 OSR 00220 3244 DCA COUNT /MAX COUNT IS -1000. 00221 7404 OSR 00222 7004 RAL /PUT BIT 0 IN LINK. 00223 7630 SZL CLA 00224 4245 JMS LEFT /SKIPS NEXT INSTRUCTION 00225 4252 JMS RIGHT 00226 7100 CLL 00227 1241 GO, TAD SAVEL 00230 7010 RAR 00231 1240 TAD SAVEAC 00232 7004 INSTR, RAL /HLT /OVERWRITTEN BY RAR OR RAL. 00233 2243 ISZ COUNTR 00234 5233 JMP INSTR+1 00235 2244 ISZ COUNT 00236 5233 JMP INSTR+1 00237 5213 JMP BEGIN 00240 0000 SAVEAC, 0 00241 0000 SAVEL, 0 00242 7000 K7000, 7000 00243 0000 COUNTR, 0 00244 0000 COUNT, 0 /SUBROUTINES TO DETERMINE DIRECTION. 00245 0000 LEFT, 0 00246 2245 ISZ LEFT /SKIP INSTR AFTER JMS LEFT. 00247 1257 TAD KRAL 00250 3232 DCA INSTR 00251 5645 JMP I LEFT /STORE 'RAL' IN 'INSTR 00252 0000 RIGHT, 0 00253 1256 TAD KRAR 00254 3232 DCA INSTR /STORE "RAR" IN 'INSTR 00255 5652 JMP I RIGHT 00256 7010 KRAR, RAR ///////////////////////////////////////////////////////// 00257 7004 KRAL, RAL // Figure 5-16C. Program Interrupt Demonstration Program // (Initialization Routine and Rotate Subprogram) /////////////////////////////////////// PAL8-V10A NO DATE PAGE 3 /SKIP CHAIN TO SERVICE ROUTINES 00260 3054 SERV, DCA AC /SAVE AC AND L 00261 7004 RAL /DURING AN INTERRUPT. 00262 3055 DCA L 00263 6041 TSF /IS INTERRUPT CAUSED 00264 7410 SKP /BY TELETYPE PRINTER? 00265 5456 JMP I PRINTR /SERVICE TELETYPE PRINTER. 00266 6031 KSF /IS INTERRUPT CAUSED 00267 7410 SKP /BY KEYBOARD? 00270 5457 JMP I KEYBRD /SERVICE KEYBOARD. 00271 7402 HLT /SHOULD NEVER REACH HERE. /ORDER SUB-PROGRAM 00272 7300 ORDER, CLA CLL 00273 1100 TAD AMOUNT /SET TALLY FOR COMPARISONS. 00274 7041 CIA 00275 7001 IAC 00276 3102 DCA TALLY 00277 3101 DCA FLAG /CLEARS FLAG FOR EACH PASS 00300 1063 TAD BUFF 00301 3103 DCA X1 00302 1063 TAD BUFF 00303 7001 IAC 00304 3104 DCA X2 00305 1504 TEST, TAD I X2 00306 7041 CIA 00307 1503 TAD I X1 /IS X2 LESS THAN X1 ? 00310 7750 SPA SNA CLA 00311 5322 JMP INCPTR /NO: DON'T REVERSE. 00312 1503 REVERSE,TAD I X1 /YES: REVERSE X2 AND X1. 00313 3076 DCA HOLD 00314 1504 TAD I X2 00315 3503 DCA I X1 00316 1076 TAD HOLD 00317 3504 DCA I X2 00320 7340 CLA CLL CMA /SET FLAG TO SIGNAL 00321 3101 DCA FLAG /THAT A REVERSE WAS DONE 00322 2103 INCPTR, ISZ X1 /INCREMENT X POINTERS. 00323 2104 ISZ X2 00324 2102 ISZ TALLY /COMPARED ALL ENTRIES? 00325 5305 JMP TEST /NO: COMPARE NEXT X'S. 00326 1101 TAD FLAG /YES: ORDER DONE YET? 00327 7640 SZA CLA 00330 5272 JMP ORDER /NO: MAKE ANOTHER PASS. 00331 7240 CLA CMA 00332 3050 DCA MODE /YES: SET OUTPUT MODE. 00333 1063 TAD BUFF /SET POINTER TO FIRST ENTRY. 00334 3064 DCA BUFFPT 00335 3051 DCA SW1 /CLEAR NUMBER STATUS SWITCH. 00336 1100 TAD AMOUNT /SET A TALLY FOR OUTPUT. 00337 7041 CIA 00340 3105 DCA PRNTCT 00341 7000 NOP /TLS /TO TRIGGER NEXT INTERRUPT.(a null to TLS ??) 00342 5461 JMP I EXITPT // Figure 5-1 6D. Program Interrupt Demonstration Program // (Skip Chain to Service Routines and Order Subprogram) /////////////////////////////////////// PAL8-V10A NO DATE PAGE 4 ///////////////////////////////////////////////////////////////////// // The service routines are reached through the skip chain in Figure // 5-16D. These service routines are located on a separate memory page // and are reached through pointer words stored on page 0. // // The order subprogram is initiated when input is complete. The // routine sorts the positive octal numbers stored in the buffer into in- // creasing order. The technique is the same as that used previously in the // program of Figure 5-14. // // These routines conclude the instructions placed on page 1 of mem- // ory. The service routines begin on the next memory page. ///////////////////////////////////////////////////////////////////// 0400 *400 00400 6032 KB, KCC 00401 1050 TAD MODE /INPUT MODE DOES NOT (output mode surely JW) 00402 7640 SZA CLA /HONOR KEYBOARD REQUEST. 00403 5375 JMP EXIT 00404 1051 TAD SW1 00405 7640 SZA CLA /CHECK FOR A NEW NUMBER 00406 5213 JMP CNTDIG /OR A CONTINUED DIGIT. 00407 1065 TAD M4 00410 3066 DCA DIGCTR 00411 1067 TAD TEMP1 00412 3070 DCA TEMP 00413 6034 CNTDIG, KRS /READ KEYBOARD CHARACTER. 00414 6046 TLS /TYPE IT ON PRINTER. 00415 3470 DCA I TEMP /STORE DIGIT TEMPORARILY. 00416 1470 CHECK, TAD I TEMP 00417 1113 TAD MDOLAR /CHECK FOR TERMINAL $ 00420 7650 SNA CLA 00421 5460 JMP I ORDPTR 00422 1470 TAD I TEMP 00423 1114 TAD M260 /ASCII LESS THAN 260? 00424 7510 SPA 00425 5231 JMP ERROR /YES: ERROR. 00426 1075 TAD M10 /NO: SUBTRACT 10. 00427 7510 SPA /GREATER THAN 267? 00430 5236 JMP LEGAL /NO: DIGIT IS LEGAL. 00431 7201 ERROR, CLA IAC /NOT AN OCTAL NUMBER. 00432 3053 DCA SW3 /SET TO TYPE ?,CR,LF. 00433 3051 DCA SW1 /SET FOR A NEW NUMBER. 00434 7000 NOP /TLS /overwrites previous TLS with null ?? ///////////////////////////////////////////////////////////////////// // Figure 5-16E. Program Interrupt Demonstration Program // (Keyboard Service Routine) ///////////////////////////////////////////////////////////////////// /////////////////////////////////////// PAL8-V10A NO DATE PAGE 5 ///////////////////////////////////////////////////////////////////// // The service routines begin in location 400 as presented in Figure // 5-16E. The keyboard service routine honors an interrupt only if the // mode is set to 0. The routine uses SW1 to specify number status, re- // setting the digit counter if a new number is started. The routine accepts // the incoming digit and types it on the printer. // // The input of a non-octal character or terminal symbol ($) is checked // after each character is received. Whenever the terminal $ is received // by the program, control is transferred to the order subprogram. If the // character is not an octal digit, the program types a question mark and // ignores the whole entry in which it occurred. The program requests a // new 4-digit number by typing a carriage return and line feed. // // When four digits have been received, the pack routine combines the // four ASCII codes into one octal number and stores the number in the // buffer. If the number is negative, the entry is disallowed. (The next // packed number will be deposited in the same location, thus destroying // the negative number.) A running count of the entries is kept and later // used when ordering is performed. The software switches are finally set // to return the carriage for the next number to be input. // // The printer service routine in Figure 5-16F is used to output the // ordered numbers and to type carriage returns, line feeds and question // marks during input. The "mode bypass switch", SW3, is used in con- // junction with the subroutines on page 0 to type carriage returns and // line feeds. If the program is in output mode, the results of the sorting // will be typed by the printer service routine. The stored numbers will be // unpacked, translated into ASCII codes and typed out. // // When the action of either service routine is completed, the exit rou- // tine returns control to the background program until the next interrupt // occurs. This routine restores the accumulator and link and turns the // interrupt on before jumping to the interrupted background program. // The restart routine initializes the software switches for the ordering // of a new set of data input from the keyboard. The mode is set for input // and control returns to the background program until new input is // suppied. ///////////////////////////////////////////////////////////////////// /////////////////////////////////////// PAL8-V10A NO DATE PAGE 6 00435 5375 JMP EXIT 00436 7240 LEGAL, CLA CMA /SET SW1 TO SIGNAL 00437 3051 DCA SW1 /A CONTINUED NUMBER. 00440 2070 ISZ TEMP 00441 2066 ISZ DIGCTR /HAVE 4 DIGITS? 00442 5375 JMP EXIT /NO: GET NEXT DIGIT. 00443 1067 PACK, TAD TEMP1 /YES: PUT NUMBER TOGETHER. 00444 3070 DCA TEMP 00445 3076 DCA HOLD 00446 1065 TAD M4 00447 3066 DCA DIGCTR 00450 1076 DIGPCK, TAD HOLD /NEXT 7 INSTRUCTIONS 00451 7104 RAL CLL /COMBINE THE A OCTAL DIGITS 00452 7006 RTL /INTO ONE MEMORY WORD. 00453 1470 TAD I TEMP 00454 1114 TAD M260 00455 3076 DCA HOLD 00456 2070 ISZ TEMP 00457 2066 ISZ DIGCTR 00460 5250 JMP DIGPCK /PACK ANOTHER DIGIT. 00461 1076 TAD HOLD 00462 3464 DCA I BUFFPT /STORE THE OCTAL NUMBER. 00463 1464 TAD I BUFFPT /CHECK FOR NEGATIVE ENTRY. 00464 1115 TAD K4000 00465 7710 SPA CLA 00466 5271 JMP NOTNEG /ENTRY IS LEGAL. 00467 7001 IAC /SET SW3 TO TYPE A "?". 00470 5274 JMP DISALO /DISALLOW NEGATIVE ENTRY. 00471 2064 NOTNEG, ISZ BUFFPT 00472 2100 ISZ AMOUNT /COUNT THE ENTRIES. 00473 7240 CLA CMA /TYPE A CR,LF 00474 3053 DISALO, DCA SW3 /AFTER THE ENTRY. 00475 3051 DCA SW1 /CLEAR SW1 FOR NEXT PASS. 00476 7000 NOP /TLS /overwrites previous TLS with null ?? 00477 5375 JMP EXIT ///////////////////////////////////////////////////////////////////// // Figure 5-16E (cont.). Program Interrupt Demonstration Program // (Keyboard Service Routine) ///////////////////////////////////////////////////////////////////// /////////////////////////////////////// PAL8-V10A NO DATE PAGE 7 /PRINTER SERVICE ROUTINE 00500 6042 TP, TCF 00501 1053 TAD SW3 /CHECK MODE-BYPASS-SWITCH, 00502 7650 SNA CLA 00503 5314 JMP MODCHK /NO BYPASS, CHECK MODE. 00504 1053 TAD SW3 00505 7710 SPA CLA 00506 5317 JMP RETLF /MODE-BYPASS, DO A CR & LF. 00507 1112 TAD QUEST /MODE BY PASS SET FOR "?". 00510 6046 TLS 00511 7240 CLA CMA /AFTER TYPING THE ? SET SW3. 00512 3053 DCA SW3 /TO TYPE THE CR &LF 00513 5375 JMP EXIT 00514 1050 MODCHK, TAD MODE /CHECK MODE. 00515 7650 SNA CLA 00516 5375 JMP EXIT /INPUT MODE: IGNORE REQUEST! 00517 1052 RETLF, TAD SW2 /OUTPUT MODE: BEGIN OUTPUT. 00520 7650 SNA CLA 00521 5116 JMP CR /FIRST PASS, CARRIAGE RETURN. 00522 1052 TAD SW2 00523 7710 SPA CLA 00524 5123 JMP LF /LINE FEED ON SECOND PASS. 00525 1051 DATA, TAD SW1 /PRINT DATA ON THIRD PASS. 00526 7640 SZA CLA /NEW NUMBER? 00527 5335 JMP DIGTYP /NO: TYPE ANOTHER DIGIT. 00530 1065 TAD M4 /YES: RESET DIGIT COUNTER. 00531 3066 DCA DIGCTR 00532 3076 DCA HOLD /CLEAR THESE LOCATIONS. 00533 3077 DCA HOLDL ///////////////////////////////////////////////////////////////////// // Figure 5-16F. Program Interrupt Demonstration Program // (Printer Service, Exit and Restart Routines) ///////////////////////////////////////////////////////////////////// /////////////////////////////////////// PAL8-V10A NO DATE PAGE 8 00534 1464 TAD I BUFFPT /GET NUMBER TO BE PRINTED. 00535 1077 DIGTYP, TAD HOLDL 00536 7104 CLL RAL /ROTATE INTO THE LINK. 00537 1076 TAD HOLD /THESE TWELVE INSTRUCTIONS 00540 7004 RAL /PRINT OUT THE NEXT DIGIT. 00541 7006 RTL 00542 3076 DCA HOLD 00543 7010 RAR 00544 3077 DCA HOLDL 00545 1076 TAD HOLD 00546 0106 AND K7 00547 1107 TAD K260 00550 6046 TLS 00551 7240 CLA CMA /SET FOR ANOTHER DIGIT. 00552 3051 DCA SW1 00553 2066 ISZ DIGCTR /WORD COMPLETE? 00554 5375 JMP EXIT /NO: GET ANOTHER DIGIT. 00555 7200 CLA /YES: SIGNAL A NEW NUMBER. 00556 3051 DCA SW1 00557 3052 DCA SW2 /TYPE A CR & LF. 00560 2064 ISZ BUFFPT 00561 2105 ISZ PRNTCT /ALL NUMBERS PRINTED? 00562 5375 JMP EXIT /NO: WAIT FOR NEW NUMBER. 00563 7300 RESTART,CLA CLL /YES: SET UP FOR NEW INPUT. 00564 3050 DCA MODE 00565 3051 DCA SW1 00566 3052 DCA SW2 00567 7040 CMA /SET BYPASS SWITCH 00570 3053 DCA SW3 /TO TYPE A CR & LF. 00571 1063 TAD BUFF 00572 3064 DCA BUFFPT 00573 3100 DCA AMOUNT 00574 5375 JMP EXIT /ROUTINE TO RETURN TO ROTATE PROGRAM 00575 7300 EXIT, CLA CLL 00576 1055 TAD L 00577 7010 RAR 00600 1054 TAD AC 00601 6001 ION 00602 5400 JMP I 0 /0 CONTAINS RETURN ADDRESS. 0603 END=. ///////////////////////////////////////////////////////////////////// // Figure 5-16F (cont.). Program Interrupt Demonstration Program // (Printer Service, Exit and Restart Routines) // https://archive.org/stream/bitsavers_decpdp8hanmming1969_20151892/ // IntroToProgramming1969_djvu.txt (reconstituted J.E. Wulff 20190204) ///////////////////////////////////////////////////////////////////// /////////////////////////////////////// PAL8-V10A NO DATE PAGE 9 0000 *0 /FIRST INSTRUCTIONS AFTER AN INTERRUPT. 00000 0000 0 00001 5402 JMP I 2 00002 0260 SERV 0050 *50 /CONSTANTS STORED ON PAGE 0. 00050 0000 MODE, 0 /INPUT=0; OUTPUT=-l. 00051 0000 SW1, 0 /NUMBER STATUS SWITCH 00052 0000 SW2, 0 /OUTPUT:CR=0,LF=-l,DATA=l. 00053 0000 SW3, 0 /MODE BYPASS SWITCH 00054 0000 AC, 0 /SAVE AC AND 00055 0000 L, 0 /L DURING AN INTERRUPT. 00056 0500 PRINTR, TP /FOLLOWING ARE POINTERS FOR 00057 0400 KEYBRD, KB /THE RESPECTIVE ROUTINES. 00060 0272 ORDPTR, ORDER 00061 0575 EXITPT, EXIT 00062 1000 M7000, 1000 /ORDER SUB-PROGRAM CONSTANTS 00063 0603 BUFF, END 00064 0000 BUFFPT, 0 00065 7774 M4, 7774 00066 0000 DIGCTR, 0 00067 0071 TEMP1, .+2 00070 0000 TEMP, 0 00071 0000 0 00072 0000 0 00073 0000 0 00074 0000 0 00075 7770 M10, -10 00076 0000 HOLD, 0 00077 0000 HOLDL, 0 00100 0000 AMOUNT, 0 00101 0000 FLAG, 0 00102 0000 TALLY, 0 00103 0000 X1, 0 00104 0000 X2, 0 00105 0000 PRNTCT, 0 00106 0007 K7, 7 IFDEF DUBL < / defined for palbart assembler K260, 260 / '0' K212, 212 / LF K215, 215 / CR QUEST, 277 MDOLAR, -244 M260, -260 > IFNDEF DUBL < / NOT defined for PAL8 assembler 00107 0060 K260, 60 / '0' 00110 0012 K212, 12 / LF 00111 0015 K215, 15 / CR 00112 0077 QUEST, 77 00113 7734 MDOLAR, -44 00114 7720 M260, -60 > /////////////////////////////////////// PAL8-V10A NO DATE PAGE 9-1 00115 4000 K4000, 4000 ///////////////////////////////////////////////////////////////////// // Figure 5-1 6A. Program Interrupt Demonstration Program // (Constants Located on Page 0) ///////////////////////////////////////////////////////////////////// /////////////////////////////////////// PAL8-V10A NO DATE PAGE 10 /SUBROUTINES STORED ON PAGE 0. 00116 1111 CR, TAD K215 /CARRIAGE RETURN ROUTINE 00117 6046 TLS 00120 7240 CLA CMA 00121 3052 DCA SW2 /SET SW2 FOR A LF. 00122 5461 JMP I EXITPT 00123 1110 LF, TAD K212 /LINE FEED ROUTINE 00124 6046 TLS 00125 7200 CLA 00126 1053 TAD SW3 00127 7650 SNA CLA 00130 5134 JMP SW2SET 00131 3053 DCA SW3 /TURN OFF MODE BYPASS. 00132 3052 DCA SW2 /SET SW2 FOR CR. 00133 5461 JMP I EXITPT 00134 7301 SW2SET, CLA CLL IAC 00135 3052 DCA SW2 /SET SW2 FOR DATA, 00136 5461 JMP I EXITPT ///////////////////////////////////////////////////////////////////// // Figure 5-1 6B. Program Interrupt Demonstration Program // (Subroutines Located on Page 0) // // The location TEMP is used as a pointer to the four locations after // it; these locations are used for the storage of incoming ASCII codes. // // The subroutines CR and LF type the carriage returns and line feeds // when called for by the setting of SW2. // // The program begins in location 200 as shown in Figure 5-16C. The // initialization routine sets each of the software switches to zero. After // the initialization is completed, the interrupt facility is turned on and the // background program is started. // // The rotate subprogram begins by checking the setting of the switch // register to determine the direction of rotation. The value of bit // specifies a rotate right when it is a 0, or a rotate left when it is a 1. The // last nine bits of the switch register determine the speed of the rotation. // They are stored in COUNT and determine the number of passes // through the ISZ COUNTR, JMP .-1 loop. // // The BEGIN routine determines the speed and direction and the GO // routine establishes the bit position after each check of the switch regis- // ter setting. The INSTR routine executes the delay and the rotation of // the bit. ///////////////////////////////////////////////////////////////////// $ /////////////////////////////////////// PAL8-V10A NO DATE PAGE 11 AC 0054 REVERS 0312 AMOUNT 0100 RIGHT 0252 BEGIN 0213 ROTATE 0212 BUFF 0063 SAVEAC 0240 BUFFPT 0064 SAVEL 0241 CHECK 0416 SERV 0260 CNTDIG 0413 START 0200 COUNT 0244 SW1 0051 COUNTR 0243 SW2 0052 CR 0116 SW2SET 0134 DATA 0525 SW3 0053 DIGCTR 0066 TALLY 0102 DIGPCK 0450 TEMP 0070 DIGTYP 0535 TEMP1 0067 DISALO 0474 TEST 0305 END 0603 TP 0500 ERROR 0431 X1 0103 EXIT 0575 X2 0104 EXITPT 0061 FLAG 0101 GO 0227 HOLD 0076 HOLDL 0077 INCPTR 0322 INSTR 0232 KB 0400 KEYBRD 0057 KRAL 0257 KRAR 0256 K212 0110 K215 0111 K260 0107 K4000 0115 K7 0106 K7000 0242 L 0055 LEFT 0245 LEGAL 0436 LF 0123 MDOLAR 0113 MODCHK 0514 MODE 0050 M10 0075 M260 0114 M4 0065 M7000 0062 NOTNEG 0471 ORDER 0272 ORDPTR 0060 PACK 0443 PRINTR 0056 PRNTCT 0105 QUEST 0112 RESTAR 0563 RETLF 0517 ERRORS DETECTED: 0 LINKS GENERATED: 0