From b04641067f481dc4b79b0f5a806496a2bbc6c3e3 Mon Sep 17 00:00:00 2001 From: David Meyer Date: Thu, 10 Mar 2022 20:40:38 +0900 Subject: [PATCH] initial contents --- address.txt | 42 ++++++++++++++++++++++++++++++++++++ ex1.mac | 21 ++++++++++++++++++ ex2a.mac | 24 +++++++++++++++++++++ ex2b.mac | 31 ++++++++++++++++++++++++++ ex3.mac | 33 ++++++++++++++++++++++++++++ ex4a.mac | 48 +++++++++++++++++++++++++++++++++++++++++ gorin.bib | 2 ++ hello-mac.txt | 16 ++++++++++++++ hello.mac | 16 ++++++++++++++ hw1.mac | 17 +++++++++++++++ hw2-0.mac | 33 ++++++++++++++++++++++++++++ hw2-1.mac | 56 +++++++++++++++++++++++++++++++++++++++++++++++ hw2.mac | 49 +++++++++++++++++++++++++++++++++++++++++ instfmt.txt | 28 ++++++++++++++++++++++++ instruct.txt | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++ mydtim.mac | 21 ++++++++++++++++++ mydtim.txt | 47 ++++++++++++++++++++++++++++++++++++++++ template.mac | 18 ++++++++++++++++ 18 files changed, 562 insertions(+) create mode 100644 address.txt create mode 100644 ex1.mac create mode 100644 ex2a.mac create mode 100644 ex2b.mac create mode 100644 ex3.mac create mode 100644 ex4a.mac create mode 100644 gorin.bib create mode 100644 hello-mac.txt create mode 100644 hello.mac create mode 100644 hw1.mac create mode 100644 hw2-0.mac create mode 100644 hw2-1.mac create mode 100644 hw2.mac create mode 100644 instfmt.txt create mode 100644 instruct.txt create mode 100644 mydtim.mac create mode 100644 mydtim.txt create mode 100644 template.mac diff --git a/address.txt b/address.txt new file mode 100644 index 0000000..9667ba0 --- /dev/null +++ b/address.txt @@ -0,0 +1,42 @@ +Memory Address Determination + +The effective memory address referenced by a PDP-10 instruction is +determined by the instructions address (Y), index (X), and indirect (I) +fields. + + +Direct Addressing "Y" + +When Y is specified without X or I, the instruction's effective address +is simply Y. The instruction uses the contents of memory location Y. + + +Indexed Addressing "Y(X)" + +When Y and X are specified but I is zero, the effective address is +determined by using Y as a base then moving forward a number of memory +locations corresponding to the current value of accumulator X. + + +Indirect Addressing "@Y" + +When I is set, the effective address is determined by taking the +contents of memory location Y and interpreting it as another memory +location the contents of which will be used by the instruction. + +Indirect and indexed addressing can be combined: "@Y(X)" + + +The Three I's + +Unfortunately, three related concepts in MACRO assembly language have +been given similar names: Index, Indirect, and Immediate. + +Indexed and indirect addressing are explained above. + +Immediate is an optional modifier to some instructions. When the +immediate modifier is specified, the instruction's effective address +is determined as normal, then the value of the effective address +itself is used as the numeric argument to the instruction, instead of +the contents of the effective address as would be used in a +non-immediate MOVE. diff --git a/ex1.mac b/ex1.mac new file mode 100644 index 0000000..461f7fb --- /dev/null +++ b/ex1.mac @@ -0,0 +1,21 @@ + TITLE G018 - Program to type "Hi". Example 1 + +Comment $ Example 1. Program to type "Hi" + +The following program types "Hi" and carriage return line feed (CRLF) +on the terminal. + +Gorin, p. 18 + +$ + + SEARCH MONSYM ;Add TOPS-20 symbols to MACRO + +START: RESET ;RESET the state of I/O devices + HRROI 1,MESAGE ;Copy address of message to register 1 + PSOUT ;Output the message + HALTF ;Stop execution here. + +MESAGE: ASCIZ /Hi +/ + END START ;End of program, start at START diff --git a/ex2a.mac b/ex2a.mac new file mode 100644 index 0000000..64c06ee --- /dev/null +++ b/ex2a.mac @@ -0,0 +1,24 @@ + TITLE G062 - TRIANGLE Example 2-A + SEARCH MONSYM + +Comment $ Program to print a Triangle $ + +START: RESET + MOVEI 10,5 ;let register 10 be the line number. + ;set it to 5. +;print each line +LINE: MOVE 11,10 ;copy the line number to register 11 +;print the stars on each line +STARS: HRROI 1,ASTER ;Print one asterisk + PSOUT + SOJG 11,STARS ;decrement star count, loop if more + HRROI 1,NEWLIN ;print carriage return and line feed + PSOUT ; to prepare for the next line. + SOJG 10,LINE ;decrement the line numbe held in 10. + ; If the result is positive, do another line + HALTF ;stop here + +ASTER: ASCIZ /*/ +NEWLIN: ASCIZ / +/ + END START diff --git a/ex2b.mac b/ex2b.mac new file mode 100644 index 0000000..89820f4 --- /dev/null +++ b/ex2b.mac @@ -0,0 +1,31 @@ + TITLE TRI AGAIN - Example 2-B + SEARCH MONSYM + +Comment $ A different triangle (Gorin p. 64) $ + +START: RESET ;begin execution here + MOVEI 12,0 ;initial line count +;here to print each line +LINE: MOVEI 13,0 ;initial character count +;print one character on a line +CHAR: CAML 13,12 ;skip if printing spaces + JRST PSTAR ;go print a star + HRROI 1,BLANK ;print a blank + PSOUT + JRST ELIN ;test for end of line + +PSTAR: HRROI 1,ASTER ;print a star + PSOUT +ELIN: CAIGE 13,6 ;have we reached the end of line? + AOJA 13,CHAR ;print the next character + HRROI 1,NEWLIN ;print the carriage return & line feed + PSOUT + CAIGE 12,6 ;finished all lines yet? + AOJA 12,LINE ;no. do more. + HALTF ;all done + +BLANK: ASCIZ / / +ASTER: ASCIZ /*/ +NEWLIN: ASCIZ / +/ + END START diff --git a/ex3.mac b/ex3.mac new file mode 100644 index 0000000..cae8429 --- /dev/null +++ b/ex3.mac @@ -0,0 +1,33 @@ + TITLE ECHO INPUT LINE -- Example 3 + SEARCH MONSYM + +BUFLEN==40 ;the length of the input buffer. + +PROMPT: ASCIZ /Welcome to Echo. Please type a line: / +IBUFR: BLOCK BUFLEN ;reserve space for the input line + +START: RESET ;start here. initialize I/O +GETLIN: HRROI 1,PROMPT ;source of the prompt message + PSOUT ;send prompt to the terminal + HRROI 1,IBUFR ;descriptor of the input buffer + MOVEI 2,5*BUFLEN-1 ;character count of the buffer + HRROI 3,PROMPT ;the reprompt pointer for RDTTY + RDTTY ;read one line from the terminal + ERJMP INERR ;in case of error, print a message + MOVE 15,IBUFR ;first five letters of input line + CAMN 15,[ASCII/LEAVE/] ;test to see if user typed LEAVE + JRST STOP ;LEAVE was typed. Halt the program. + HRROI 1,[ASCIZ /The line you typed was: /] + PSOUT + HRROI 1,IBUFR ;point to the input line for PSOUT + PSOUT ;echo (retype) the input line. + JRST GETLIN ;Go get another line. + +INERR: HRROI 1,[ASCIZ/Error from RDTTY. I give up +/] + PSOUT ;send an error message and stop. +STOP: HALTF ;stop the program here + JRST STOP ;In case of a CONTINUE command, + ; stay stopped. + + END START ;specify the start address. diff --git a/ex4a.mac b/ex4a.mac new file mode 100644 index 0000000..5646803 --- /dev/null +++ b/ex4a.mac @@ -0,0 +1,48 @@ + TITLE REVERSE - Example 4-A + SEARCH MONSYM + +Comment $ + Program to reverse the characters on each line of input. + Program will stop when an empty line is input. + + This program demonstrates the last-in, first-out property + of push-down stacks. Also, it shows the PBIN and PBOUT + JSYS calls. +$ + +A=1 ;symbolic name for ac 1 +P=17 ;symbolic for stack pointer + +PDLEN==200 ;define the stack size +PDLIST: BLOCK PDLEN ;reserve space for the stack. + +START: RESET + MOVE P,[IOWD PDLEN,PDLIST] ;initialize stack pointer +GETLIN: HRROI A,[ASCIZ/Please type a line: /] + PSOUT +INLOOP: PBIN ;read one character + CAIN A,15 ;skip unless carriage return + JRST INLOOP ;discard carriage return + CAIN A,12 ;skip unless end of line + JRST INDONE ;LF was seen. We are done now. + PUSH P,A ;store character on the stack + JRST INLOOP + +;Here at the end of the input line +INDONE: CAMN P,[IOWD PDLEN,PDLIST] ;is the stack empty? + JRST STOP ;empty line, stop running. + HRROI A,[ASCIZ/The reversed line: /] + PSOUT +OUTLOO: POP P,A ;get one character from stack + PBOUT ;send it to the terminal + CAME P,[IOWD PDLEN,PDLIST] ;is the stack empty now? + JRST OUTLOO ;not yet. Loop again. + HRROI A,[ASCIZ/ +/] + PSOUT ;send CR and LF. + JRST GETLIN ;repeat + +STOP: HALTF ;stop at blank line + JRST STOP ;stay stopped + + END START diff --git a/gorin.bib b/gorin.bib new file mode 100644 index 0000000..1793333 --- /dev/null +++ b/gorin.bib @@ -0,0 +1,2 @@ +Ralph E. Gorin, INTRODUCTION TO DECSYSTEM-20 ASSEMBLY LANGUAGE PROGRAMMING, + Bedford, MA, USA: Digital Press, 1981. diff --git a/hello-mac.txt b/hello-mac.txt new file mode 100644 index 0000000..ce89b38 --- /dev/null +++ b/hello-mac.txt @@ -0,0 +1,16 @@ +HELLO.MAC - Hello program in MACRO assembly language + +PUBLIC:HELLO.MAC +PUBLIC:HELLO-MAC.TXT + +Contributed by David Meyer / +March 9, 2022 + +A minimal example of MACRO source code demonstating character string +output. + +To compile, load, and run: + + @EXEC PS:HELLO.MAC + +Make a copy and try your hand at MACRO! diff --git a/hello.mac b/hello.mac new file mode 100644 index 0000000..c0364c9 --- /dev/null +++ b/hello.mac @@ -0,0 +1,16 @@ + TITLE HELLO - Hello program in MACRO assembly language + +Comment $ + Contributed by David Meyer / + March 9, 2022 +$ + + SEARCH MONSYM ;Add TOPS-20 symbols to MACRO + +START: RESET ;RESET the state of I/O devices + HRROI 1,[ASCIZ "Hello, world, from MACRO! +"] ;Compile string (including CRLF) and put + ; address in AC1 + PSOUT ;Output the string + HALTF ;Stop execution here. + END START ;End of program, start at START diff --git a/hw1.mac b/hw1.mac new file mode 100644 index 0000000..2d6ad1e --- /dev/null +++ b/hw1.mac @@ -0,0 +1,17 @@ + TITLE G024 - Self-Identification + +COMMENT / Gorin p. 24 Section 3.3 Exercise (HW1.MAC) / + + SEARCH MONSYM + +START: RESET + HRROI 1,MESAGE + PSOUT + HALTF + +MESAGE: ASCIZ / +My name is David Meyer. +I work at Sumitomo Chemical. +I am studying TOPS-20 assembly language to entertain myself. +/ + END START diff --git a/hw2-0.mac b/hw2-0.mac new file mode 100644 index 0000000..49de69e --- /dev/null +++ b/hw2-0.mac @@ -0,0 +1,33 @@ + TITLE HW2 - Print diamond on screen (Homework 2) + SEARCH MONSYM + +Comment $ (Gorin p. 65) $ + +START: RESET + MOVEI 10,7 ;lines in top triangle + MOVEI 12,6 ;first star on line + MOVEI 13,10 ;last star on line +TOP: MOVEI 11,15 ;char. position countdown + AOS 12 + SOS 13 +TOPCHR: HRROI 1,ASTER + PSOUT + SOJG 11,TOPCHR + HRROI 1,NEWLIN + PSOUT + SOJG 10,TOP + MOVEI 10,6 ;lines in bottom triangle +BOTTOM: MOVEI 11,15 +BOTCHR: HRROI 1,ASTER + PSOUT + SOJG 11,BOTCHR + HRROI 1,NEWLIN + PSOUT + SOJG 10,BOTTOM + HALTF + +ASTER: ASCIZ /*/ +SPACE: ASCIZ / / +NEWLIN: ASCIZ / +/ + END START diff --git a/hw2-1.mac b/hw2-1.mac new file mode 100644 index 0000000..68b0e43 --- /dev/null +++ b/hw2-1.mac @@ -0,0 +1,56 @@ + TITLE HW2 DIAMOND - Homework 2 + SEARCH MONSYM + +Comment $ (Gorin p. 65) $ + +START: RESET ;begin execution here +;UPPER TRIANGLE ... + MOVEI 12,6 ;initial line countdown + MOVEI 14,5 ;initial line length +; here to print each line +ULINE: MOVEI 13,0 ;initial character count + AOS 14 ;increment line length +; print one character on a line +UCHAR: CAML 13,12 ;skip if printing spaces + JRST UPSTAR ;go print a star + HRROI 1,BLANK ;print a blank + PSOUT + JRST UELIN ;test for end of line + +UPSTAR: HRROI 1,ASTER ;print a star + PSOUT +UELIN: CAMGE 13,14 ;have we reached the end of line? + AOJA 13,UCHAR ;print the next character + HRROI 1,NEWLIN ;print the carriage return & line feed + PSOUT + CAILE 12,1 ;finished all lines yet? + SOJA 12,ULINE ;no. do more. + +;LOWER TRIANGLE ... + MOVEI 12,0 ;initial line count + MOVEI 14,15 ;initial line length +; here to print each line +LLINE: MOVEI 13,0 ;initial character count + SOS 14 ;decrement line length +; print one character on a line +LCHAR: CAML 13,12 ;skip if printing spaces + JRST LPSTAR ;go print a star + HRROI 1,BLANK ;print a blank + PSOUT + JRST LELIN ;test for end of line + +LPSTAR: HRROI 1,ASTER ;print a star + PSOUT +LELIN: CAMGE 13,14 ;have we reached the end of line? + AOJA 13,LCHAR ;print the next character + HRROI 1,NEWLIN ;print the carriage return & line feed + PSOUT + CAIGE 12,6 ;finished all lines yet? + AOJA 12,LLINE ;no. do more. + HALTF ;all done + +BLANK: ASCIZ / / +ASTER: ASCIZ /*/ +NEWLIN: ASCIZ / +/ + END START diff --git a/hw2.mac b/hw2.mac new file mode 100644 index 0000000..9726785 --- /dev/null +++ b/hw2.mac @@ -0,0 +1,49 @@ + TITLE HW2 DIAMOND - Homework 2 + SEARCH MONSYM + +Comment $ (Gorin p. 65) + + Accumulator usage: + 10 line counter (L: [-6, 6]) + 11 star pairs on current line (P: [0, 6] (L<=0) + [5, 0] (L>0)) + 12 filler space counter (F: |L| (initial)) + 13 star pair counter +$ + +START: RESET + MOVNI 10,6 + MOVEI 11,0 + +LINE: MOVM 12,10 + MOVE 13,11 + +FILL: JUMPE 12,PAIRS + HRROI 1,SPACE + PSOUT + SOJA 12,FILL + +PAIRS: JUMPE 13,ENDLIN + HRROI 1,STRSTR + PSOUT + SOJA 13,PAIRS + +ENDLIN: HRROI 1,STRNL + PSOUT + + AOJ 10, + CAILE 10,6 + JRST END + + CAILE 10,0 + SOSA 11 + AOJ 11, + JRST LINE + +END: HALTF + +SPACE: ASCIZ / / +STRSTR: ASCIZ /**/ +STRNL: ASCIZ /* +/ + END START diff --git a/instfmt.txt b/instfmt.txt new file mode 100644 index 0000000..c0675c1 --- /dev/null +++ b/instfmt.txt @@ -0,0 +1,28 @@ +PDP-10 Instruction Format + +PDP-10 machine code instructions are stored in 36-bit words with the +following format: + +Bits Length Contents +0-8 9 OP: operation code +9-12 4 AC: accumulator +13 1 I: indirect flag +14-17 4 X: index +18-35 18 Y: address + +(Input/output instructions have a different format, but are only allowed +in privileged programs.) + + +Instruction fields are represented in assembly language statements as +follows: + + OM (AC, I, Y, X are zero) + OM Y (AC, I, X are zero) + OM AC, (I, Y, X are zero) + OM AC,Y (I and X are zero) + OM AC,Y(X) (I is zero) + OM AC,@Y (I is 1, X is zero) + OM AC,@Y(X) (AC, I, Y, X all non-zero) + +(OM: operation code mnemonic name) \ No newline at end of file diff --git a/instruct.txt b/instruct.txt new file mode 100644 index 0000000..e713afe --- /dev/null +++ b/instruct.txt @@ -0,0 +1,60 @@ +PDP-10 Instructions + +MOV - Move full word between accumulator and memory. + + MOVE* - Move without modification. + MOVN* - Negate source. + MOVM* - Magnitude (absolute value) of source. + MOVS* - Swap source upper- and lower-half words. + + MOV* - Move from memory to AC. + MOV*I - Immediate. Source is value of E itself. + MOV*M - Move from AC to memory. + MOV*S - Move from E to E. + +EXCH - Exchange values of AC and E. + +JRST - Unconditional jump. + +JUMP[c] - Compare AC to zero and jump to E if condition met. + +AOJ[c] - Add one to AC, compare result to zero, and jump if condition + met. + +SOJ[c] - Substract one from AC, compare result to zero, and jump if + condition met. + +AOBJ - Add one to both upper- and lower-half word of AC and jump. + + AOBJN - Jump if AC is less than zero. + AOBJP - Jump if AC is greater than or equal to zero. + +SKIP[c] - Compare contents of E to zero and skip next instruction if + condition met. If AC is non-zero, set AC to contents of E. + +AOS[c] - Add one to E, compare result to zero, and skip next + instruction if condition met. If AC is non-zero, set AC to + contents of E. + +SOS[c] - Substract one from E, compare result to zero, and skip next + instruction if condition met. If AC is non-zero, set AC to + contents of E. + +CAM[c] - Compare contents of AC and E and skip next instruction if + condition met. + +CAI[c] - Compare contents of AC to value of E (immediate) and skip next + instruction if condition met. + + +[c] - Arithmetic conditions for jump and skip instructions (JUMP, AOJ, + SOJ, SKIP, AOS, SOS, CAM, CAI). + + blank - Never jump/skip. + L - Less than. + LE - Less than or equal. + E - Equal. + N - Not equal. + GE - Greater than or equal. + G - Greater than. + A - Always jump/skip (JUMPA is deprecated in favor of JRST). diff --git a/mydtim.mac b/mydtim.mac new file mode 100644 index 0000000..9f25d30 --- /dev/null +++ b/mydtim.mac @@ -0,0 +1,21 @@ + TITLE MYDTIM - Emulate EXEC DAYTIME command +Comment $ + Contributed by David Meyer / + March 9, 2022 +$ + SEARCH MONSYM + +START: RESET + HRROI 1,[ASCIZ " "] ;Compile single space string and print + PSOUT ; at beginning of line (because DAYTIME + ; does) + GTAD ;Set AC1 to current system date/time word + MOVE 2,1 ;Copy date/time from AC1 to AC2 + + MOVEI 1,.PRIOU ;Set AC1 to output destination (.PRIOU = + ; primary output) + HRROI 3,-1 ;Set AC3 to format option + ODTIM + + HALTF + END START diff --git a/mydtim.txt b/mydtim.txt new file mode 100644 index 0000000..1a6089f --- /dev/null +++ b/mydtim.txt @@ -0,0 +1,47 @@ +MYDTIM.MAC - Emulate EXEC DAYTIME command + +PUBLIC:MYDTIM.MAC +PUBLIC:MYDTIM.EXE +PUBLIC:MYDTIM.TXT + +Contributed by David Meyer / +March 9, 2022 + +MACRO assembly language source demonstrating use of GTAD and ODTIM JSYS +to get system date/time, then format and print it like the EXEC command +DAYTIME. + +GTAD + Gets the current system date/time word (the format of which is a + story for another day) and stores it in AC1. + +ODTIM + Format and print a date/time. + INPUTS: + AC1: Output destination (.PRIOU for primary output) + AC2: Date/time word (-1 to use current system date/time) + AC3: Date format (-1 for "Weekday, Month dd, yyyy hh:mm:ss" + (like DAYTIME))[*] + +(Since ODTIM can be instructed to use the current system date/time by +storing -1 in AC2, the lines: + + GTAD + MOVE 2,1 + +... could be replaced with: + + HRROI 2,-1 + +... eliminating the need to call GTAD directly.) + + +[*] For more format options, see "ODTIM JSYS 220", TOPS-20 Monitor Calls + Reference Manual, p. 3-295. + + +Reference: + +TOPS-20 Monitor Calls Reference Manual. Nashua, NH: Digital Equipment +Corporation, 1982. Available: Bitsavers' Computing Archive, +http://bitsavers.org/pdf/dec/pdp10/TOPS20/AA-4166E-TM_TOPS-20_Monitor_Calls_Reference_Ver_5_Dec82.pdf [Accessed March 9, 2022]. diff --git a/template.mac b/template.mac new file mode 100644 index 0000000..56c6cf6 --- /dev/null +++ b/template.mac @@ -0,0 +1,18 @@ + TITLE TEMPLT - MACRO program source file template + +Comment $ This is a template for MACRO assembly language source files + +$ + + SEARCH MONSYM ;Add TOPS-20 symbols to MACRO + +START: RESET ;RESET the state of I/O devices + + ;... (program source here) ... + + HALTF ;Stop execution here. + +DATA: ASCIZ /Program data goes here ... +/ + + END START ;End of program, start at START