mirror of
https://github.com/livingcomputermuseum/pdp7-unix.git
synced 2026-02-15 12:27:30 +00:00
I refactored tools/wktcat.s to lose the repeated code, and I also
improved the comments in the code. I'm happy with it, now.
This commit is contained in:
@@ -9,9 +9,6 @@
|
||||
"
|
||||
" ./a7out a.out z1 z1
|
||||
" <the text you typed in will be displayed twice>
|
||||
"
|
||||
" Also, the current coding is hideous and needs refactoring.
|
||||
" I'm still coming to grips with PDP-7 assembly code.
|
||||
|
||||
main:
|
||||
" Load the pointer pointer in 017777 to see if we have any arguments
|
||||
@@ -19,23 +16,24 @@ main:
|
||||
sad d4 " Skip if we have more than four argument words
|
||||
jmp stdinout " Only four argument words, so no arguments
|
||||
|
||||
lac 017777
|
||||
tad d1 " Bump AC up by 5 so that it points at the first argument
|
||||
lac 017777 " Move five words past the argument word count
|
||||
tad d1 " so that AC points at the first argument
|
||||
tad d4
|
||||
|
||||
" This section opens files, and copies their contents to standard output
|
||||
" This section opens files and copies their contents to standard output
|
||||
catfiles:
|
||||
" We start with AC pointing to an argument. Save it at label 1f
|
||||
" We start with AC pointing to an argument. Save it at the "name" label
|
||||
dac name
|
||||
|
||||
" Open the file and get the fd into AC
|
||||
sys open; name:0; 0; 0
|
||||
spa
|
||||
jmp badfile " Bad fd, exit with an error message
|
||||
jmp badfile " Negative fd, exit with an error message
|
||||
dac fd " Save the file descriptor
|
||||
|
||||
fileloop:
|
||||
" Read five words into the buffer from the input file
|
||||
" Five was chosen arbitrarily
|
||||
lac fd
|
||||
sys read; buf; 5
|
||||
spa " Skip if result was >= 0
|
||||
@@ -76,26 +74,15 @@ end:
|
||||
sys exit
|
||||
|
||||
" This section copies from standard input to standard output
|
||||
" We cheat by setting the fd value to zero and storing 8
|
||||
" into the argc word count, so that when the code hits
|
||||
" fileend, the word count drops to 4 and we exit.
|
||||
stdinout:
|
||||
" Read five words into the buffer from stdin
|
||||
" Five was chosen arbitrarily
|
||||
lac d8
|
||||
dac 017777 i " Save 8 into the word count
|
||||
lac d0
|
||||
sys read; buf; 5
|
||||
spa " Skip if result was >= 0
|
||||
jmp error " Result was -ve, so error result
|
||||
sna " Skip if result was >0
|
||||
jmp end " Result was zero, so nothing left to read
|
||||
|
||||
" Save the count of words read in
|
||||
dac 1f
|
||||
|
||||
" Write five words from the buffer to stdout
|
||||
lac d1
|
||||
sys write; buf; 1:0
|
||||
|
||||
" and loop back for more words to read
|
||||
jmp stdinout
|
||||
|
||||
dac fd " Save file descriptor 0
|
||||
jmp fileloop
|
||||
|
||||
" This code comes from the real cat.s
|
||||
badfile:
|
||||
@@ -107,12 +94,11 @@ badfile:
|
||||
sys write; 1f; 2
|
||||
sys exit " and exit
|
||||
|
||||
1: 040; 077012
|
||||
|
||||
1: 040; 077012 " String literal: " ?\n"
|
||||
|
||||
error:
|
||||
" Print an "err read" string and exit
|
||||
lac d1
|
||||
" Print an "err read" string on stderr and exit
|
||||
lac d8
|
||||
sys write; noreadstr; 5
|
||||
sys exit
|
||||
|
||||
@@ -120,11 +106,11 @@ noreadstr:
|
||||
<er>;<r 040;<re>;<ad>;012000
|
||||
|
||||
fd: 0 " fd of the open file
|
||||
d0: 0 " Constants 0 and 1
|
||||
d0: 0 " Constants 0, 1, 4 and 8
|
||||
d1: 1
|
||||
d4: 4
|
||||
d8: 8 " stderr seems to have fd 8
|
||||
minus4: 0777774 " -4 constant
|
||||
minus4: 0777774 " Constant -4
|
||||
|
||||
" Input buffer for read
|
||||
buf: 0; 0; 0; 0; 0
|
||||
|
||||
Reference in New Issue
Block a user