From 42c7a240ed6314c168984ea015261ee332b425b3 Mon Sep 17 00:00:00 2001 From: Warren Toomey Date: Wed, 23 Mar 2016 11:14:01 +1000 Subject: [PATCH] I wrote a version of od. --- build/Makefile | 7 ++- build/proto | 1 + src/other/wktod.s | 109 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 src/other/wktod.s diff --git a/build/Makefile b/build/Makefile index ff1b392..bf120e0 100644 --- a/build/Makefile +++ b/build/Makefile @@ -141,11 +141,11 @@ $(BINDIR)/altmkdir: $(ALTSRC)/wktmkdir.s # The commands that did not come from the scans others: dirs $(BINDIR)/sh $(BINDIR)/wktcat $(BINDIR)/wktcp $(BINDIR)/date \ - $(BINDIR)/ln $(BINDIR)/ls $(BINDIR)/mv $(BINDIR)/stat + $(BINDIR)/ln $(BINDIR)/ls $(BINDIR)/mv $(BINDIR)/stat $(BINDIR)/od # Alternative other commands: no dd, but . and .. altothers: dirs $(BINDIR)/sh $(BINDIR)/wktcat $(BINDIR)/wktcp $(BINDIR)/date \ - $(BINDIR)/ln $(BINDIR)/altls $(BINDIR)/mv $(BINDIR)/stat + $(BINDIR)/ln $(BINDIR)/altls $(BINDIR)/mv $(BINDIR)/stat $(BINDIR)/od $(BINDIR)/sh: $(OTHERSRC)/pbsh.s @@ -175,6 +175,9 @@ $(BINDIR)/mv: $(OTHERSRC)/wktmv.s $(BINDIR)/stat: $(OTHERSRC)/wktstat.s $(AS) $(ASARGS) -o $(BINDIR)/stat $(OTHERSRC)/wktstat.s +$(BINDIR)/od: $(OTHERSRC)/wktod.s + $(AS) $(ASARGS) -o $(BINDIR)/od $(OTHERSRC)/wktod.s + tests: mkdir -p $(TESTDIR) $(AS) $(ASARGS) -o $(TESTDIR)/decimal_out $(TESTSRC)/decimal_out.s diff --git a/build/proto b/build/proto index 2892d88..ea2a82d 100644 --- a/build/proto +++ b/build/proto @@ -33,6 +33,7 @@ dd drwr- -1 4 init frwr- -1 bin/init ln frwr- -1 bin/ln ls frwr- -1 bin/ls + od frwr- -1 bin/od mv frwr- -1 bin/mv password frw-- -1 fs/password sh frwr- -1 bin/sh diff --git a/src/other/wktod.s b/src/other/wktod.s new file mode 100644 index 0000000..80c7f73 --- /dev/null +++ b/src/other/wktod.s @@ -0,0 +1,109 @@ +" Warren's version of od: od filename +" + +main: + lac 017777 i " Do we have any arguments? + sad d4 + jmp noarg " No, an error + + lac 017777 " Move five words past the argument word count + tad d5 " so that AC points at the first argument + dac argptr + + sys open; argptr:0; 0 " Open up the file, save the file descriptor + spa + jmp badfile + dac fd + +lineloop: + lac fd + sys read; buf; 8 " Read 8 words from the file + sna + sys exit " Nothing read, exit now + dac count + + lac offset " Print out the offset + jms octal; + lac fd1 + sys write; colon; 1 " Write colon space + lac ibufptr + dac bufptr " Start at the beginning of the buffer + + +printloop: + lac bufptr i " Print out the next word + jms octal; + lac fd1 + sys write; space; 1 " Write a space + -1 + tad count " Decrement the count + dac count + sna + jmp endofline " Nothing left to print + isz bufptr + jmp printloop + + +endofline: + lac fd1 + sys write; newline; 1 " Write a space + lac d8 + tad offset " Bump up the offset + dac offset + jmp lineloop + + + + + +octal: 0 + lmq " Move the argument into MQ + -6 + dac c " Set the loop count to 6 +1: + cla + llss 3 " Shift 3 more bits into AC + tad o60 " Add AC to ASCII '0' + dac cbuf " and print out the digit + lac fd1 + sys write; cbuf; 1 + isz c " Any more characters to print out? + jmp 1b " Yes, loop back + jmp octal i " and return from subroutine + + +noarg: + " Print a "no arg" error and exit + lac d1 + sys write; noargstr; 4 + sys exit +noargstr: ; < a>; ; 012 + +badfile: + lac argptr " Get the pointer to the argument + dac 1f " Store it in 1f below + lac d1 + sys write; 1:0; 4 " Write the name, max 4 words + lac d1 " Then write " ?\n" + sys write; 1f; 2 + sys exit " and exit +1: 040; 077012 " String literal: " ?\n" + +ibufptr: buf +bufptr: buf +buf: .=.+8 " Buffer of eight words +count: 0 " Count of words read in +offset: 0 " Offset from the beginning of file +cbuf: 0 " Used to print out in the octal routing +c: .=.+1 " Loop counter for printing octal digits +fd: 0 + +fd1: d1: 1 +d4: 4 +d5: 5 +d8: 8 +o60: 060 + +colon: 072040 " Colon space string +space: 040 " Space string +newline: 012 " Newline string