tools/as7: added syscalls chmod and chown, added auto-increment
locations, fixed a bug in character input, added several EAE instructions. We now have cp.s, chmod.s and chown.s working.
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
||||
" cat: cat [arg1 arg2 ...]
|
||||
" cat: cat arg1 [arg2 ...]
|
||||
|
||||
" Load the pointer pointer in 017777 to see if we have any arguments
|
||||
lac 017777 i
|
||||
|
||||
+58
-52
@@ -1,77 +1,83 @@
|
||||
" chmode
|
||||
" chmod: chmod mode file [file file ...]
|
||||
"
|
||||
" mode is an octal number
|
||||
|
||||
lac 017777 i
|
||||
lac 017777 i " Have we got any arguments?
|
||||
sad d4
|
||||
jmp error
|
||||
|
||||
jmp error " No, give an error
|
||||
lac 017777
|
||||
tad d4
|
||||
dac 8
|
||||
tad d1
|
||||
dac name
|
||||
dzm octal
|
||||
dzm nchar
|
||||
-8
|
||||
dac c1
|
||||
tad d4 " Skip past argc
|
||||
dac 8 " and save the ptr to the octal value at location 8
|
||||
tad d1 " Why only 1 here?
|
||||
dac name " Save the filename pointer
|
||||
dzm octal " Zero the octal value and
|
||||
dzm nchar " the number of characters
|
||||
-8 " Set c1 to -8 so we can increment up to zero
|
||||
dac c1 " and thus count the number of chars in the argument
|
||||
|
||||
1:
|
||||
lac nchar
|
||||
dzm nchar
|
||||
sza
|
||||
jmp 2f
|
||||
lac 8 i
|
||||
lmq
|
||||
and o177
|
||||
dac nchar
|
||||
lacq
|
||||
lrss 9
|
||||
lac nchar " Get any left-over character from the last loop
|
||||
dzm nchar " and set nchar to empty now
|
||||
sza " It was already empty, so get a new word
|
||||
jmp 2f " Not empty, it has the second ASCII value, goto 2f
|
||||
lac 8 i " Read the next word with two chars in it
|
||||
lmq " Copy it to MQ
|
||||
and o177 " Trim off all but the second ASCII value
|
||||
dac nchar " Save it into nchar
|
||||
lacq " Bring it back from MQ
|
||||
lrss 9 " and shift down the first ASCII value
|
||||
|
||||
2:
|
||||
sad o40
|
||||
jmp 3f
|
||||
tad om60
|
||||
lmq
|
||||
lac octal
|
||||
cll; als 3
|
||||
omq
|
||||
dac octal
|
||||
sad o40 " If the character is a space
|
||||
jmp 3f " don't try to make it part of the octal value
|
||||
tad om60 " Not a space, subtract 060 i.e. '0'
|
||||
lmq " Move it into MQ
|
||||
lac octal " Load the octal value up to here
|
||||
cll; als 3 " Shift it left 3 bits
|
||||
omq " OR in the digit from MQ
|
||||
dac octal " and save back in the octal value
|
||||
|
||||
3:
|
||||
isz c1
|
||||
jmp 1b
|
||||
isz c1 " Is that the last character?
|
||||
jmp 1b " No, go back and get another one
|
||||
|
||||
loop:
|
||||
lac 017777 i
|
||||
lac 017777 i " How many arguments left?
|
||||
sad d8
|
||||
sys exit
|
||||
tad dm4
|
||||
dac 017777 i
|
||||
lac name
|
||||
sys exit " None, exit
|
||||
tad dm4 " Subtract 4 to indicate one less argument
|
||||
dac 017777 i " and save for next time
|
||||
lac name " Also move to the next filename
|
||||
tad d4
|
||||
dac name
|
||||
lac octal
|
||||
sys chmode; name:0
|
||||
lac octal " Set AC to have the new file mode
|
||||
sys chmod; name:0 " and change the file's mode
|
||||
sma
|
||||
jmp loop
|
||||
lac name
|
||||
dac 1f
|
||||
lac d1
|
||||
sys write; 1:0; 4
|
||||
jmp loop " Loop if no error
|
||||
lac name " We got back -1, error
|
||||
dac 1f " Write out the filename on stdout
|
||||
lac d1 " followed by the " ?\n" string
|
||||
sys write; 1:0; 4 " and loop back
|
||||
lac d1
|
||||
sys write; 1f; 2
|
||||
jmp loop
|
||||
|
||||
1:
|
||||
040;077012
|
||||
040;077012 " String literal " ?\n"
|
||||
|
||||
error:
|
||||
lac d1
|
||||
lac d1 " Write " "\n" to stdout and exit
|
||||
sys write; 1b+1; 1
|
||||
sys exit
|
||||
|
||||
om60: -060
|
||||
o40: 040
|
||||
d1: 1
|
||||
d1: 1 " Numeric constants
|
||||
d4: 4
|
||||
d8: 8
|
||||
dm4: -4
|
||||
d4: 4
|
||||
o40: 040
|
||||
o177: 0177
|
||||
om60: -060
|
||||
|
||||
nchar: .=.+1
|
||||
nchar: .=.+1 " Number of characters in the value entered
|
||||
c1: .=.+1
|
||||
octal: .=.+1
|
||||
octal: .=.+1 " The resulting octal value
|
||||
|
||||
+60
-53
@@ -1,76 +1,83 @@
|
||||
" chown
|
||||
lac 017777 i
|
||||
sad d4
|
||||
jmp error
|
||||
" chown: chown uid file [file file ...]
|
||||
"
|
||||
" uid is an octal number
|
||||
|
||||
lac 017777 i " Have we got any arguments?
|
||||
sad d4
|
||||
jmp error " No, give an error
|
||||
lac 017777
|
||||
tad d4
|
||||
dac 8
|
||||
tad d1
|
||||
dac name
|
||||
dzm octal
|
||||
dzm nochar
|
||||
-8
|
||||
dac c1
|
||||
tad d4 " Skip past argc
|
||||
dac 8 " and save the ptr to the octal value at location 8
|
||||
tad d1 " Why only 1 here?
|
||||
dac name " Save the filename pointer
|
||||
dzm octal " Zero the octal value and
|
||||
dzm nchar " the number of characters
|
||||
-8 " Set c1 to -8 so we can increment up to zero
|
||||
dac c1 " and thus count the number of chars in the argument
|
||||
|
||||
1:
|
||||
lac nchar
|
||||
dzm nchar
|
||||
sza
|
||||
jmp 2f
|
||||
lac 8 i
|
||||
lmq
|
||||
and o177
|
||||
dac nchar
|
||||
lacq
|
||||
lrss 9
|
||||
lac nchar " Get any left-over character from the last loop
|
||||
dzm nchar " and set nchar to empty now
|
||||
sza " It was already empty, so get a new word
|
||||
jmp 2f " Not empty, it has the second ASCII value, goto 2f
|
||||
lac 8 i " Read the next word with two chars in it
|
||||
lmq " Copy it to MQ
|
||||
and o177 " Trim off all but the second ASCII value
|
||||
dac nchar " Save it into nchar
|
||||
lacq " Bring it back from MQ
|
||||
lrss 9 " and shift down the first ASCII value
|
||||
|
||||
2:
|
||||
sad o40
|
||||
jmp 3f
|
||||
tad om60
|
||||
lmq
|
||||
lac octal
|
||||
cll; als 3
|
||||
omq
|
||||
dac octal
|
||||
sad o40 " If the character is a space
|
||||
jmp 3f " don't try to make it part of the octal value
|
||||
tad om60 " Not a space, subtract 060 i.e. '0'
|
||||
lmq " Move it into MQ
|
||||
lac octal " Load the octal value up to here
|
||||
cll; als 3 " Shift it left 3 bits
|
||||
omq " OR in the digit from MQ
|
||||
dac octal " and save back in the octal value
|
||||
|
||||
3:
|
||||
isz c1
|
||||
jmp 1b
|
||||
isz c1 " Is that the last character?
|
||||
jmp 1b " No, go back and get another one
|
||||
|
||||
loop:
|
||||
lac 017777 i
|
||||
lac 017777 i " How many arguments left?
|
||||
sad d8
|
||||
sys exit
|
||||
tad dm4
|
||||
dac 017777 i
|
||||
lac name
|
||||
sys exit " None, exit
|
||||
tad dm4 " Subtract 4 to indicate one less argument
|
||||
dac 017777 i " and save for next time
|
||||
lac name " Also move to the next filename
|
||||
tad d4
|
||||
dac name
|
||||
lac octal
|
||||
sys chowner; name:0
|
||||
lac octal " Set AC to have the new file mode
|
||||
sys chown; name:0 " and change the file's owner
|
||||
sma
|
||||
jmp loop
|
||||
lac name
|
||||
dac 1f
|
||||
lac d1
|
||||
sys write; 1:0; 4
|
||||
jmp loop " Loop if no error
|
||||
lac name " We got back -1, error
|
||||
dac 1f " Write out the filename on stdout
|
||||
lac d1 " followed by the " ?\n" string
|
||||
sys write; 1:0; 4 " and loop back
|
||||
lac d1
|
||||
sys write; 1f; 2
|
||||
jmp loop
|
||||
|
||||
1:
|
||||
040;077012
|
||||
040;077012 " String literal " ?\n"
|
||||
|
||||
error:
|
||||
lac d1
|
||||
sys write; 1b+1; 1
|
||||
lac d1 " Write " "\n" to stdout and exit
|
||||
sys write; 1b+1; 1
|
||||
sys exit
|
||||
|
||||
om60: -060
|
||||
o40: 040
|
||||
d1: 1
|
||||
d1: 1 " Numeric constants
|
||||
d4: 4
|
||||
d8: 8
|
||||
dm4: -4
|
||||
d4: 4
|
||||
o40: 040
|
||||
o177: 0177
|
||||
om60: -060
|
||||
|
||||
nchar: .=.+1
|
||||
nchar: .=.+1 " Number of characters in the value entered
|
||||
c1: .=.+1
|
||||
octal: .=.+1
|
||||
octal: .=.+1 " The resulting octal value
|
||||
|
||||
+31
-26
@@ -1,41 +1,46 @@
|
||||
" chrm
|
||||
" chrm: chrm dir file [file file ...]
|
||||
"
|
||||
" chdir into the named directory and unlink the files that are in there
|
||||
"
|
||||
" The code depends on a "dd" directory existing which holds the named dir
|
||||
|
||||
lac 017777
|
||||
tad d5
|
||||
dac 1f
|
||||
dac 2f
|
||||
lac 017777 i
|
||||
lac 017777 " Go to the argc
|
||||
tad d5 " Skip past the argc and argv[0]
|
||||
dac 1f " Save argv[1] in the chdir arg below
|
||||
dac 2f " and in the unlink as well? Yes, we skip it
|
||||
lac 017777 i " How many arguments do we have?
|
||||
sad d4
|
||||
sys exit
|
||||
tad dm4
|
||||
dac 017777 i
|
||||
sys chdir; dd
|
||||
sys chdir; 1;0
|
||||
sys exit " None, so exit
|
||||
tad dm4 " Subtract 1
|
||||
dac 017777 i " and save in the argc
|
||||
|
||||
sys chdir; dd " chdir to dd
|
||||
sys chdir; 1;0 " and then into the first argument
|
||||
1:
|
||||
lac 017777 i
|
||||
lac 017777 i " Any arguments left?
|
||||
sad d4
|
||||
sys exit
|
||||
tad dm4
|
||||
sys exit " No, exit the program
|
||||
tad dm4 " Subtract 4 from the argc and update it
|
||||
dac 017777 i
|
||||
lac 2f
|
||||
lac 2f " Move up to the next filename
|
||||
tad d4
|
||||
dac 2f
|
||||
sys unlink; 2:0
|
||||
dac 2f " and save it in the unlink arg
|
||||
sys unlink; 2:0 " Unlink the file
|
||||
sma
|
||||
jmp 1b
|
||||
lac 2b
|
||||
jmp 1b " Loop back if the unlink was OK, or issue err
|
||||
lac 2b " Copy the filename pointer below
|
||||
dac 2f
|
||||
lac d1
|
||||
lac d1 " Write the filename on stdout
|
||||
sys write; 2:0; 4
|
||||
lac d1
|
||||
sys write; 1f; 2
|
||||
jmp 1b
|
||||
1:
|
||||
040077;012000
|
||||
sys write; 1f; 2 " Write " ?\n" on stdout
|
||||
jmp 1b " and loop back
|
||||
|
||||
1:
|
||||
040077;012000 " String literal " ?\n"
|
||||
dd:
|
||||
<dd>;040040;040040;040040
|
||||
<dd>;040040;040040;040040 " Filename dd
|
||||
d1: 1
|
||||
d4: 4
|
||||
d5: 5
|
||||
dm4: -4
|
||||
dm4: -4
|
||||
|
||||
+65
-58
@@ -1,81 +1,89 @@
|
||||
" cp
|
||||
" cp: cp file1 file2 [file3 file4 [file5 file6] ...]
|
||||
"
|
||||
" Copies in pairs: file1 to file2, file3 to file4 etc.
|
||||
|
||||
lac 017777 " Skip past argc and save
|
||||
tad d1 " argv[0] (our name) into name2
|
||||
dac name2 " We will skip past it later
|
||||
|
||||
lac 017777
|
||||
tad d1
|
||||
dac name2
|
||||
loop:
|
||||
lac 017777 i
|
||||
lac 017777 i " Any arguments left?
|
||||
sad d4
|
||||
sys exit
|
||||
sad d8
|
||||
jmp unbal
|
||||
tad dm8
|
||||
dac 017777 i
|
||||
lac name2
|
||||
sys exit " 4 words = no args left, exit
|
||||
sad d8 " Do we have 2 args?
|
||||
jmp unbal " No, an unbalanced set of arguments
|
||||
tad dm8 " Subtract 8 (two args) from the argc
|
||||
dac 017777 i " and save it
|
||||
lac name2
|
||||
tad d4
|
||||
dac name1
|
||||
dac name1 " Skipping pairs of filenames? not sure
|
||||
tad d4
|
||||
dac name2
|
||||
sys open; name1: 0; 0
|
||||
sys open; name1: 0; 0 " Open the input file
|
||||
spa
|
||||
jmp error
|
||||
lac o17
|
||||
sys creat; name2: 0
|
||||
jmp error " File open error
|
||||
lac o17 " Why load 15 (017) into AC?
|
||||
sys creat; name2: 0 " Create the output file
|
||||
spa
|
||||
jmp error
|
||||
dzm nin
|
||||
jmp error " File create error
|
||||
dzm nin " Set the number of input words to zero
|
||||
|
||||
1:
|
||||
lac bufp
|
||||
tad nin
|
||||
dac 0f
|
||||
lac bufp " Set up the base of the upcoming read
|
||||
tad nin " to be the buffer + nin so we skip
|
||||
dac 0f " the existing words in the buffer
|
||||
-1
|
||||
tad nin
|
||||
cma
|
||||
tad d1024
|
||||
tad nin " Calculate 1024 - nin, i.e. the number
|
||||
cma " of empty words yet to be filled in the
|
||||
tad d1024 " buffer, and use it as the read count
|
||||
dac 0f+1
|
||||
lac d2
|
||||
lac d2 " Read from fd 2: hard-wired in fd!
|
||||
sys read; 0:..;..
|
||||
sna
|
||||
jmp 2f
|
||||
tad nin
|
||||
dac nin
|
||||
jmp 2f " No words were read in, go to 2f
|
||||
tad nin " Add the number of words read in
|
||||
dac nin " to the existing number of words
|
||||
sad d1024
|
||||
jmp 2f
|
||||
jmp 1b
|
||||
jmp 2f " We do have 1,024 words, go to 2f
|
||||
jmp 1b " Loop back if we don't have 1,024 words
|
||||
|
||||
2:
|
||||
lac nin
|
||||
dac 2f
|
||||
lac d3
|
||||
sys write; buf; 2: 0
|
||||
dzm nin
|
||||
lac 2b
|
||||
sad d1024
|
||||
jmp 1b
|
||||
lac d2
|
||||
sys close
|
||||
lac nin " Load the number of words in the input buffer
|
||||
dac 2f " Save in the write word count argument
|
||||
lac d3 " Write to fd 3: hard-wired out fd!
|
||||
sys write; buf; 2:0
|
||||
dzm nin " Set nin back to zero
|
||||
lac 2b " Get the write count (updated by sys write)
|
||||
sad d1024 " Did we write the buffer out?
|
||||
jmp 1b " Yes, we wrote 1,024 words, so loop back
|
||||
" to read another buffer's worth
|
||||
lac d2
|
||||
sys close " Close fd 2 and fd 3
|
||||
lac d3
|
||||
sys close
|
||||
jmp loop
|
||||
error:
|
||||
lac name1
|
||||
jmp loop " Loop back to deal with the next arguments
|
||||
|
||||
error: " File error, print out the name1 on
|
||||
lac name1 " standard output, fd 1 followed by " ?\n"
|
||||
dac 1f
|
||||
lac d1
|
||||
sys write; 1: 0; 4
|
||||
lac d1
|
||||
sys write; 1:0; 4
|
||||
lac d1
|
||||
sys write; mes; 1
|
||||
lac name2
|
||||
lac name2 " Then do the same with name 2
|
||||
dac 1f
|
||||
lac d1
|
||||
sys write; 1: 0; 4
|
||||
lac d1
|
||||
sys write; mes; 2
|
||||
jmp loop
|
||||
jmp loop " Loop back to deal with the next arguments
|
||||
|
||||
mes:
|
||||
040000;077012
|
||||
unbal:
|
||||
lac name2
|
||||
tad d4
|
||||
040000;077012 " String literal: " ?\n"
|
||||
|
||||
unbal: " We had an unbalanced set of arguments
|
||||
lac name2 " so print out the name after name2
|
||||
tad d4 " on standard output followed by " ?\n"
|
||||
dac 1f
|
||||
lac d1
|
||||
sys write; 1: 0; 4
|
||||
@@ -83,15 +91,14 @@ unbal:
|
||||
sys write; mes; 2
|
||||
sys exit
|
||||
|
||||
d1: 1
|
||||
d1: 1 " Numeric constants
|
||||
d2: 2
|
||||
d3: 3
|
||||
d4: 4
|
||||
d8: 8
|
||||
o17: 017
|
||||
dm8: -8
|
||||
d3: 3
|
||||
d1024: 1024
|
||||
nin: 0
|
||||
bufp: buf
|
||||
d2: 2
|
||||
|
||||
buf:
|
||||
nin: 0 " Number of words in the input buffer
|
||||
bufp: buf " Pointer to the buffer
|
||||
buf: .=.+1024 " Buffer of 1,024 words
|
||||
|
||||
Reference in New Issue
Block a user