From 575163a35ad5d0303e6eb02e8979702c0498f937 Mon Sep 17 00:00:00 2001 From: Warren Toomey Date: Fri, 4 Mar 2016 14:34:25 +1000 Subject: [PATCH] I wrote a test for the octal conversion routine, and I updated ds.s with the comments that I wrote for the octal conversion. --- src/cmd/ds.s | 40 +++++++++++++++++++----------------- src/other/octal_test.s | 46 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 19 deletions(-) create mode 100644 src/other/octal_test.s diff --git a/src/cmd/ds.s b/src/cmd/ds.s index d26d0e4..fa18890 100644 --- a/src/cmd/ds.s +++ b/src/cmd/ds.s @@ -363,28 +363,30 @@ putname: 0 jmp putname i octal: 0 - lmq - lac d5 - tad octal i - cma - dac c + lmq " Move the negative argument into the MQ + " as we will use shifting to deal with the + " number by shifting groups of 3 digits. + lac d5 " By adding 5 to the negative count and + tad octal i " complementing it, we set the actual + cma " loop count up to 6 - count. So, if we + dac c " want to print 2 digits, we lose 6 - 2 = 4 digits 1: - llss 3 - isz c - jmp 1b - lac octal i - dac c + llss 3 " Lose top 3 bits of the MQ + isz c " Do we have any more to lose? + jmp 1b " Yes, keep looping + lac octal i " Save the actual number of print digits into c + dac c " as a negative number. 1: - " ecla llss 3 - llss 3 - tad o60 + cla + llss 3 " Shift 3 more bits into AC + tad o60 " Add AC to ASCII '0' + jms putc " and print out the digit + isz c " Any more characters to print out? + jmp 1b " Yes, loop back + law 040 " Print out a space jms putc - isz c - jmp 1b - law 040 - jms putc - isz octal - jmp octal i + isz octal " Move return address 1 past the argument + jmp octal i " and return from subroutine error: 0 -1 diff --git a/src/other/octal_test.s b/src/other/octal_test.s new file mode 100644 index 0000000..7fa9c25 --- /dev/null +++ b/src/other/octal_test.s @@ -0,0 +1,46 @@ +" Octal test: This code borrowed from ds.s to test the llss +" instruction. It should print out num in octal followed by +" a space. + + lac num + jms octal; -3 + sys exit + +octal: 0 + lmq " Move the negative argument into the MQ + " as we will use shifting to deal with the + " number by shifting groups of 3 digits. + + lac d5 " By adding 5 to the negative count and + tad octal i " complementing it, we set the actual + cma " loop count up to 6 - count. So, if we + dac c " want to print 2 digits, we lose 6 - 2 = 4 digits +1: + llss 3 " Lose top 3 bits of the MQ + isz c " Do we have any more to lose? + jmp 1b " Yes, keep looping + lac octal i " Save the actual number of print digits into c + dac c " as a negative number. +1: + cla + llss 3 " Shift 3 more bits into AC + tad o60 " Add AC to ASCII '0' + dac buf " and print out the digit + lac fd1 + sys write; buf; 1 + isz c " Any more characters to print out? + jmp 1b " Yes, loop back + lac o40 " Print out a space + dac buf + lac fd1 + sys write; buf; 1 + isz octal " Move return address 1 past the argument + jmp octal i " and return from subroutine + +fd1: 1 +d5: 5 +o40: 040 +o60: 060 +num: 0126 +buf: 0 +c: .=.+1