src/cmd/cat.s: More comments added, but still more to add.

This commit is contained in:
Warren Toomey
2016-02-27 15:30:38 +10:00
parent 8a8611c590
commit da58308ae4
+39 -35
View File
@@ -1,54 +1,57 @@
" cat " cat: cat [arg1 arg2 ...]
lac 017777 i " exit if four argument words only? " Load the pointer pointer in 017777 to see if we have any arguments
sad d4 lac 017777 i
jmp nofiles sad d4 " Skip if we have more than four argument words
lac 017777 jmp nofiles " Only four argument words, so no arguments
tad d1 " why not tad d5 (add 5)? lac 017777 " Move five words past the argument word count
tad d4 tad d1 " so that AC points at the first argument
dac name " name = *(017777) + 5 tad d4 " and save the pointer in name
dac name
loop: loop:
sys open; name; 0; 0 " open file, get fd back sys open; name; 0; 0 " Open file, get fd back
spa " exit if fd == -1 spa
jmp badfile jmp badfile " Negative fd, exit with an error message
dac fi " save file descriptor in fi dac fi " save file descriptor in fi
1: 1:
jms getc " get a character in AC jms getc " get a character in AC
sad o4 sad o4
jmp 1f jmp 1f
jms putc " write the character on stdout jms putc " write the character on stdout
jmp 1b jmp 1b
1: 1:
lac fi lac fi " Close the file descriptor in fi
sys close sys close
loop1: loop1:
-4 -4
tad 017777 i tad 017777 i " Subtract 4 from the count of argument words
dac 017777 i dac 017777 i
sad d4 sad d4 " Is the value 4, i.e. no args left?
jmp done jmp done " Yes, so exit
lac name
tad d4 lac name " Still an argument, so move up
tad d4 " to the next filename argument
dac name dac name
jmp loop jmp loop " and loop back to cat this file
badfile: badfile:
lac name lac name " Get the pointer to the filename
dac 1f dac 1f " Store it in 1f below
lac d8 " Load fd 8 which is stderr
sys write; 1:0; 4 " Write the four words of the filename
lac d8 lac d8
sys write; 1:0; 4 sys write; 1f; 2 " and then write " ?\n"
lac d8 jmp loop1 " Now try doing the next argument
sys write; 1f; 2
jmp loop1 1: 040;077012 " String literal: " ?\n"
1: 040;077012
nofiles: nofiles:
lac d8 lac d8
sys write; 1f; 5 " write 5 words to fd 8? sys write; 1f; 5 " Write "No files\n" to stderr
sys exit " and exit sys exit " and exit
1: <no>; 040; <fi>;<le>;<s 012 1: <no>; 040; <fi>;<le>;<s 012
@@ -56,24 +59,24 @@ nofiles:
done: done:
lac noc lac noc
sns sns
sys exit sys exit
and d1 and d1
sna cla sna cla
jmp 1f jmp 1f
jms putc jms putc
jmp done jmp done
1: 1:
lac noc lac noc
rcr rcr
dac 1f dac 1f
lac fo " load fd 1, stdout lac fo " Load fd 1, stdout
sys write; iopt+1; 1:.. sys write; iopt+1; 1:..
sys exit sys exit
getc: 0 getc: 0
lac ipt lac ipt
sad eipt sad eipt
jmp 1f jmp 1f
dac 1f dac 1f
add o400000 add o400000
dac ipt dac ipt
@@ -83,13 +86,13 @@ getc: 0
lrss 9 lrss 9
and o177 " keep the lowest 7 bits and o177 " keep the lowest 7 bits
sna sna
jmp getc+1 jmp getc+1
jmp getc i " return from subroutine jmp getc i " return from subroutine
1: 1:
lac fi lac fi
sys read; iipt+1; 64 sys read; iipt+1; 64
sna sna
jmp 1f jmp 1f
tad iipt tad iipt
dac eipt dac eipt
lac iipt lac iipt
@@ -107,7 +110,7 @@ putc: 0
add o400000 add o400000
dac opt dac opt
spa spa
jmp 1f jmp 1f
lac 2f i lac 2f i
xor 2f+1 xor 2f+1
jmp 3f jmp 3f
@@ -119,7 +122,7 @@ putc: 0
isz noc isz noc
lac noc lac noc
sad d128 sad d128
skp skp
jmp putc i jmp putc i
lac fo " load fd 1, stdout lac fo " load fd 1, stdout
sys write; iopt+1; 64 sys write; iopt+1; 64
@@ -127,6 +130,7 @@ putc: 0
dac opt dac opt
dzm noc dzm noc
jmp putc i jmp putc i
2: 0;0 2: 0;0
ipt: 0 ipt: 0
eipt: 0 eipt: 0