resolved conflict

This commit is contained in:
Will Senn
2016-03-01 10:18:55 -06:00
19 changed files with 1583 additions and 869 deletions
+483 -441
View File
File diff suppressed because it is too large Load Diff
+66 -64
View File
@@ -10,17 +10,17 @@
dac name
loop:
sys open; name:0; 0; " Open file, get fd back
sys open; name:0; 0 " Open file, get fd back
spa
jmp badfile " Negative fd, exit with an error message
dac fi " save file descriptor in fi
dac fi " Save file descriptor in fi
1:
jms getc " get a character in AC
jms getc " Get a character in AC
sad o4
jmp 1f
jms putc " write the character on stdout
jmp 1b
jmp 1f " Break the loop when we get a ctrl-D
jms putc " Write the character on stdout
jmp 1b " and loop back
1:
lac fi " Close the file descriptor in fi
@@ -57,93 +57,95 @@ nofiles:
1: <no>; 040; <fi>;<le>;<s 012
done:
lac noc
lac noc " Is the number of characters left zero?
sna
sys exit
sys exit " Yes, exit
and d1
sna cla
jmp 1f
jms putc
jmp done
jms putc " Store the character in the buffer
jmp done " and loop back
1:
lac noc
rcr
dac 1f
lac noc " Get the number of characters in the buffer
rcr " Divide by two to convert to words
dac 1f " Save in the write's word count below
lac fo " Load fd 1, stdout
sys write; iopt+1; 1
sys write; iopt+1; 1:.. " Write the leftover buffer and exit
sys exit
getc: 0
lac ipt
lac ipt " Load the pointer to the next word in the buffer
sad eipt
jmp 1f
dac 2f
add o400000
jmp 1f " We've reached the end of the buffer, so read more
dac 2f " Save the pointer
add o400000 " Flip the msb and save into ipt
dac ipt
ral
lac 2f i
szl
lrss 9
and o177 " keep the lowest 7 bits
ral " Move the msb into the link register
lac 2f i " Load the word from the buffer
szl " Skip if this is the second character in the word
lrss 9 " It's the first char, shift down the top character
and o177 " Keep the lowest 7 bits
sna
jmp getc+1
jmp getc i " return from subroutine
jmp getc+1 " Skip a NUL characters and read another one
jmp getc i " Return the character from the subroutine
1:
lac fi
lac fi " Buffer is empty, read another 64 characters
sys read; iipt+1; 64
sna
jmp 1f
tad iipt
dac eipt
lac iipt
jmp 1f " No characters were read in
tad iipt " Add the word count to the base of the buffer
dac eipt " and store in the end buffer pointer
lac iipt " Reset the ipt to the base of the buffer
dac ipt
jmp getc+1
jmp getc+1 " and loop back to get one character
1:
lac o4
lac o4 " No character, return with ctrl-D
jmp getc i " return from subroutine
putc: 0
and o177 " keep the lowest 7 bits
and o177 " Keep the lowest 7 bits and save into 2f+1
dac 2f+1
lac opt
dac 2f
add o400000
dac opt
spa
jmp 1f
lac 2f i
lac opt " Save the pointer to the empty buffer
dac 2f " position to 2f
add o400000 " Flip the msb and save back into opt
dac opt " This also has the effect of incrementing
" the opt pointer every second addition!
spa " If the bit was set, we already have one
jmp 1f " character at 2f+1. If no previous character,
lac 2f i " merge the old and new character together
xor 2f+1
jmp 3f
jmp 3f " and go to the "save it in buffer" code
1:
lac 2f+1
lac 2f+1 " Move the character up into the top half
alss 9
3:
dac 2f i
isz noc
lac noc
dac 2f i " Save the word into the buffer
isz noc " Add 1 to the char count, never skipping
lac noc " Have we reached 128 characters, 64 words?
sad d128
skp
jmp putc i
lac fo " load fd 1, stdout
sys write; iopt+1; 64
jmp putc i " No, so return (more room still in the buffer)
lac fo " Load fd1 (i.e stdout)
sys write; iopt+1; 64 " and write out the 64 words in the buffer
lac iopt
dac opt
dzm noc
jmp putc i
dac opt " Set opt pointing back to base of buffer
dzm noc " Set the number of chars in the buffer to 0
jmp putc i " and return
2: 0;0
ipt: 0
eipt: 0
iipt: .+1; .=.+64 " 64 word input buffer
fi: 0
opt: .+2
iopt: .+1; .=.+64 " 64 word output buffer
noc: 0
fo: 1 " output file descriptor, fd 1 is stdout
2: 0;0 " Current input and output word pointers
ipt: 0 " Current input buffer base
eipt: 0 " Pointer to end of data read in input buffer
iipt: .+1; .=.+64 " 64 word input buffer and pointer to it
fi: 0 " Input file descriptor
opt: .+2 " Current output buffer base
iopt: .+1; .=.+64 " 64 word output buffer and pointer to it
noc: 0 " Number of output characters
fo: 1 " Output file descriptor, fd 1 is stdout
d1: 1 " octal and decimal constants
d1: 1 " Octal and decimal constants
o4:d4: 4
d8: 8
o400000: 0400000
o177: 0177
d128: 128
o400000: 0400000 " Msb toggle bit
o177: 0177 " ASCII mask
d128: 128 " 128 words in the output buffer
+2
View File
@@ -1,3 +1,4 @@
/* ** 08-rest.pdf page 4 */
main $(
auto ch;
extrn read, write;
@@ -8,6 +9,7 @@ main $(
ch = ch + 040;
if (ch==015) goto loop;
if (ch==014) goto loop;
/* -->------------------------> if (ch == 0177) goto loop; */
if (ch==011)
$( ch = 040040;
write(040040);
+105
View File
@@ -0,0 +1,105 @@
" Warren's cat program: cat [arg1 arg2 ...]
main:
" Load the pointer pointer in 017777 to see if we have any arguments
lac 017777 i
sad d4 " Skip if we have more than four argument words
jmp stdinout " Only four argument words, so no arguments
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
catfiles:
" 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;
spa
jmp badfile " Negative fd, exit with an error message
dac fd " Save the file descriptor
fileloop:
" Read 64 words into the buffer from the input file
lac fd
sys read; buf; 64
spa " Skip if result was >= 0
jmp error " Result was -ve, so error result
sna " Skip if result was >0
jmp fileend " 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 fileloop
fileend:
" Close the open file descriptor
lac fd
sys close
" Subtract 4 from the count of argument words
-4
tad 017777 i
dac 017777 i
sad d4 " Is the value 4, i.e. no args left?
jmp end " Yes, so exit
" Still an argument, so move up to the next filename argument
lac name
tad d4
dac name
jmp catfiles " and loop back to cat this file
end:
" exit
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:
lac d8
dac 017777 i " Save 8 into the word count
lac d0
dac fd " Save file descriptor 0
jmp fileloop
" This code comes from the real cat.s
badfile:
lac name " Get the pointer to the filename
dac 1f " Store it in 1f below
lac d8 " Load fd 8 which is stderr
sys write; 1:0; 4 " Write the name, max 4 words
lac d8 " Then write " ?\n"
sys write; 1f; 2
sys exit " and exit
1: 040; 077012 " String literal: " ?\n"
error:
" Print an "err read" string on stderr and exit
lac d8
sys write; noreadstr; 5
sys exit
noreadstr:
<er>;<r 040;<re>;<ad>;012000
fd: 0 " fd of the open file
d0: 0 " Constants 0, 1, 4 and 8
d1: 1
d4: 4
d8: 8 " stderr seems to have fd 8
minus4: 0777774 " Constant -4
" Input buffer for read
buf: .=.+64
+110
View File
@@ -0,0 +1,110 @@
" Warren's cp program: cp arg1 arg2
main:
" Load the pointer pointer in 017777 to see if we have any arguments
lac 017777 i
sad d12
jmp 1f " We have 12 words, so we have 2 arguments
jmp argserror " Otherwise, print an error and exit
1: lac 017777 " Move five words past the argument word count
tad d5 " so that AC points at the first argument
" Save the pointer to the file name
dac name
" Open the input file and get the fd into AC
sys open; name:0; 0;
spa
jmp badfile " Negative fd, exit with an error message
dac infd " Save the file descriptor
lac 017777 " Move nine words past the argument word count
tad d9 " so that AC points at the second argument
dac name
dac name2
" Open the ouput file and get the fd into AC
sys open; name2:0; 1;
spa
jmp badfile " Negative fd, exit with an error message
dac outfd " Save the file descriptor
fileloop:
" Read 64 words into the buffer from the input file
lac infd
sys read; buf; 64
spa " Skip if result was >= 0
jmp readerror " Result was -ve, so error result
sna " Skip if result was >0
jmp fileend " Result was zero, so nothing left to read
" Save the count of words read in
dac 1f
" Write five words from the buffer to the output file
lac outfd
sys write; buf; 1:0
spa " Skip if result was >= 0
jmp writeerror " Result was -ve, so error result
" and loop back for more words to read
jmp fileloop
fileend:
" Close the open file descriptors
lac infd
sys close
lac outfd
sys close
sys exit
" This code comes from the real cat.s
badfile:
lac name " Get the pointer to the filename
dac 1f " Store it in 1f below
lac d8 " Load fd 8 which is stderr
sys write; 1:0; 4 " Write the name, max 4 words
lac d8 " Then write " ?\n"
sys write; 1f; 2
sys exit " and exit
1: 040; 077012 " String literal: " ?\n"
readerror:
" Print an "err read" string on stderr and exit
lac d8
sys write; noreadstr; 5
sys exit
noreadstr:
<er>;<r 040;<re>;<ad>;012000
writeerror:
" Print an "err write" string on stderr and exit
lac d8
sys write; nowritestr; 6
sys exit
nowritestr:
<er>;<r 040;<wr>;<it>;<e 012
argserror:
" Print an "bad args" string on stderr and exit
lac d8
sys write; badargs; 5
sys exit
badargs:
<ba>;<d 040;<ar>;<gs>;012000
infd: 0 " fd of the input file
outfd: 0 " fd of the output file
d5: 5
d9: 9
d8: 8 " stderr seems to have fd 8
d12: 12
" Input buffer for read
buf: .=.+64
+61
View File
@@ -0,0 +1,61 @@
" Test program for several system calls: open, read, write, close, exit
" Do:
" ./as7 write_test.s > a.out
" ./a7out -d a.out
main:
" Test the lac, dac instructions
lac in
dac out
" Write hello to fd1 i.e stdout
lac d1
sys write; hello; 7
" Test if the assembler can dac into a mid-line label
lac helloptr
dac 1f
lac d1
sys write; 1:0; 7
" Try to open file fred
sys open; fred; 0;
" read 5 words into the buffer from stdin: type in 10 or more characters!
lac d0
sys read; buf; 5
" Stop and dump memory, so you can see five words at location 0400
" Comment out the hlt instruction to test close and exit
hlt
" close stdin
lac d0
sys close
" exit
sys exit
" We should not get to the halt instruction
hlt
" Some memory locations for lac and dac
. = 0100
in: 023
. = 0200
out: 0
" Hello, world\n, two ASCII chars per word
hello: <He>; <l 0154; 0157 ,>; 040; <wo>; <rl>; <d 012
helloptr: hello
" fred as a four word filename
fred: <fr>; <ed>; 040040; 040040
" Input buffer for read
. = 0400
buf: 0
d0: 0
d1: 1
+43 -43
View File
@@ -21,61 +21,61 @@ orig:
jmp 1f+1
1f
1: 0
iof
dac u.ac
iof " interrupts off
dac u.ac " save user AC
lacq
dac u.mq
dac u.mq " save user MQ
lac 8
dac u.rq
dac u.rq " save user auto-index location 8
lac 9
dac u.rq+1
jms copy; 10; u.rq+2; 6
lac 1b
dac u.rq+8
dac u.rq+1 " save user auto-index location 9
jms copy; 10; u.rq+2; 6 " save user auto-index locations 10-15
lac 1b " load user PC after system call
dac u.rq+8 " save user PC
-1 " load -1
dac .savblk " set "save" flag (cleared by disk I/O?)
dac .insys " set "in system" flag
lac uquant " load user quantum count
jms betwen; d0; maxquant " check if between 0 & maxquant??
jms swap " no: swap processes
ion " interrupts on
-1
dac .savblk
dac .insys
lac uquant
jms betwen; d0; maxquant
jms swap
ion
-1
tad u.rq+8
jms laci
jms betwen; o20001; swn
jmp badcal
tad swp
dac .+1
jmp .. i
tad u.rq+8 " get address of system call
jms laci " load AC indirect??
jms betwen; o20001; swn " range check
jmp badcal " bad system call
tad swp " add system call table base
dac .+1 " save as next instruction
jmp .. i " dispatch system call
. = orig+0100
jmp coldentry
jms halt
okexit:
dzm: u.ac
sysexit:
ion
lac .savblk
sza
jmp 1f
jms copy; sysdata; dskbuf; 64
dzm u.ac " 'OK' system call exit: clear user AC
sysexit: " common system call exit code
ion " enable interrupts
lac .savblk " load "save" flag
sza " is zero (cleared by disk I/O)?
jmp 1f " no: no disk I/O done?
jms copy; sysdata; dskbuf; 64 " copy system data to disk buffer
cla
jms dskio; 07000
jms dskio; 07000 " save to disk?
1:
dzm .insys
dzm .insys " clear "in system call" flag
jms chkint
skp
jmp .save
jms copy; u.rq+2; 10; 6
lac u.rq+1
jmp .save " dump core??
jms copy; u.rq+2; 10; 6 " restore auto-index locations 10-15
lac u.rq+1 " restore auto-index location 9
dac 9
lac u.rq
lac u.rq " restore auto-index location 8
dac 8
lac u.rq
lac u.mq " restore MQ register
lmq
lac u.ac
jmp u.rq+8 i
lac u.ac " restore AC register
jmp u.rq+8 i " return to user
swap: 0
ion
@@ -129,21 +129,21 @@ swap: 0
jmp swap i
t = t+1
swp:
jmp .
swp: " system call dispatch table
jmp . " base instruction
.save; .getuid; .open; .read; .write; .creat; .seek; .tell
.close; .link; .unlink; .setuid; .rename; .exit; .time; .intrp
.chdir; .chmod; .chown; badcal; .sysloc; badcal; .capt; .rele
.status; badcal; .smes; .rmes; .fork
swn:
.-swp-1 i
.-swp-1 i " count of system calls, plus indirect!
.intrp:
lac u.ac
dac u.intflg
jmp okexit
.sysloc:
.sysloc: " "sysloc": syscall to return system addresses
lac u.ac
and o17777
jms betwen; d1; locn
@@ -154,7 +154,7 @@ swn:
dac u.ac
jmp sysexit
locsw:
locsw: " table of system data structures for "sysloc" call
lac .
iget; inode; userdata; sysdata; copy; copyz; betwen; dskrd
dskwr; dskbuf; dpdata; namei; pbsflgs; alloc; free; dspdata
+15 -12
View File
@@ -53,9 +53,9 @@
jms iput
jmp okexit
.getuid:
.getuid: " getuid system call
lac u.uid
dac u.ac
dac u.ac " return u.uid in user AC
jmp sysexit
.seek:
@@ -146,12 +146,12 @@
jms iput
jmp sysexit
.setuid:
lac u.uid
sma
jms error
lac u.ac
dac u.uid
.setuid: " setuid system call
lac u.uid " load current user id
sma " negative?
jms error " no: error!!
lac u.ac " load user AC
dac u.uid " save as new uid
jmp sysexit
.rename:
@@ -168,11 +168,14 @@
jms copy; 1:0; d.name; 4
jmp okexit
" time system call returns line (mains) frequency ticks since boot?
" note: returns uptime!?
" at 60Hz, 36 bits would last 36+ years!
.time:
lac s.tim
dac u.ac
lac s.tim+1
dac u.mq
lac s.tim " load high order bits
dac u.ac " return in AC
lac s.tim+1 " load low order bits
dac u.mq " return in MQ
jmp sysexit
.chdir:
+9 -9
View File
@@ -1,7 +1,7 @@
"** 01-s1.pdf page 41
" s7
pibreak:
pibreak: " priority interrupt processing "chain"
dac .ac "** CROSSED OUT....
dpsf
@@ -25,15 +25,15 @@ pibreak:
dac dpwrite
jmp piret "** END OF CROSSOUT
1: clsf
jmp 1f
1: clsf " clock overflow (line frequency ticks)?
jmp 1f " no
lpb
dac pbsflgs
isz s.tim+1
skp
isz s.tim
isz uquant
lpb " load display push buttons
dac pbsflgs " save
isz s.tim+1 " increment low order tick count
skp " no overflow, skip second increment
isz s.tim " low order overflowed, increment high order count
isz uquant " increment user quantum counter
"** written: ttydelay -> ttyd1
"** written: ttyrestart -> ttyres1
cnop:
+89 -91
View File
@@ -1,97 +1,95 @@
"** 01-s1.pdf page 62
" sop
dac = 0040000
jms = 0100000
dzm = 0140000
lac = 0200000
xor = 0240000
add = 0300000
tad = 0340000
xct = 0400000
isz = 0440000
and = 0500000
sad = 0540000
jmp = 0600000
nop = 0740000
i = 020000
law = 0760000
cma = 0740001
las = 0750004
ral = 0740010
rar = 0740020
hlt = 0740040
sma = 0740100
sza = 0740200
snl = 0740400
skp = 0741000
sna = 0741200
szl = 0741400
rtl = 0742010
rtr = 0742020
cil = 0744000
rcl = 0744010
rcr = 0744020
cia = 0750000
lrs = 0640500
lrss = 0660500
lls = 0640600
llss = 0660600
als = 0640700
alss = 0660700
mul = 0653323
idiv = 0653323
lacq = 0641002
clq = 0650000
omq = 0650002
cmq = 0650004
lmq = 0652000
dac = 0040000 " MEM: deposit AC
jms = 0100000 " MEM: jump to subroutine
dzm = 0140000 " MEM: deposit zero to memory
lac = 0200000 " MEM: load AC
xor = 0240000 " MEM: XOR with AC
add = 0300000 " MEM: one's complement add
tad = 0340000 " MEM: two's complement add
xct = 0400000 " MEM: execute
isz = 0440000 " MEM: increment and skip if zero
and = 0500000 " MEM: AND
sad = 0540000 " MEM: skip if AC different
jmp = 0600000 " MEM: jump
nop = 0740000 " OPR: no-op
i = 020000 " indirect
law = 0760000 " OPR: load accumulator with (instr)
cma = 0740001 " OPR: complement AC
las = 0750004 " OPR: load AC from switches
ral = 0740010 " OPR: rotate AC left
rar = 0740020 " OPR: rotate AC right
hlt = 0740040 " OPR: halt
sma = 0740100 " OPR: skip on minus AC
sza = 0740200 " OPR: skip on zero AC
snl = 0740400 " OPR: skip on non-zero link
skp = 0741000 " OPR: skip unconditionally
sna = 0741200 " OPR: skip on non-zero AC
szl = 0741400 " OPR: skip on zero link
rtl = 0742010 " OPR: rotate two left
rtr = 0742020 " OPR: rotate two right
cll = 0744000 " OPR: clear link
rcl = 0744010 " OPR: clear link, rotate left
rcr = 0744020 " OPR: clear link, rotate right
cla = 0750000 " OPR: clear AC
lrs = 0640500 " EAE: long right shift
lrss = 0660500 " EAE: long right shift, signed
lls = 0640600 " EAE: long left shift
llss = 0660600 " EAE: long left shift, signed
als = 0640700 " EAE: AC left shift
alss = 0660700 " EAE: AC left shift, signed
mul = 0653323 " EAE: multiply
idiv = 0653323 " EAE: integer divide
lacq = 0641002 " EAE: load AC with MQ
clq = 0650000 " EAE: clear MQ
omq = 0650002 " EAE: OR MQ into AC
cmq = 0650004 " EAE: complement MQ
lmq = 0652000 " EAE: load MQ from AC
dscs = 0707141
dslw = 0707124
dslm = 0707142
dsld = 0707104
dsls = 0707144
dssf = 0707121
dsrs = 0707132
iof = 0700002
ion = 0700042
caf = 0703302
clon = 0700044
clsf = 0700001
dscs = 0707141 " DSK: clear status register
dslw = 0707124 " DSK: clear and load WC from AC
dslm = 0707142 " DSK: clear and load MAC from AC
dsld = 0707104 " DSK: clear and load TA and SA from AC
dsls = 0707144 " DSK: load status
dssf = 0707121 " DSK: skip on flags
dsrs = 0707132 " DSK: read status register
iof = 0700002 " PIC: interrupts off
ion = 0700042 " PIC: interrupts on
caf = 0703302 " CPU: clear all flags
clon = 0700044 " CLK: clear flag, enable
clsf = 0700001 " CLK: skip if overflow
"** 01-s1.pdf page 63
clof = 0700004
ksf = 0700301
krb = 0700312
tsf = 0700401
tcf = 0700402
tls = 0700406
sck = 0704301
cck = 0704304
lck = 0704312
rsf = 0700101
rsa = 0700104
rrb = 0700112
psf = 0700201
pcf = 0700202
psa = 0700204
cdf = 0700501
lds = 0701052
lda = 0701012
wcga = 0704206
raef = 0700742
rlpd = 0700723
beg = 0700547
spb = 0704401
cpb = 0704404
lpb = 0704412
wbl = 0704424
dprs = 0704752
dpsf = 0704741
dpcf = 0704761
dprc = 0704712
crsf = 0706701
crrb = 0706712
clof = 0700004 " CLK: clear flag, disable
ksf = 0700301 " KBD: skip if flag set
krb = 0700312 " KBD: read buffer
tsf = 0700401 " TTY: skip if flag set
tcf = 0700402 " TTY: clear flag
tls = 0700406 " TTY: load buffer, select
sck = 0704301 " S-2: skip on console keyboard
cck = 0704304 " S-2: clear console keyboard
lck = 0704312 " S-2: load console keyboard
rsf = 0700101 " PTR: skip if flag set
rsa = 0700104 " PTR: select alphanumeric mode
rrb = 0700112 " PTR: clear flag, or read buffer
psf = 0700201 " PTP: skip if flag set
pcf = 0700202 " PTP: clear flag
psa = 0700204 " PTP: alphanumeric mode
cdf = 0700501 " ???
lds = 0701052 " S-2: load display status
lda = 0701012 " S-2: load display address
wcga = 0704206 " S-2: ???
raef = 0700742 " S-2: resume after edges flag
rlpd = 0700723 " S-2: resume after light pen stop, disabled
beg = 0700547 " S-2: begin
spb = 0704401 " S-2: skip on push button flag
cpb = 0704404 " S-2: clear push button flag
lpb = 0704412 " S-2: load push buttons
wbl = 0704424 " S-2: write button lights
dprs = 0704752 " dataphone: read status
dpsf = 0704741 " dataphone: skip on flag
dpcf = 0704761 " dataphone: clear flag
dprc = 0704712 " dataphone: read character
crsf = 0706701 " CDR: skip if ready
crrb = 0706712 " CDR: read buffer