Home » CEEFAX disks » telesoftware5.adl » 30-01-88/T\OSB12

30-01-88/T\OSB12

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » CEEFAX disks » telesoftware5.adl
Filename: 30-01-88/T\OSB12
Read OK:
File size: 32DF bytes
Load address: 0000
Exec address: FFFFFFFF
File contents
OSBITS - An Exploration of the BBC Micro at Machine Level

By Programmer

...........................................................


Part 12: ASCII to Binary Conversion

I think we get so used to inputting numbers into a computer
that we can forget that they are not in the right format. 
The keys we press put the ASCII value of the particular
digit we type into the micro rather than the number itself.

Some sort of conversion program is needed to take a string
of ASCII characters that represent a number and convert them
into a binary number in memory on which the program can
work.

In the previous module we produced a routine that took
digits typed in at the keyboard, refusing to accept invalid
characters, and put the result into a small chunk of memory
called the input buffer.  That program returns in this
module as a subroutine in a larger program which will leave
us with a 4 byte number in work space in the computer
memory.

Once that number is in memory we can perform arithmetical
operations on it: add, subtract, multiply and divide.  Once
we have a result, that will be a binary number in memory and
to print it out we have to convert in the opposite
direction, binary to ASCII.

B/osb11 left us with a string in a buffer.  The first digit
of that string could be a number, or a minus sign.  I'll
leave the sign for a moment.  First let's look at the
problem of conversion.

As an example let's take a string that contains the
following characters:

                     1234

Remember that is a string of four characters, not a number
with the value 1234.  If we start at the left hand end we
find a '1'.  Now I know that under the Arabic numeral system
the actual value of that '1' depends on it's position, but
for ASCII to binary conversion we do not know, indeed do not
need to know, it's position directly.  If we look at the
next character in the string we find the '2' but more
important we now know that the '1' is in fact worth 10 so we
have a 'running total' of 12.  As we look at the next
position we find a '3' and we know that our '12' to the left
is in fact now worth 120 giving us a total of 123.  Finally
we find a '4', the figures to our left are now worth 1230
and so we have a total of 1234, which is what was blindingly
obvious in the first place!

Let's think of this in terms of a computer algorithm (a
recipe if you like) and that goes like this:

    Multiply the number 'so far' by 10
    Add the value of the digit currently being read to the
        number 'so far'
    Repeat loop until there are no more digits

When you start the number 'so far' is of course zero.  I
should perhaps call it the partial result or the accumulated
result.

This algorithm has an advantage in that it can readily be
adapted to read in numbers in bases other than 10.  In that
case it would read:

    Multiply the number 'so far' by the base
    Add the value of the digit currently being read to the
        number 'so far'
    Repeat until there are no more digits

There are a couple of unanswered questions here.  Just how
do you determine that there are no more digits?  The easiest
way is to continue until you hit a character that is not in
your character set.  In our case, for decimal input, we
continue until we hit a character that is not between zero
and nine.

What is the value of a digit?  That is easy for the numbers
0 to 9 because the ASCII codes for them are &30 to &39 or 48
to 57.  We just subtract 48 from the ASCII.

So we need to be able to multiply a number by the base in
order to carry out this input procedure.  The routine in
this module is in fact general enough to cope with any base
up to 255 (although sorting out the values of the characters
in that base might cause some problems) but for the time
being we'll use it to deal with decimal numbers.  The bases
you might want to use eventually are binary (2) octal (8)
decimal (10) and hexadecimal (16).

The largest number that can be held in 4 bytes using 2's
complement negative is 2147483647 positive or - 2147483648
negative which correspond to &7FFFFFFF and &80000000.  In
fact in this routine I have sacrificed the ability to enter
- 2147483648 itself in order to simplify the coding a
little.  The largest negative number is - 2147483647, but I
doubt if that will cause much wailing and gnashing of teeth.

So just how do we multiply in machine code?  Well
fortunately we can fall back on good old fashioned long
multiplication, which is absurdly simple in binary since you
have a very rudimentary multiplication table.

Let's multiply 11011 by 1011 (i.e. 27 by 11)

                11011
                    x
                 1011
            ---------
             11011000
               110110
                11011
            ---------
            100101001     which is  297

I hope you can see that for each set bit of the multiplier
(1101) there is a row in the space between the dotted lines. 
Just like decimal long multiplication the rows are offset to
the left corresponding to the 'power' of the bit the row
belongs to.  You should note also that you essentially only
need to know the one times table and that the adding up of
the partial products is more difficult for a mere human than
the multiplying that produces each partial product.

In machine code the 'difficult' adding is taken care of
easily using ADC.  So what about those partial products
being offset left .... well that's rotating isn't it?  So
how does it look as an algorithm?

We'll actually do this backwards so it looks more like

                    11011
                        x
                     1011
                ---------
                    11011
                   110110
                 11011000
                ---------
                100101001

but the result is the same.

Take the rightmost (least significant bit) of the multiplier
and if it is set add the multiplicand to the contents of the
partial product workspace (ppws) which is empty to start
with, if it is clear do nothing.

Rotate the multiplier right and the multiplicand left.

Repeat the two stages until the multiplier is zero.

In practice you rotate the multiplier first because you use
the carry flag to check whether a bit is set, so it looks
like this if both numbers and their product are less than a
byte in size:

                .loop
                LSR multiplier
                BCC no_add
                CLC
                LDA multiplicand
                ADC ppws
                STA ppws
                .no_add
                BEQ exit
                ASL multiplicand
                JMP loop


If your product is larger than a byte (as it was in our long
multiplication example above) then you simply have to add
zero (with carry) to the high byte, after you have added the
low bytes together.  Let's say that the partial product was
in ppws and ppws+1 and that you were adding in a value from
the accumulator.  It would look like this: 

                   CLC
                   ADC ppws
                   STA ppws
                   LDA #0
                   ADC ppws+1
                   STA ppws+1

Note that we don't clear the carry before the second
addition.

It is possible to hold the multiplier in the accumulator
(this is done in the program module) but if either
multiplier or multiplicand are greater than 255 then
multi-byte rotating and multi-byte addition must be used. 
Multi-byte addition I have already covered.  Multi-byte
rotating is straightforward enough.  Basically your first
rotation is either an ASL or an LSR because you do not want
to bring in the carry flag at first, but other rotations are
ROL or ROR so that you can use the carry flag to carry
between bytes.  Here is an example with some memory called
mem to mem+3 being rotated left, which multiplies its value
by two.

                    ASL mem
                    ROL mem+1
                    ROL mem+2
                    ROL mem+3

The multiplication in B/osb12 is a compromise in that the
multiplicand is 4 bytes long but the multiplier is a single
byte (usually 10).  I hope this will make the technique
clear, next time I will break from input and output of
numbers to give you a general multi-byte multiplication
routine which we can use later when we come on to numbers
with a decimal point.

Having discussed the techniques let's run through the
program in this module.  It is copiously annotated, which
makes it a bit long.  If you have a micro without second
processor or shadow screen you will have to go into mode 7
to run it although it is best displayed as a listing in mode
3.

In setting up B/osb12 I have decided not to enable the
assembly listing which is why line 190 goes to 2 instead of
3.  The final code takes up over 500 bytes and I have
reserved &250 bytes of memory in line 170.  To help testing
function key 2 inputs the largest positive and negative
numbers.

The changes to the input routine from last time are as
follows:

The buffer size is increased as 11 digit numbers, including
a minus sign, can be accepted.  A plus sign has been added
to the valid character list.  The zero flag is set on exit
if the string is of zero length.

The main body of the code, from line 260 to line 400, calls
two subroutines, subject to trapping ESCAPEs and zero length
strings (lines 370 and 380).  The subroutine starting at
'input_character' is essentially that from the last module.
The subroutine at 'convert_ASCII_to_binary' takes the string
in the input buffer and converts it into a 4 byte binary
number and leaves the result in 4 bytes of memory starting
at 'digit_ws'.

The conversion subroutine is at line 1550.  Note that the
workspace must be cleared before use.  I have been known to
forget to do this with silly results!  The sign flag is
cleared also.

We go through the string in the input buffer a character at
a time using X as a counter/index.  If a character is not
between 0 and 9 we branch to 'not_number'.  There, if we are
looking at the first character in the string we check for a
+ or a - sign and set the sign flag if it is a minus.  A +
is just ignored.  Any other character would cause an
'invalid number' error but this should not occur here as the
input routine filters other characters out.  A non numeric
character anywhere else in the string is counted as
terminating the string.  This terminator will usually be a
carriage return.

There were two possible ways of dealing with a negative
number.  I could turn the number negative after it
was entered or I could actually build up a negative number
during the number entry routine.  In the end I decided to
convert after entry, since this makes the code simpler and
has only the slight side effect of invalidating the largest
negative number (&80000000) as I mentioned before.  After
the string has been terminated, and the code reaches the
address 'exit_number_conversion' we check to see if the sign
flag is set.  If it is the number is negative and we simply
subtract it from zero (lines 2160 - 2280).

I have put the numerical base in memory as a variable to
make conversion of this routine to other bases more
straightforward.  You should try to convert to base 8, or
even 16, to check if you understand how it works and that I
have explained it clearly enough.  In each case, of course,
you will need different characters.  0-7 for octal and 0-9
A-F for hexadecimal.

To process a digit we first subtract the ASCII value of '0'
from it (48) and then call a subroutine at 'process_number'.
As the comment says we multiply the number held in digit_ws
(et al) by the base and add the new digit (held in
'accustore' temporarily) to produce a new partial result in
digit_ws.

Note line 2630.  Here is an error trap that catches any
number that sets the top bit (becomes negative) during this
addition.  If that happens the number has overflowed 4
bytes.  This is also done at line 3050.  I have given the
add and rotate error traps different messages so you can see
which operates when if you deliberately enter huge numbers. 
You might try deleting the traps and seeing what happens. 
The trap at line 3050 is a bit belt and braces since I am
not convinced it catches anything.

We save X to the stack because X is holding the current
offset down the input buffer and so we must not lose it.

The 'mult_by_base' subroutine uses 4 bytes at 'ppws' as
partial product workspace and holds the multiplier in the
accumulator most of the time.  If a number rotates to set
the top bit then we have another overflow situation and that
is trapped in line 3160.  Otherwise this section of code is
a straightforward multiplication where the multiplier is
only a byte in size and the multiplicand is 4 bytes in size.

I wanted to put the final result back in digit_ws so lines
3270 to 3340 copy it across there.  The BASIC routine
between line 3430 and 3460 enables you to check the results.

The next module will deal with multi-byte multiplication,
also called multiple precision multiplication, in a more
general way.
00000000  4f 53 42 49 54 53 20 2d  20 41 6e 20 45 78 70 6c  |OSBITS - An Expl|
00000010  6f 72 61 74 69 6f 6e 20  6f 66 20 74 68 65 20 42  |oration of the B|
00000020  42 43 20 4d 69 63 72 6f  20 61 74 20 4d 61 63 68  |BC Micro at Mach|
00000030  69 6e 65 20 4c 65 76 65  6c 0d 0d 42 79 20 50 72  |ine Level..By Pr|
00000040  6f 67 72 61 6d 6d 65 72  0d 0d 2e 2e 2e 2e 2e 2e  |ogrammer........|
00000050  2e 2e 2e 2e 2e 2e 2e 2e  2e 2e 2e 2e 2e 2e 2e 2e  |................|
*
00000080  2e 2e 2e 2e 2e 0d 0d 0d  50 61 72 74 20 31 32 3a  |........Part 12:|
00000090  20 41 53 43 49 49 20 74  6f 20 42 69 6e 61 72 79  | ASCII to Binary|
000000a0  20 43 6f 6e 76 65 72 73  69 6f 6e 0d 0d 49 20 74  | Conversion..I t|
000000b0  68 69 6e 6b 20 77 65 20  67 65 74 20 73 6f 20 75  |hink we get so u|
000000c0  73 65 64 20 74 6f 20 69  6e 70 75 74 74 69 6e 67  |sed to inputting|
000000d0  20 6e 75 6d 62 65 72 73  20 69 6e 74 6f 20 61 20  | numbers into a |
000000e0  63 6f 6d 70 75 74 65 72  0d 74 68 61 74 20 77 65  |computer.that we|
000000f0  20 63 61 6e 20 66 6f 72  67 65 74 20 74 68 61 74  | can forget that|
00000100  20 74 68 65 79 20 61 72  65 20 6e 6f 74 20 69 6e  | they are not in|
00000110  20 74 68 65 20 72 69 67  68 74 20 66 6f 72 6d 61  | the right forma|
00000120  74 2e 20 0d 54 68 65 20  6b 65 79 73 20 77 65 20  |t. .The keys we |
00000130  70 72 65 73 73 20 70 75  74 20 74 68 65 20 41 53  |press put the AS|
00000140  43 49 49 20 76 61 6c 75  65 20 6f 66 20 74 68 65  |CII value of the|
00000150  20 70 61 72 74 69 63 75  6c 61 72 0d 64 69 67 69  | particular.digi|
00000160  74 20 77 65 20 74 79 70  65 20 69 6e 74 6f 20 74  |t we type into t|
00000170  68 65 20 6d 69 63 72 6f  20 72 61 74 68 65 72 20  |he micro rather |
00000180  74 68 61 6e 20 74 68 65  20 6e 75 6d 62 65 72 20  |than the number |
00000190  69 74 73 65 6c 66 2e 0d  0d 53 6f 6d 65 20 73 6f  |itself...Some so|
000001a0  72 74 20 6f 66 20 63 6f  6e 76 65 72 73 69 6f 6e  |rt of conversion|
000001b0  20 70 72 6f 67 72 61 6d  20 69 73 20 6e 65 65 64  | program is need|
000001c0  65 64 20 74 6f 20 74 61  6b 65 20 61 20 73 74 72  |ed to take a str|
000001d0  69 6e 67 0d 6f 66 20 41  53 43 49 49 20 63 68 61  |ing.of ASCII cha|
000001e0  72 61 63 74 65 72 73 20  74 68 61 74 20 72 65 70  |racters that rep|
000001f0  72 65 73 65 6e 74 20 61  20 6e 75 6d 62 65 72 20  |resent a number |
00000200  61 6e 64 20 63 6f 6e 76  65 72 74 20 74 68 65 6d  |and convert them|
00000210  0d 69 6e 74 6f 20 61 20  62 69 6e 61 72 79 20 6e  |.into a binary n|
00000220  75 6d 62 65 72 20 69 6e  20 6d 65 6d 6f 72 79 20  |umber in memory |
00000230  6f 6e 20 77 68 69 63 68  20 74 68 65 20 70 72 6f  |on which the pro|
00000240  67 72 61 6d 20 63 61 6e  0d 77 6f 72 6b 2e 0d 0d  |gram can.work...|
00000250  49 6e 20 74 68 65 20 70  72 65 76 69 6f 75 73 20  |In the previous |
00000260  6d 6f 64 75 6c 65 20 77  65 20 70 72 6f 64 75 63  |module we produc|
00000270  65 64 20 61 20 72 6f 75  74 69 6e 65 20 74 68 61  |ed a routine tha|
00000280  74 20 74 6f 6f 6b 0d 64  69 67 69 74 73 20 74 79  |t took.digits ty|
00000290  70 65 64 20 69 6e 20 61  74 20 74 68 65 20 6b 65  |ped in at the ke|
000002a0  79 62 6f 61 72 64 2c 20  72 65 66 75 73 69 6e 67  |yboard, refusing|
000002b0  20 74 6f 20 61 63 63 65  70 74 20 69 6e 76 61 6c  | to accept inval|
000002c0  69 64 0d 63 68 61 72 61  63 74 65 72 73 2c 20 61  |id.characters, a|
000002d0  6e 64 20 70 75 74 20 74  68 65 20 72 65 73 75 6c  |nd put the resul|
000002e0  74 20 69 6e 74 6f 20 61  20 73 6d 61 6c 6c 20 63  |t into a small c|
000002f0  68 75 6e 6b 20 6f 66 20  6d 65 6d 6f 72 79 0d 63  |hunk of memory.c|
00000300  61 6c 6c 65 64 20 74 68  65 20 69 6e 70 75 74 20  |alled the input |
00000310  62 75 66 66 65 72 2e 20  20 54 68 61 74 20 70 72  |buffer.  That pr|
00000320  6f 67 72 61 6d 20 72 65  74 75 72 6e 73 20 69 6e  |ogram returns in|
00000330  20 74 68 69 73 0d 6d 6f  64 75 6c 65 20 61 73 20  | this.module as |
00000340  61 20 73 75 62 72 6f 75  74 69 6e 65 20 69 6e 20  |a subroutine in |
00000350  61 20 6c 61 72 67 65 72  20 70 72 6f 67 72 61 6d  |a larger program|
00000360  20 77 68 69 63 68 20 77  69 6c 6c 20 6c 65 61 76  | which will leav|
00000370  65 0d 75 73 20 77 69 74  68 20 61 20 34 20 62 79  |e.us with a 4 by|
00000380  74 65 20 6e 75 6d 62 65  72 20 69 6e 20 77 6f 72  |te number in wor|
00000390  6b 20 73 70 61 63 65 20  69 6e 20 74 68 65 20 63  |k space in the c|
000003a0  6f 6d 70 75 74 65 72 0d  6d 65 6d 6f 72 79 2e 0d  |omputer.memory..|
000003b0  0d 4f 6e 63 65 20 74 68  61 74 20 6e 75 6d 62 65  |.Once that numbe|
000003c0  72 20 69 73 20 69 6e 20  6d 65 6d 6f 72 79 20 77  |r is in memory w|
000003d0  65 20 63 61 6e 20 70 65  72 66 6f 72 6d 20 61 72  |e can perform ar|
000003e0  69 74 68 6d 65 74 69 63  61 6c 0d 6f 70 65 72 61  |ithmetical.opera|
000003f0  74 69 6f 6e 73 20 6f 6e  20 69 74 3a 20 61 64 64  |tions on it: add|
00000400  2c 20 73 75 62 74 72 61  63 74 2c 20 6d 75 6c 74  |, subtract, mult|
00000410  69 70 6c 79 20 61 6e 64  20 64 69 76 69 64 65 2e  |iply and divide.|
00000420  20 20 4f 6e 63 65 0d 77  65 20 68 61 76 65 20 61  |  Once.we have a|
00000430  20 72 65 73 75 6c 74 2c  20 74 68 61 74 20 77 69  | result, that wi|
00000440  6c 6c 20 62 65 20 61 20  62 69 6e 61 72 79 20 6e  |ll be a binary n|
00000450  75 6d 62 65 72 20 69 6e  20 6d 65 6d 6f 72 79 20  |umber in memory |
00000460  61 6e 64 0d 74 6f 20 70  72 69 6e 74 20 69 74 20  |and.to print it |
00000470  6f 75 74 20 77 65 20 68  61 76 65 20 74 6f 20 63  |out we have to c|
00000480  6f 6e 76 65 72 74 20 69  6e 20 74 68 65 20 6f 70  |onvert in the op|
00000490  70 6f 73 69 74 65 0d 64  69 72 65 63 74 69 6f 6e  |posite.direction|
000004a0  2c 20 62 69 6e 61 72 79  20 74 6f 20 41 53 43 49  |, binary to ASCI|
000004b0  49 2e 0d 0d 42 2f 6f 73  62 31 31 20 6c 65 66 74  |I...B/osb11 left|
000004c0  20 75 73 20 77 69 74 68  20 61 20 73 74 72 69 6e  | us with a strin|
000004d0  67 20 69 6e 20 61 20 62  75 66 66 65 72 2e 20 20  |g in a buffer.  |
000004e0  54 68 65 20 66 69 72 73  74 20 64 69 67 69 74 0d  |The first digit.|
000004f0  6f 66 20 74 68 61 74 20  73 74 72 69 6e 67 20 63  |of that string c|
00000500  6f 75 6c 64 20 62 65 20  61 20 6e 75 6d 62 65 72  |ould be a number|
00000510  2c 20 6f 72 20 61 20 6d  69 6e 75 73 20 73 69 67  |, or a minus sig|
00000520  6e 2e 20 20 49 27 6c 6c  0d 6c 65 61 76 65 20 74  |n.  I'll.leave t|
00000530  68 65 20 73 69 67 6e 20  66 6f 72 20 61 20 6d 6f  |he sign for a mo|
00000540  6d 65 6e 74 2e 20 20 46  69 72 73 74 20 6c 65 74  |ment.  First let|
00000550  27 73 20 6c 6f 6f 6b 20  61 74 20 74 68 65 0d 70  |'s look at the.p|
00000560  72 6f 62 6c 65 6d 20 6f  66 20 63 6f 6e 76 65 72  |roblem of conver|
00000570  73 69 6f 6e 2e 0d 0d 41  73 20 61 6e 20 65 78 61  |sion...As an exa|
00000580  6d 70 6c 65 20 6c 65 74  27 73 20 74 61 6b 65 20  |mple let's take |
00000590  61 20 73 74 72 69 6e 67  20 74 68 61 74 20 63 6f  |a string that co|
000005a0  6e 74 61 69 6e 73 20 74  68 65 0d 66 6f 6c 6c 6f  |ntains the.follo|
000005b0  77 69 6e 67 20 63 68 61  72 61 63 74 65 72 73 3a  |wing characters:|
000005c0  0d 0d 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |..              |
000005d0  20 20 20 20 20 20 20 31  32 33 34 0d 0d 52 65 6d  |       1234..Rem|
000005e0  65 6d 62 65 72 20 74 68  61 74 20 69 73 20 61 20  |ember that is a |
000005f0  73 74 72 69 6e 67 20 6f  66 20 66 6f 75 72 20 63  |string of four c|
00000600  68 61 72 61 63 74 65 72  73 2c 20 6e 6f 74 20 61  |haracters, not a|
00000610  20 6e 75 6d 62 65 72 0d  77 69 74 68 20 74 68 65  | number.with the|
00000620  20 76 61 6c 75 65 20 31  32 33 34 2e 20 20 49 66  | value 1234.  If|
00000630  20 77 65 20 73 74 61 72  74 20 61 74 20 74 68 65  | we start at the|
00000640  20 6c 65 66 74 20 68 61  6e 64 20 65 6e 64 20 77  | left hand end w|
00000650  65 0d 66 69 6e 64 20 61  20 27 31 27 2e 20 20 4e  |e.find a '1'.  N|
00000660  6f 77 20 49 20 6b 6e 6f  77 20 74 68 61 74 20 75  |ow I know that u|
00000670  6e 64 65 72 20 74 68 65  20 41 72 61 62 69 63 20  |nder the Arabic |
00000680  6e 75 6d 65 72 61 6c 20  73 79 73 74 65 6d 0d 74  |numeral system.t|
00000690  68 65 20 61 63 74 75 61  6c 20 76 61 6c 75 65 20  |he actual value |
000006a0  6f 66 20 74 68 61 74 20  27 31 27 20 64 65 70 65  |of that '1' depe|
000006b0  6e 64 73 20 6f 6e 20 69  74 27 73 20 70 6f 73 69  |nds on it's posi|
000006c0  74 69 6f 6e 2c 20 62 75  74 0d 66 6f 72 20 41 53  |tion, but.for AS|
000006d0  43 49 49 20 74 6f 20 62  69 6e 61 72 79 20 63 6f  |CII to binary co|
000006e0  6e 76 65 72 73 69 6f 6e  20 77 65 20 64 6f 20 6e  |nversion we do n|
000006f0  6f 74 20 6b 6e 6f 77 2c  20 69 6e 64 65 65 64 20  |ot know, indeed |
00000700  64 6f 20 6e 6f 74 0d 6e  65 65 64 20 74 6f 20 6b  |do not.need to k|
00000710  6e 6f 77 2c 20 69 74 27  73 20 70 6f 73 69 74 69  |now, it's positi|
00000720  6f 6e 20 64 69 72 65 63  74 6c 79 2e 20 20 49 66  |on directly.  If|
00000730  20 77 65 20 6c 6f 6f 6b  20 61 74 20 74 68 65 0d  | we look at the.|
00000740  6e 65 78 74 20 63 68 61  72 61 63 74 65 72 20 69  |next character i|
00000750  6e 20 74 68 65 20 73 74  72 69 6e 67 20 77 65 20  |n the string we |
00000760  66 69 6e 64 20 74 68 65  20 27 32 27 20 62 75 74  |find the '2' but|
00000770  20 6d 6f 72 65 0d 69 6d  70 6f 72 74 61 6e 74 20  | more.important |
00000780  77 65 20 6e 6f 77 20 6b  6e 6f 77 20 74 68 61 74  |we now know that|
00000790  20 74 68 65 20 27 31 27  20 69 73 20 69 6e 20 66  | the '1' is in f|
000007a0  61 63 74 20 77 6f 72 74  68 20 31 30 20 73 6f 20  |act worth 10 so |
000007b0  77 65 0d 68 61 76 65 20  61 20 27 72 75 6e 6e 69  |we.have a 'runni|
000007c0  6e 67 20 74 6f 74 61 6c  27 20 6f 66 20 31 32 2e  |ng total' of 12.|
000007d0  20 20 41 73 20 77 65 20  6c 6f 6f 6b 20 61 74 20  |  As we look at |
000007e0  74 68 65 20 6e 65 78 74  0d 70 6f 73 69 74 69 6f  |the next.positio|
000007f0  6e 20 77 65 20 66 69 6e  64 20 61 20 27 33 27 20  |n we find a '3' |
00000800  61 6e 64 20 77 65 20 6b  6e 6f 77 20 74 68 61 74  |and we know that|
00000810  20 6f 75 72 20 27 31 32  27 20 74 6f 20 74 68 65  | our '12' to the|
00000820  20 6c 65 66 74 0d 69 73  20 69 6e 20 66 61 63 74  | left.is in fact|
00000830  20 6e 6f 77 20 77 6f 72  74 68 20 31 32 30 20 67  | now worth 120 g|
00000840  69 76 69 6e 67 20 75 73  20 61 20 74 6f 74 61 6c  |iving us a total|
00000850  20 6f 66 20 31 32 33 2e  20 20 46 69 6e 61 6c 6c  | of 123.  Finall|
00000860  79 0d 77 65 20 66 69 6e  64 20 61 20 27 34 27 2c  |y.we find a '4',|
00000870  20 74 68 65 20 66 69 67  75 72 65 73 20 74 6f 20  | the figures to |
00000880  6f 75 72 20 6c 65 66 74  20 61 72 65 20 6e 6f 77  |our left are now|
00000890  20 77 6f 72 74 68 20 31  32 33 30 0d 61 6e 64 20  | worth 1230.and |
000008a0  73 6f 20 77 65 20 68 61  76 65 20 61 20 74 6f 74  |so we have a tot|
000008b0  61 6c 20 6f 66 20 31 32  33 34 2c 20 77 68 69 63  |al of 1234, whic|
000008c0  68 20 69 73 20 77 68 61  74 20 77 61 73 20 62 6c  |h is what was bl|
000008d0  69 6e 64 69 6e 67 6c 79  0d 6f 62 76 69 6f 75 73  |indingly.obvious|
000008e0  20 69 6e 20 74 68 65 20  66 69 72 73 74 20 70 6c  | in the first pl|
000008f0  61 63 65 21 0d 0d 4c 65  74 27 73 20 74 68 69 6e  |ace!..Let's thin|
00000900  6b 20 6f 66 20 74 68 69  73 20 69 6e 20 74 65 72  |k of this in ter|
00000910  6d 73 20 6f 66 20 61 20  63 6f 6d 70 75 74 65 72  |ms of a computer|
00000920  20 61 6c 67 6f 72 69 74  68 6d 20 28 61 0d 72 65  | algorithm (a.re|
00000930  63 69 70 65 20 69 66 20  79 6f 75 20 6c 69 6b 65  |cipe if you like|
00000940  29 20 61 6e 64 20 74 68  61 74 20 67 6f 65 73 20  |) and that goes |
00000950  6c 69 6b 65 20 74 68 69  73 3a 0d 0d 20 20 20 20  |like this:..    |
00000960  4d 75 6c 74 69 70 6c 79  20 74 68 65 20 6e 75 6d  |Multiply the num|
00000970  62 65 72 20 27 73 6f 20  66 61 72 27 20 62 79 20  |ber 'so far' by |
00000980  31 30 0d 20 20 20 20 41  64 64 20 74 68 65 20 76  |10.    Add the v|
00000990  61 6c 75 65 20 6f 66 20  74 68 65 20 64 69 67 69  |alue of the digi|
000009a0  74 20 63 75 72 72 65 6e  74 6c 79 20 62 65 69 6e  |t currently bein|
000009b0  67 20 72 65 61 64 20 74  6f 20 74 68 65 0d 20 20  |g read to the.  |
000009c0  20 20 20 20 20 20 6e 75  6d 62 65 72 20 27 73 6f  |      number 'so|
000009d0  20 66 61 72 27 0d 20 20  20 20 52 65 70 65 61 74  | far'.    Repeat|
000009e0  20 6c 6f 6f 70 20 75 6e  74 69 6c 20 74 68 65 72  | loop until ther|
000009f0  65 20 61 72 65 20 6e 6f  20 6d 6f 72 65 20 64 69  |e are no more di|
00000a00  67 69 74 73 0d 0d 57 68  65 6e 20 79 6f 75 20 73  |gits..When you s|
00000a10  74 61 72 74 20 74 68 65  20 6e 75 6d 62 65 72 20  |tart the number |
00000a20  27 73 6f 20 66 61 72 27  20 69 73 20 6f 66 20 63  |'so far' is of c|
00000a30  6f 75 72 73 65 20 7a 65  72 6f 2e 20 20 49 0d 73  |ourse zero.  I.s|
00000a40  68 6f 75 6c 64 20 70 65  72 68 61 70 73 20 63 61  |hould perhaps ca|
00000a50  6c 6c 20 69 74 20 74 68  65 20 70 61 72 74 69 61  |ll it the partia|
00000a60  6c 20 72 65 73 75 6c 74  20 6f 72 20 74 68 65 20  |l result or the |
00000a70  61 63 63 75 6d 75 6c 61  74 65 64 0d 72 65 73 75  |accumulated.resu|
00000a80  6c 74 2e 0d 0d 54 68 69  73 20 61 6c 67 6f 72 69  |lt...This algori|
00000a90  74 68 6d 20 68 61 73 20  61 6e 20 61 64 76 61 6e  |thm has an advan|
00000aa0  74 61 67 65 20 69 6e 20  74 68 61 74 20 69 74 20  |tage in that it |
00000ab0  63 61 6e 20 72 65 61 64  69 6c 79 20 62 65 0d 61  |can readily be.a|
00000ac0  64 61 70 74 65 64 20 74  6f 20 72 65 61 64 20 69  |dapted to read i|
00000ad0  6e 20 6e 75 6d 62 65 72  73 20 69 6e 20 62 61 73  |n numbers in bas|
00000ae0  65 73 20 6f 74 68 65 72  20 74 68 61 6e 20 31 30  |es other than 10|
00000af0  2e 20 20 49 6e 20 74 68  61 74 0d 63 61 73 65 20  |.  In that.case |
00000b00  69 74 20 77 6f 75 6c 64  20 72 65 61 64 3a 0d 0d  |it would read:..|
00000b10  20 20 20 20 4d 75 6c 74  69 70 6c 79 20 74 68 65  |    Multiply the|
00000b20  20 6e 75 6d 62 65 72 20  27 73 6f 20 66 61 72 27  | number 'so far'|
00000b30  20 62 79 20 74 68 65 20  62 61 73 65 0d 20 20 20  | by the base.   |
00000b40  20 41 64 64 20 74 68 65  20 76 61 6c 75 65 20 6f  | Add the value o|
00000b50  66 20 74 68 65 20 64 69  67 69 74 20 63 75 72 72  |f the digit curr|
00000b60  65 6e 74 6c 79 20 62 65  69 6e 67 20 72 65 61 64  |ently being read|
00000b70  20 74 6f 20 74 68 65 0d  20 20 20 20 20 20 20 20  | to the.        |
00000b80  6e 75 6d 62 65 72 20 27  73 6f 20 66 61 72 27 0d  |number 'so far'.|
00000b90  20 20 20 20 52 65 70 65  61 74 20 75 6e 74 69 6c  |    Repeat until|
00000ba0  20 74 68 65 72 65 20 61  72 65 20 6e 6f 20 6d 6f  | there are no mo|
00000bb0  72 65 20 64 69 67 69 74  73 0d 0d 54 68 65 72 65  |re digits..There|
00000bc0  20 61 72 65 20 61 20 63  6f 75 70 6c 65 20 6f 66  | are a couple of|
00000bd0  20 75 6e 61 6e 73 77 65  72 65 64 20 71 75 65 73  | unanswered ques|
00000be0  74 69 6f 6e 73 20 68 65  72 65 2e 20 20 4a 75 73  |tions here.  Jus|
00000bf0  74 20 68 6f 77 0d 64 6f  20 79 6f 75 20 64 65 74  |t how.do you det|
00000c00  65 72 6d 69 6e 65 20 74  68 61 74 20 74 68 65 72  |ermine that ther|
00000c10  65 20 61 72 65 20 6e 6f  20 6d 6f 72 65 20 64 69  |e are no more di|
00000c20  67 69 74 73 3f 20 20 54  68 65 20 65 61 73 69 65  |gits?  The easie|
00000c30  73 74 0d 77 61 79 20 69  73 20 74 6f 20 63 6f 6e  |st.way is to con|
00000c40  74 69 6e 75 65 20 75 6e  74 69 6c 20 79 6f 75 20  |tinue until you |
00000c50  68 69 74 20 61 20 63 68  61 72 61 63 74 65 72 20  |hit a character |
00000c60  74 68 61 74 20 69 73 20  6e 6f 74 20 69 6e 0d 79  |that is not in.y|
00000c70  6f 75 72 20 63 68 61 72  61 63 74 65 72 20 73 65  |our character se|
00000c80  74 2e 20 20 49 6e 20 6f  75 72 20 63 61 73 65 2c  |t.  In our case,|
00000c90  20 66 6f 72 20 64 65 63  69 6d 61 6c 20 69 6e 70  | for decimal inp|
00000ca0  75 74 2c 20 77 65 0d 63  6f 6e 74 69 6e 75 65 20  |ut, we.continue |
00000cb0  75 6e 74 69 6c 20 77 65  20 68 69 74 20 61 20 63  |until we hit a c|
00000cc0  68 61 72 61 63 74 65 72  20 74 68 61 74 20 69 73  |haracter that is|
00000cd0  20 6e 6f 74 20 62 65 74  77 65 65 6e 20 7a 65 72  | not between zer|
00000ce0  6f 0d 61 6e 64 20 6e 69  6e 65 2e 0d 0d 57 68 61  |o.and nine...Wha|
00000cf0  74 20 69 73 20 74 68 65  20 76 61 6c 75 65 20 6f  |t is the value o|
00000d00  66 20 61 20 64 69 67 69  74 3f 20 20 54 68 61 74  |f a digit?  That|
00000d10  20 69 73 20 65 61 73 79  20 66 6f 72 20 74 68 65  | is easy for the|
00000d20  20 6e 75 6d 62 65 72 73  0d 30 20 74 6f 20 39 20  | numbers.0 to 9 |
00000d30  62 65 63 61 75 73 65 20  74 68 65 20 41 53 43 49  |because the ASCI|
00000d40  49 20 63 6f 64 65 73 20  66 6f 72 20 74 68 65 6d  |I codes for them|
00000d50  20 61 72 65 20 26 33 30  20 74 6f 20 26 33 39 20  | are &30 to &39 |
00000d60  6f 72 20 34 38 0d 74 6f  20 35 37 2e 20 20 57 65  |or 48.to 57.  We|
00000d70  20 6a 75 73 74 20 73 75  62 74 72 61 63 74 20 34  | just subtract 4|
00000d80  38 20 66 72 6f 6d 20 74  68 65 20 41 53 43 49 49  |8 from the ASCII|
00000d90  2e 0d 0d 53 6f 20 77 65  20 6e 65 65 64 20 74 6f  |...So we need to|
00000da0  20 62 65 20 61 62 6c 65  20 74 6f 20 6d 75 6c 74  | be able to mult|
00000db0  69 70 6c 79 20 61 20 6e  75 6d 62 65 72 20 62 79  |iply a number by|
00000dc0  20 74 68 65 20 62 61 73  65 20 69 6e 0d 6f 72 64  | the base in.ord|
00000dd0  65 72 20 74 6f 20 63 61  72 72 79 20 6f 75 74 20  |er to carry out |
00000de0  74 68 69 73 20 69 6e 70  75 74 20 70 72 6f 63 65  |this input proce|
00000df0  64 75 72 65 2e 20 20 54  68 65 20 72 6f 75 74 69  |dure.  The routi|
00000e00  6e 65 20 69 6e 0d 74 68  69 73 20 6d 6f 64 75 6c  |ne in.this modul|
00000e10  65 20 69 73 20 69 6e 20  66 61 63 74 20 67 65 6e  |e is in fact gen|
00000e20  65 72 61 6c 20 65 6e 6f  75 67 68 20 74 6f 20 63  |eral enough to c|
00000e30  6f 70 65 20 77 69 74 68  20 61 6e 79 20 62 61 73  |ope with any bas|
00000e40  65 0d 75 70 20 74 6f 20  32 35 35 20 28 61 6c 74  |e.up to 255 (alt|
00000e50  68 6f 75 67 68 20 73 6f  72 74 69 6e 67 20 6f 75  |hough sorting ou|
00000e60  74 20 74 68 65 20 76 61  6c 75 65 73 20 6f 66 20  |t the values of |
00000e70  74 68 65 20 63 68 61 72  61 63 74 65 72 73 0d 69  |the characters.i|
00000e80  6e 20 74 68 61 74 20 62  61 73 65 20 6d 69 67 68  |n that base migh|
00000e90  74 20 63 61 75 73 65 20  73 6f 6d 65 20 70 72 6f  |t cause some pro|
00000ea0  62 6c 65 6d 73 29 20 62  75 74 20 66 6f 72 20 74  |blems) but for t|
00000eb0  68 65 20 74 69 6d 65 0d  62 65 69 6e 67 20 77 65  |he time.being we|
00000ec0  27 6c 6c 20 75 73 65 20  69 74 20 74 6f 20 64 65  |'ll use it to de|
00000ed0  61 6c 20 77 69 74 68 20  64 65 63 69 6d 61 6c 20  |al with decimal |
00000ee0  6e 75 6d 62 65 72 73 2e  20 20 54 68 65 20 62 61  |numbers.  The ba|
00000ef0  73 65 73 0d 79 6f 75 20  6d 69 67 68 74 20 77 61  |ses.you might wa|
00000f00  6e 74 20 74 6f 20 75 73  65 20 65 76 65 6e 74 75  |nt to use eventu|
00000f10  61 6c 6c 79 20 61 72 65  20 62 69 6e 61 72 79 20  |ally are binary |
00000f20  28 32 29 20 6f 63 74 61  6c 20 28 38 29 0d 64 65  |(2) octal (8).de|
00000f30  63 69 6d 61 6c 20 28 31  30 29 20 61 6e 64 20 68  |cimal (10) and h|
00000f40  65 78 61 64 65 63 69 6d  61 6c 20 28 31 36 29 2e  |exadecimal (16).|
00000f50  0d 0d 54 68 65 20 6c 61  72 67 65 73 74 20 6e 75  |..The largest nu|
00000f60  6d 62 65 72 20 74 68 61  74 20 63 61 6e 20 62 65  |mber that can be|
00000f70  20 68 65 6c 64 20 69 6e  20 34 20 62 79 74 65 73  | held in 4 bytes|
00000f80  20 75 73 69 6e 67 20 32  27 73 0d 63 6f 6d 70 6c  | using 2's.compl|
00000f90  65 6d 65 6e 74 20 6e 65  67 61 74 69 76 65 20 69  |ement negative i|
00000fa0  73 20 32 31 34 37 34 38  33 36 34 37 20 70 6f 73  |s 2147483647 pos|
00000fb0  69 74 69 76 65 20 6f 72  20 2d 20 32 31 34 37 34  |itive or - 21474|
00000fc0  38 33 36 34 38 0d 6e 65  67 61 74 69 76 65 20 77  |83648.negative w|
00000fd0  68 69 63 68 20 63 6f 72  72 65 73 70 6f 6e 64 20  |hich correspond |
00000fe0  74 6f 20 26 37 46 46 46  46 46 46 46 20 61 6e 64  |to &7FFFFFFF and|
00000ff0  20 26 38 30 30 30 30 30  30 30 2e 20 20 49 6e 0d  | &80000000.  In.|
00001000  66 61 63 74 20 69 6e 20  74 68 69 73 20 72 6f 75  |fact in this rou|
00001010  74 69 6e 65 20 49 20 68  61 76 65 20 73 61 63 72  |tine I have sacr|
00001020  69 66 69 63 65 64 20 74  68 65 20 61 62 69 6c 69  |ificed the abili|
00001030  74 79 20 74 6f 20 65 6e  74 65 72 0d 2d 20 32 31  |ty to enter.- 21|
00001040  34 37 34 38 33 36 34 38  20 69 74 73 65 6c 66 20  |47483648 itself |
00001050  69 6e 20 6f 72 64 65 72  20 74 6f 20 73 69 6d 70  |in order to simp|
00001060  6c 69 66 79 20 74 68 65  20 63 6f 64 69 6e 67 20  |lify the coding |
00001070  61 0d 6c 69 74 74 6c 65  2e 20 20 54 68 65 20 6c  |a.little.  The l|
00001080  61 72 67 65 73 74 20 6e  65 67 61 74 69 76 65 20  |argest negative |
00001090  6e 75 6d 62 65 72 20 69  73 20 2d 20 32 31 34 37  |number is - 2147|
000010a0  34 38 33 36 34 37 2c 20  62 75 74 20 49 0d 64 6f  |483647, but I.do|
000010b0  75 62 74 20 69 66 20 74  68 61 74 20 77 69 6c 6c  |ubt if that will|
000010c0  20 63 61 75 73 65 20 6d  75 63 68 20 77 61 69 6c  | cause much wail|
000010d0  69 6e 67 20 61 6e 64 20  67 6e 61 73 68 69 6e 67  |ing and gnashing|
000010e0  20 6f 66 20 74 65 65 74  68 2e 0d 0d 53 6f 20 6a  | of teeth...So j|
000010f0  75 73 74 20 68 6f 77 20  64 6f 20 77 65 20 6d 75  |ust how do we mu|
00001100  6c 74 69 70 6c 79 20 69  6e 20 6d 61 63 68 69 6e  |ltiply in machin|
00001110  65 20 63 6f 64 65 3f 20  20 57 65 6c 6c 0d 66 6f  |e code?  Well.fo|
00001120  72 74 75 6e 61 74 65 6c  79 20 77 65 20 63 61 6e  |rtunately we can|
00001130  20 66 61 6c 6c 20 62 61  63 6b 20 6f 6e 20 67 6f  | fall back on go|
00001140  6f 64 20 6f 6c 64 20 66  61 73 68 69 6f 6e 65 64  |od old fashioned|
00001150  20 6c 6f 6e 67 0d 6d 75  6c 74 69 70 6c 69 63 61  | long.multiplica|
00001160  74 69 6f 6e 2c 20 77 68  69 63 68 20 69 73 20 61  |tion, which is a|
00001170  62 73 75 72 64 6c 79 20  73 69 6d 70 6c 65 20 69  |bsurdly simple i|
00001180  6e 20 62 69 6e 61 72 79  20 73 69 6e 63 65 20 79  |n binary since y|
00001190  6f 75 0d 68 61 76 65 20  61 20 76 65 72 79 20 72  |ou.have a very r|
000011a0  75 64 69 6d 65 6e 74 61  72 79 20 6d 75 6c 74 69  |udimentary multi|
000011b0  70 6c 69 63 61 74 69 6f  6e 20 74 61 62 6c 65 2e  |plication table.|
000011c0  0d 0d 4c 65 74 27 73 20  6d 75 6c 74 69 70 6c 79  |..Let's multiply|
000011d0  20 31 31 30 31 31 20 62  79 20 31 30 31 31 20 28  | 11011 by 1011 (|
000011e0  69 2e 65 2e 20 32 37 20  62 79 20 31 31 29 0d 0d  |i.e. 27 by 11)..|
000011f0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00001200  31 31 30 31 31 0d 20 20  20 20 20 20 20 20 20 20  |11011.          |
00001210  20 20 20 20 20 20 20 20  20 20 78 0d 20 20 20 20  |          x.    |
00001220  20 20 20 20 20 20 20 20  20 20 20 20 20 31 30 31  |             101|
00001230  31 0d 20 20 20 20 20 20  20 20 20 20 20 20 2d 2d  |1.            --|
00001240  2d 2d 2d 2d 2d 2d 2d 0d  20 20 20 20 20 20 20 20  |-------.        |
00001250  20 20 20 20 20 31 31 30  31 31 30 30 30 0d 20 20  |     11011000.  |
00001260  20 20 20 20 20 20 20 20  20 20 20 20 20 31 31 30  |             110|
00001270  31 31 30 0d 20 20 20 20  20 20 20 20 20 20 20 20  |110.            |
00001280  20 20 20 20 31 31 30 31  31 0d 20 20 20 20 20 20  |    11011.      |
00001290  20 20 20 20 20 20 2d 2d  2d 2d 2d 2d 2d 2d 2d 0d  |      ---------.|
000012a0  20 20 20 20 20 20 20 20  20 20 20 20 31 30 30 31  |            1001|
000012b0  30 31 30 30 31 20 20 20  20 20 77 68 69 63 68 20  |01001     which |
000012c0  69 73 20 20 32 39 37 0d  0d 49 20 68 6f 70 65 20  |is  297..I hope |
000012d0  79 6f 75 20 63 61 6e 20  73 65 65 20 74 68 61 74  |you can see that|
000012e0  20 66 6f 72 20 65 61 63  68 20 73 65 74 20 62 69  | for each set bi|
000012f0  74 20 6f 66 20 74 68 65  20 6d 75 6c 74 69 70 6c  |t of the multipl|
00001300  69 65 72 0d 28 31 31 30  31 29 20 74 68 65 72 65  |ier.(1101) there|
00001310  20 69 73 20 61 20 72 6f  77 20 69 6e 20 74 68 65  | is a row in the|
00001320  20 73 70 61 63 65 20 62  65 74 77 65 65 6e 20 74  | space between t|
00001330  68 65 20 64 6f 74 74 65  64 20 6c 69 6e 65 73 2e  |he dotted lines.|
00001340  20 0d 4a 75 73 74 20 6c  69 6b 65 20 64 65 63 69  | .Just like deci|
00001350  6d 61 6c 20 6c 6f 6e 67  20 6d 75 6c 74 69 70 6c  |mal long multipl|
00001360  69 63 61 74 69 6f 6e 20  74 68 65 20 72 6f 77 73  |ication the rows|
00001370  20 61 72 65 20 6f 66 66  73 65 74 20 74 6f 0d 74  | are offset to.t|
00001380  68 65 20 6c 65 66 74 20  63 6f 72 72 65 73 70 6f  |he left correspo|
00001390  6e 64 69 6e 67 20 74 6f  20 74 68 65 20 27 70 6f  |nding to the 'po|
000013a0  77 65 72 27 20 6f 66 20  74 68 65 20 62 69 74 20  |wer' of the bit |
000013b0  74 68 65 20 72 6f 77 0d  62 65 6c 6f 6e 67 73 20  |the row.belongs |
000013c0  74 6f 2e 20 20 59 6f 75  20 73 68 6f 75 6c 64 20  |to.  You should |
000013d0  6e 6f 74 65 20 61 6c 73  6f 20 74 68 61 74 20 79  |note also that y|
000013e0  6f 75 20 65 73 73 65 6e  74 69 61 6c 6c 79 20 6f  |ou essentially o|
000013f0  6e 6c 79 0d 6e 65 65 64  20 74 6f 20 6b 6e 6f 77  |nly.need to know|
00001400  20 74 68 65 20 6f 6e 65  20 74 69 6d 65 73 20 74  | the one times t|
00001410  61 62 6c 65 20 61 6e 64  20 74 68 61 74 20 74 68  |able and that th|
00001420  65 20 61 64 64 69 6e 67  20 75 70 20 6f 66 0d 74  |e adding up of.t|
00001430  68 65 20 70 61 72 74 69  61 6c 20 70 72 6f 64 75  |he partial produ|
00001440  63 74 73 20 69 73 20 6d  6f 72 65 20 64 69 66 66  |cts is more diff|
00001450  69 63 75 6c 74 20 66 6f  72 20 61 20 6d 65 72 65  |icult for a mere|
00001460  20 68 75 6d 61 6e 20 74  68 61 6e 0d 74 68 65 20  | human than.the |
00001470  6d 75 6c 74 69 70 6c 79  69 6e 67 20 74 68 61 74  |multiplying that|
00001480  20 70 72 6f 64 75 63 65  73 20 65 61 63 68 20 70  | produces each p|
00001490  61 72 74 69 61 6c 20 70  72 6f 64 75 63 74 2e 0d  |artial product..|
000014a0  0d 49 6e 20 6d 61 63 68  69 6e 65 20 63 6f 64 65  |.In machine code|
000014b0  20 74 68 65 20 27 64 69  66 66 69 63 75 6c 74 27  | the 'difficult'|
000014c0  20 61 64 64 69 6e 67 20  69 73 20 74 61 6b 65 6e  | adding is taken|
000014d0  20 63 61 72 65 20 6f 66  0d 65 61 73 69 6c 79 20  | care of.easily |
000014e0  75 73 69 6e 67 20 41 44  43 2e 20 20 53 6f 20 77  |using ADC.  So w|
000014f0  68 61 74 20 61 62 6f 75  74 20 74 68 6f 73 65 20  |hat about those |
00001500  70 61 72 74 69 61 6c 20  70 72 6f 64 75 63 74 73  |partial products|
00001510  0d 62 65 69 6e 67 20 6f  66 66 73 65 74 20 6c 65  |.being offset le|
00001520  66 74 20 2e 2e 2e 2e 20  77 65 6c 6c 20 74 68 61  |ft .... well tha|
00001530  74 27 73 20 72 6f 74 61  74 69 6e 67 20 69 73 6e  |t's rotating isn|
00001540  27 74 20 69 74 3f 20 20  53 6f 0d 68 6f 77 20 64  |'t it?  So.how d|
00001550  6f 65 73 20 69 74 20 6c  6f 6f 6b 20 61 73 20 61  |oes it look as a|
00001560  6e 20 61 6c 67 6f 72 69  74 68 6d 3f 0d 0d 57 65  |n algorithm?..We|
00001570  27 6c 6c 20 61 63 74 75  61 6c 6c 79 20 64 6f 20  |'ll actually do |
00001580  74 68 69 73 20 62 61 63  6b 77 61 72 64 73 20 73  |this backwards s|
00001590  6f 20 69 74 20 6c 6f 6f  6b 73 20 6d 6f 72 65 20  |o it looks more |
000015a0  6c 69 6b 65 0d 0d 20 20  20 20 20 20 20 20 20 20  |like..          |
000015b0  20 20 20 20 20 20 20 20  20 20 31 31 30 31 31 0d  |          11011.|
000015c0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
000015d0  20 20 20 20 20 20 20 20  78 0d 20 20 20 20 20 20  |        x.      |
000015e0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 31  |               1|
000015f0  30 31 31 0d 20 20 20 20  20 20 20 20 20 20 20 20  |011.            |
00001600  20 20 20 20 2d 2d 2d 2d  2d 2d 2d 2d 2d 0d 20 20  |    ---------.  |
00001610  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00001620  20 20 31 31 30 31 31 0d  20 20 20 20 20 20 20 20  |  11011.        |
00001630  20 20 20 20 20 20 20 20  20 20 20 31 31 30 31 31  |           11011|
00001640  30 0d 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |0.              |
00001650  20 20 20 31 31 30 31 31  30 30 30 0d 20 20 20 20  |   11011000.    |
00001660  20 20 20 20 20 20 20 20  20 20 20 20 2d 2d 2d 2d  |            ----|
00001670  2d 2d 2d 2d 2d 0d 20 20  20 20 20 20 20 20 20 20  |-----.          |
00001680  20 20 20 20 20 20 31 30  30 31 30 31 30 30 31 0d  |      100101001.|
00001690  0d 62 75 74 20 74 68 65  20 72 65 73 75 6c 74 20  |.but the result |
000016a0  69 73 20 74 68 65 20 73  61 6d 65 2e 0d 0d 54 61  |is the same...Ta|
000016b0  6b 65 20 74 68 65 20 72  69 67 68 74 6d 6f 73 74  |ke the rightmost|
000016c0  20 28 6c 65 61 73 74 20  73 69 67 6e 69 66 69 63  | (least signific|
000016d0  61 6e 74 20 62 69 74 29  20 6f 66 20 74 68 65 20  |ant bit) of the |
000016e0  6d 75 6c 74 69 70 6c 69  65 72 0d 61 6e 64 20 69  |multiplier.and i|
000016f0  66 20 69 74 20 69 73 20  73 65 74 20 61 64 64 20  |f it is set add |
00001700  74 68 65 20 6d 75 6c 74  69 70 6c 69 63 61 6e 64  |the multiplicand|
00001710  20 74 6f 20 74 68 65 20  63 6f 6e 74 65 6e 74 73  | to the contents|
00001720  20 6f 66 20 74 68 65 0d  70 61 72 74 69 61 6c 20  | of the.partial |
00001730  70 72 6f 64 75 63 74 20  77 6f 72 6b 73 70 61 63  |product workspac|
00001740  65 20 28 70 70 77 73 29  20 77 68 69 63 68 20 69  |e (ppws) which i|
00001750  73 20 65 6d 70 74 79 20  74 6f 20 73 74 61 72 74  |s empty to start|
00001760  0d 77 69 74 68 2c 20 69  66 20 69 74 20 69 73 20  |.with, if it is |
00001770  63 6c 65 61 72 20 64 6f  20 6e 6f 74 68 69 6e 67  |clear do nothing|
00001780  2e 0d 0d 52 6f 74 61 74  65 20 74 68 65 20 6d 75  |...Rotate the mu|
00001790  6c 74 69 70 6c 69 65 72  20 72 69 67 68 74 20 61  |ltiplier right a|
000017a0  6e 64 20 74 68 65 20 6d  75 6c 74 69 70 6c 69 63  |nd the multiplic|
000017b0  61 6e 64 20 6c 65 66 74  2e 0d 0d 52 65 70 65 61  |and left...Repea|
000017c0  74 20 74 68 65 20 74 77  6f 20 73 74 61 67 65 73  |t the two stages|
000017d0  20 75 6e 74 69 6c 20 74  68 65 20 6d 75 6c 74 69  | until the multi|
000017e0  70 6c 69 65 72 20 69 73  20 7a 65 72 6f 2e 0d 0d  |plier is zero...|
000017f0  49 6e 20 70 72 61 63 74  69 63 65 20 79 6f 75 20  |In practice you |
00001800  72 6f 74 61 74 65 20 74  68 65 20 6d 75 6c 74 69  |rotate the multi|
00001810  70 6c 69 65 72 20 66 69  72 73 74 20 62 65 63 61  |plier first beca|
00001820  75 73 65 20 79 6f 75 20  75 73 65 0d 74 68 65 20  |use you use.the |
00001830  63 61 72 72 79 20 66 6c  61 67 20 74 6f 20 63 68  |carry flag to ch|
00001840  65 63 6b 20 77 68 65 74  68 65 72 20 61 20 62 69  |eck whether a bi|
00001850  74 20 69 73 20 73 65 74  2c 20 73 6f 20 69 74 20  |t is set, so it |
00001860  6c 6f 6f 6b 73 0d 6c 69  6b 65 20 74 68 69 73 20  |looks.like this |
00001870  69 66 20 62 6f 74 68 20  6e 75 6d 62 65 72 73 20  |if both numbers |
00001880  61 6e 64 20 74 68 65 69  72 20 70 72 6f 64 75 63  |and their produc|
00001890  74 20 61 72 65 20 6c 65  73 73 20 74 68 61 6e 20  |t are less than |
000018a0  61 0d 62 79 74 65 20 69  6e 20 73 69 7a 65 3a 0d  |a.byte in size:.|
000018b0  0d 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |.               |
000018c0  20 2e 6c 6f 6f 70 0d 20  20 20 20 20 20 20 20 20  | .loop.         |
000018d0  20 20 20 20 20 20 20 4c  53 52 20 6d 75 6c 74 69  |       LSR multi|
000018e0  70 6c 69 65 72 0d 20 20  20 20 20 20 20 20 20 20  |plier.          |
000018f0  20 20 20 20 20 20 42 43  43 20 6e 6f 5f 61 64 64  |      BCC no_add|
00001900  0d 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |.               |
00001910  20 43 4c 43 0d 20 20 20  20 20 20 20 20 20 20 20  | CLC.           |
00001920  20 20 20 20 20 4c 44 41  20 6d 75 6c 74 69 70 6c  |     LDA multipl|
00001930  69 63 61 6e 64 0d 20 20  20 20 20 20 20 20 20 20  |icand.          |
00001940  20 20 20 20 20 20 41 44  43 20 70 70 77 73 0d 20  |      ADC ppws. |
00001950  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 53  |               S|
00001960  54 41 20 70 70 77 73 0d  20 20 20 20 20 20 20 20  |TA ppws.        |
00001970  20 20 20 20 20 20 20 20  2e 6e 6f 5f 61 64 64 0d  |        .no_add.|
00001980  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00001990  42 45 51 20 65 78 69 74  0d 20 20 20 20 20 20 20  |BEQ exit.       |
000019a0  20 20 20 20 20 20 20 20  20 41 53 4c 20 6d 75 6c  |         ASL mul|
000019b0  74 69 70 6c 69 63 61 6e  64 0d 20 20 20 20 20 20  |tiplicand.      |
000019c0  20 20 20 20 20 20 20 20  20 20 4a 4d 50 20 6c 6f  |          JMP lo|
000019d0  6f 70 0d 0d 0d 49 66 20  79 6f 75 72 20 70 72 6f  |op...If your pro|
000019e0  64 75 63 74 20 69 73 20  6c 61 72 67 65 72 20 74  |duct is larger t|
000019f0  68 61 6e 20 61 20 62 79  74 65 20 28 61 73 20 69  |han a byte (as i|
00001a00  74 20 77 61 73 20 69 6e  20 6f 75 72 20 6c 6f 6e  |t was in our lon|
00001a10  67 0d 6d 75 6c 74 69 70  6c 69 63 61 74 69 6f 6e  |g.multiplication|
00001a20  20 65 78 61 6d 70 6c 65  20 61 62 6f 76 65 29 20  | example above) |
00001a30  74 68 65 6e 20 79 6f 75  20 73 69 6d 70 6c 79 20  |then you simply |
00001a40  68 61 76 65 20 74 6f 20  61 64 64 0d 7a 65 72 6f  |have to add.zero|
00001a50  20 28 77 69 74 68 20 63  61 72 72 79 29 20 74 6f  | (with carry) to|
00001a60  20 74 68 65 20 68 69 67  68 20 62 79 74 65 2c 20  | the high byte, |
00001a70  61 66 74 65 72 20 79 6f  75 20 68 61 76 65 20 61  |after you have a|
00001a80  64 64 65 64 20 74 68 65  0d 6c 6f 77 20 62 79 74  |dded the.low byt|
00001a90  65 73 20 74 6f 67 65 74  68 65 72 2e 20 20 4c 65  |es together.  Le|
00001aa0  74 27 73 20 73 61 79 20  74 68 61 74 20 74 68 65  |t's say that the|
00001ab0  20 70 61 72 74 69 61 6c  20 70 72 6f 64 75 63 74  | partial product|
00001ac0  20 77 61 73 0d 69 6e 20  70 70 77 73 20 61 6e 64  | was.in ppws and|
00001ad0  20 70 70 77 73 2b 31 20  61 6e 64 20 74 68 61 74  | ppws+1 and that|
00001ae0  20 79 6f 75 20 77 65 72  65 20 61 64 64 69 6e 67  | you were adding|
00001af0  20 69 6e 20 61 20 76 61  6c 75 65 20 66 72 6f 6d  | in a value from|
00001b00  0d 74 68 65 20 61 63 63  75 6d 75 6c 61 74 6f 72  |.the accumulator|
00001b10  2e 20 20 49 74 20 77 6f  75 6c 64 20 6c 6f 6f 6b  |.  It would look|
00001b20  20 6c 69 6b 65 20 74 68  69 73 3a 20 0d 0d 20 20  | like this: ..  |
00001b30  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00001b40  20 43 4c 43 0d 20 20 20  20 20 20 20 20 20 20 20  | CLC.           |
00001b50  20 20 20 20 20 20 20 20  41 44 43 20 70 70 77 73  |        ADC ppws|
00001b60  0d 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |.               |
00001b70  20 20 20 20 53 54 41 20  70 70 77 73 0d 20 20 20  |    STA ppws.   |
00001b80  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00001b90  4c 44 41 20 23 30 0d 20  20 20 20 20 20 20 20 20  |LDA #0.         |
00001ba0  20 20 20 20 20 20 20 20  20 20 41 44 43 20 70 70  |          ADC pp|
00001bb0  77 73 2b 31 0d 20 20 20  20 20 20 20 20 20 20 20  |ws+1.           |
00001bc0  20 20 20 20 20 20 20 20  53 54 41 20 70 70 77 73  |        STA ppws|
00001bd0  2b 31 0d 0d 4e 6f 74 65  20 74 68 61 74 20 77 65  |+1..Note that we|
00001be0  20 64 6f 6e 27 74 20 63  6c 65 61 72 20 74 68 65  | don't clear the|
00001bf0  20 63 61 72 72 79 20 62  65 66 6f 72 65 20 74 68  | carry before th|
00001c00  65 20 73 65 63 6f 6e 64  0d 61 64 64 69 74 69 6f  |e second.additio|
00001c10  6e 2e 0d 0d 49 74 20 69  73 20 70 6f 73 73 69 62  |n...It is possib|
00001c20  6c 65 20 74 6f 20 68 6f  6c 64 20 74 68 65 20 6d  |le to hold the m|
00001c30  75 6c 74 69 70 6c 69 65  72 20 69 6e 20 74 68 65  |ultiplier in the|
00001c40  20 61 63 63 75 6d 75 6c  61 74 6f 72 0d 28 74 68  | accumulator.(th|
00001c50  69 73 20 69 73 20 64 6f  6e 65 20 69 6e 20 74 68  |is is done in th|
00001c60  65 20 70 72 6f 67 72 61  6d 20 6d 6f 64 75 6c 65  |e program module|
00001c70  29 20 62 75 74 20 69 66  20 65 69 74 68 65 72 0d  |) but if either.|
00001c80  6d 75 6c 74 69 70 6c 69  65 72 20 6f 72 20 6d 75  |multiplier or mu|
00001c90  6c 74 69 70 6c 69 63 61  6e 64 20 61 72 65 20 67  |ltiplicand are g|
00001ca0  72 65 61 74 65 72 20 74  68 61 6e 20 32 35 35 20  |reater than 255 |
00001cb0  74 68 65 6e 0d 6d 75 6c  74 69 2d 62 79 74 65 20  |then.multi-byte |
00001cc0  72 6f 74 61 74 69 6e 67  20 61 6e 64 20 6d 75 6c  |rotating and mul|
00001cd0  74 69 2d 62 79 74 65 20  61 64 64 69 74 69 6f 6e  |ti-byte addition|
00001ce0  20 6d 75 73 74 20 62 65  20 75 73 65 64 2e 20 0d  | must be used. .|
00001cf0  4d 75 6c 74 69 2d 62 79  74 65 20 61 64 64 69 74  |Multi-byte addit|
00001d00  69 6f 6e 20 49 20 68 61  76 65 20 61 6c 72 65 61  |ion I have alrea|
00001d10  64 79 20 63 6f 76 65 72  65 64 2e 20 20 4d 75 6c  |dy covered.  Mul|
00001d20  74 69 2d 62 79 74 65 0d  72 6f 74 61 74 69 6e 67  |ti-byte.rotating|
00001d30  20 69 73 20 73 74 72 61  69 67 68 74 66 6f 72 77  | is straightforw|
00001d40  61 72 64 20 65 6e 6f 75  67 68 2e 20 20 42 61 73  |ard enough.  Bas|
00001d50  69 63 61 6c 6c 79 20 79  6f 75 72 20 66 69 72 73  |ically your firs|
00001d60  74 0d 72 6f 74 61 74 69  6f 6e 20 69 73 20 65 69  |t.rotation is ei|
00001d70  74 68 65 72 20 61 6e 20  41 53 4c 20 6f 72 20 61  |ther an ASL or a|
00001d80  6e 20 4c 53 52 20 62 65  63 61 75 73 65 20 79 6f  |n LSR because yo|
00001d90  75 20 64 6f 20 6e 6f 74  20 77 61 6e 74 0d 74 6f  |u do not want.to|
00001da0  20 62 72 69 6e 67 20 69  6e 20 74 68 65 20 63 61  | bring in the ca|
00001db0  72 72 79 20 66 6c 61 67  20 61 74 20 66 69 72 73  |rry flag at firs|
00001dc0  74 2c 20 62 75 74 20 6f  74 68 65 72 20 72 6f 74  |t, but other rot|
00001dd0  61 74 69 6f 6e 73 20 61  72 65 0d 52 4f 4c 20 6f  |ations are.ROL o|
00001de0  72 20 52 4f 52 20 73 6f  20 74 68 61 74 20 79 6f  |r ROR so that yo|
00001df0  75 20 63 61 6e 20 75 73  65 20 74 68 65 20 63 61  |u can use the ca|
00001e00  72 72 79 20 66 6c 61 67  20 74 6f 20 63 61 72 72  |rry flag to carr|
00001e10  79 0d 62 65 74 77 65 65  6e 20 62 79 74 65 73 2e  |y.between bytes.|
00001e20  20 20 48 65 72 65 20 69  73 20 61 6e 20 65 78 61  |  Here is an exa|
00001e30  6d 70 6c 65 20 77 69 74  68 20 73 6f 6d 65 20 6d  |mple with some m|
00001e40  65 6d 6f 72 79 20 63 61  6c 6c 65 64 0d 6d 65 6d  |emory called.mem|
00001e50  20 74 6f 20 6d 65 6d 2b  33 20 62 65 69 6e 67 20  | to mem+3 being |
00001e60  72 6f 74 61 74 65 64 20  6c 65 66 74 2c 20 77 68  |rotated left, wh|
00001e70  69 63 68 20 6d 75 6c 74  69 70 6c 69 65 73 20 69  |ich multiplies i|
00001e80  74 73 20 76 61 6c 75 65  0d 62 79 20 74 77 6f 2e  |ts value.by two.|
00001e90  0d 0d 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |..              |
00001ea0  20 20 20 20 20 20 41 53  4c 20 6d 65 6d 0d 20 20  |      ASL mem.  |
00001eb0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00001ec0  20 20 52 4f 4c 20 6d 65  6d 2b 31 0d 20 20 20 20  |  ROL mem+1.    |
00001ed0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00001ee0  52 4f 4c 20 6d 65 6d 2b  32 0d 20 20 20 20 20 20  |ROL mem+2.      |
00001ef0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 52 4f  |              RO|
00001f00  4c 20 6d 65 6d 2b 33 0d  0d 54 68 65 20 6d 75 6c  |L mem+3..The mul|
00001f10  74 69 70 6c 69 63 61 74  69 6f 6e 20 69 6e 20 42  |tiplication in B|
00001f20  2f 6f 73 62 31 32 20 69  73 20 61 20 63 6f 6d 70  |/osb12 is a comp|
00001f30  72 6f 6d 69 73 65 20 69  6e 20 74 68 61 74 20 74  |romise in that t|
00001f40  68 65 0d 6d 75 6c 74 69  70 6c 69 63 61 6e 64 20  |he.multiplicand |
00001f50  69 73 20 34 20 62 79 74  65 73 20 6c 6f 6e 67 20  |is 4 bytes long |
00001f60  62 75 74 20 74 68 65 20  6d 75 6c 74 69 70 6c 69  |but the multipli|
00001f70  65 72 20 69 73 20 61 20  73 69 6e 67 6c 65 0d 62  |er is a single.b|
00001f80  79 74 65 20 28 75 73 75  61 6c 6c 79 20 31 30 29  |yte (usually 10)|
00001f90  2e 20 20 49 20 68 6f 70  65 20 74 68 69 73 20 77  |.  I hope this w|
00001fa0  69 6c 6c 20 6d 61 6b 65  20 74 68 65 20 74 65 63  |ill make the tec|
00001fb0  68 6e 69 71 75 65 0d 63  6c 65 61 72 2c 20 6e 65  |hnique.clear, ne|
00001fc0  78 74 20 74 69 6d 65 20  49 20 77 69 6c 6c 20 62  |xt time I will b|
00001fd0  72 65 61 6b 20 66 72 6f  6d 20 69 6e 70 75 74 20  |reak from input |
00001fe0  61 6e 64 20 6f 75 74 70  75 74 20 6f 66 0d 6e 75  |and output of.nu|
00001ff0  6d 62 65 72 73 20 74 6f  20 67 69 76 65 20 79 6f  |mbers to give yo|
00002000  75 20 61 20 67 65 6e 65  72 61 6c 20 6d 75 6c 74  |u a general mult|
00002010  69 2d 62 79 74 65 20 6d  75 6c 74 69 70 6c 69 63  |i-byte multiplic|
00002020  61 74 69 6f 6e 0d 72 6f  75 74 69 6e 65 20 77 68  |ation.routine wh|
00002030  69 63 68 20 77 65 20 63  61 6e 20 75 73 65 20 6c  |ich we can use l|
00002040  61 74 65 72 20 77 68 65  6e 20 77 65 20 63 6f 6d  |ater when we com|
00002050  65 20 6f 6e 20 74 6f 20  6e 75 6d 62 65 72 73 0d  |e on to numbers.|
00002060  77 69 74 68 20 61 20 64  65 63 69 6d 61 6c 20 70  |with a decimal p|
00002070  6f 69 6e 74 2e 0d 0d 48  61 76 69 6e 67 20 64 69  |oint...Having di|
00002080  73 63 75 73 73 65 64 20  74 68 65 20 74 65 63 68  |scussed the tech|
00002090  6e 69 71 75 65 73 20 6c  65 74 27 73 20 72 75 6e  |niques let's run|
000020a0  20 74 68 72 6f 75 67 68  20 74 68 65 0d 70 72 6f  | through the.pro|
000020b0  67 72 61 6d 20 69 6e 20  74 68 69 73 20 6d 6f 64  |gram in this mod|
000020c0  75 6c 65 2e 20 20 49 74  20 69 73 20 63 6f 70 69  |ule.  It is copi|
000020d0  6f 75 73 6c 79 20 61 6e  6e 6f 74 61 74 65 64 2c  |ously annotated,|
000020e0  20 77 68 69 63 68 0d 6d  61 6b 65 73 20 69 74 20  | which.makes it |
000020f0  61 20 62 69 74 20 6c 6f  6e 67 2e 20 20 49 66 20  |a bit long.  If |
00002100  79 6f 75 20 68 61 76 65  20 61 20 6d 69 63 72 6f  |you have a micro|
00002110  20 77 69 74 68 6f 75 74  20 73 65 63 6f 6e 64 0d  | without second.|
00002120  70 72 6f 63 65 73 73 6f  72 20 6f 72 20 73 68 61  |processor or sha|
00002130  64 6f 77 20 73 63 72 65  65 6e 20 79 6f 75 20 77  |dow screen you w|
00002140  69 6c 6c 20 68 61 76 65  20 74 6f 20 67 6f 20 69  |ill have to go i|
00002150  6e 74 6f 20 6d 6f 64 65  20 37 0d 74 6f 20 72 75  |nto mode 7.to ru|
00002160  6e 20 69 74 20 61 6c 74  68 6f 75 67 68 20 69 74  |n it although it|
00002170  20 69 73 20 62 65 73 74  20 64 69 73 70 6c 61 79  | is best display|
00002180  65 64 20 61 73 20 61 20  6c 69 73 74 69 6e 67 20  |ed as a listing |
00002190  69 6e 20 6d 6f 64 65 0d  33 2e 0d 0d 49 6e 20 73  |in mode.3...In s|
000021a0  65 74 74 69 6e 67 20 75  70 20 42 2f 6f 73 62 31  |etting up B/osb1|
000021b0  32 20 49 20 68 61 76 65  20 64 65 63 69 64 65 64  |2 I have decided|
000021c0  20 6e 6f 74 20 74 6f 20  65 6e 61 62 6c 65 20 74  | not to enable t|
000021d0  68 65 0d 61 73 73 65 6d  62 6c 79 20 6c 69 73 74  |he.assembly list|
000021e0  69 6e 67 20 77 68 69 63  68 20 69 73 20 77 68 79  |ing which is why|
000021f0  20 6c 69 6e 65 20 31 39  30 20 67 6f 65 73 20 74  | line 190 goes t|
00002200  6f 20 32 20 69 6e 73 74  65 61 64 20 6f 66 0d 33  |o 2 instead of.3|
00002210  2e 20 20 54 68 65 20 66  69 6e 61 6c 20 63 6f 64  |.  The final cod|
00002220  65 20 74 61 6b 65 73 20  75 70 20 6f 76 65 72 20  |e takes up over |
00002230  35 30 30 20 62 79 74 65  73 20 61 6e 64 20 49 20  |500 bytes and I |
00002240  68 61 76 65 0d 72 65 73  65 72 76 65 64 20 26 32  |have.reserved &2|
00002250  35 30 20 62 79 74 65 73  20 6f 66 20 6d 65 6d 6f  |50 bytes of memo|
00002260  72 79 20 69 6e 20 6c 69  6e 65 20 31 37 30 2e 20  |ry in line 170. |
00002270  20 54 6f 20 68 65 6c 70  20 74 65 73 74 69 6e 67  | To help testing|
00002280  0d 66 75 6e 63 74 69 6f  6e 20 6b 65 79 20 32 20  |.function key 2 |
00002290  69 6e 70 75 74 73 20 74  68 65 20 6c 61 72 67 65  |inputs the large|
000022a0  73 74 20 70 6f 73 69 74  69 76 65 20 61 6e 64 20  |st positive and |
000022b0  6e 65 67 61 74 69 76 65  0d 6e 75 6d 62 65 72 73  |negative.numbers|
000022c0  2e 0d 0d 54 68 65 20 63  68 61 6e 67 65 73 20 74  |...The changes t|
000022d0  6f 20 74 68 65 20 69 6e  70 75 74 20 72 6f 75 74  |o the input rout|
000022e0  69 6e 65 20 66 72 6f 6d  20 6c 61 73 74 20 74 69  |ine from last ti|
000022f0  6d 65 20 61 72 65 20 61  73 0d 66 6f 6c 6c 6f 77  |me are as.follow|
00002300  73 3a 0d 0d 54 68 65 20  62 75 66 66 65 72 20 73  |s:..The buffer s|
00002310  69 7a 65 20 69 73 20 69  6e 63 72 65 61 73 65 64  |ize is increased|
00002320  20 61 73 20 31 31 20 64  69 67 69 74 20 6e 75 6d  | as 11 digit num|
00002330  62 65 72 73 2c 20 69 6e  63 6c 75 64 69 6e 67 0d  |bers, including.|
00002340  61 20 6d 69 6e 75 73 20  73 69 67 6e 2c 20 63 61  |a minus sign, ca|
00002350  6e 20 62 65 20 61 63 63  65 70 74 65 64 2e 20 20  |n be accepted.  |
00002360  41 20 70 6c 75 73 20 73  69 67 6e 20 68 61 73 20  |A plus sign has |
00002370  62 65 65 6e 20 61 64 64  65 64 0d 74 6f 20 74 68  |been added.to th|
00002380  65 20 76 61 6c 69 64 20  63 68 61 72 61 63 74 65  |e valid characte|
00002390  72 20 6c 69 73 74 2e 20  20 54 68 65 20 7a 65 72  |r list.  The zer|
000023a0  6f 20 66 6c 61 67 20 69  73 20 73 65 74 20 6f 6e  |o flag is set on|
000023b0  20 65 78 69 74 0d 69 66  20 74 68 65 20 73 74 72  | exit.if the str|
000023c0  69 6e 67 20 69 73 20 6f  66 20 7a 65 72 6f 20 6c  |ing is of zero l|
000023d0  65 6e 67 74 68 2e 0d 0d  54 68 65 20 6d 61 69 6e  |ength...The main|
000023e0  20 62 6f 64 79 20 6f 66  20 74 68 65 20 63 6f 64  | body of the cod|
000023f0  65 2c 20 66 72 6f 6d 20  6c 69 6e 65 20 32 36 30  |e, from line 260|
00002400  20 74 6f 20 6c 69 6e 65  20 34 30 30 2c 20 63 61  | to line 400, ca|
00002410  6c 6c 73 0d 74 77 6f 20  73 75 62 72 6f 75 74 69  |lls.two subrouti|
00002420  6e 65 73 2c 20 73 75 62  6a 65 63 74 20 74 6f 20  |nes, subject to |
00002430  74 72 61 70 70 69 6e 67  20 45 53 43 41 50 45 73  |trapping ESCAPEs|
00002440  20 61 6e 64 20 7a 65 72  6f 20 6c 65 6e 67 74 68  | and zero length|
00002450  0d 73 74 72 69 6e 67 73  20 28 6c 69 6e 65 73 20  |.strings (lines |
00002460  33 37 30 20 61 6e 64 20  33 38 30 29 2e 20 20 54  |370 and 380).  T|
00002470  68 65 20 73 75 62 72 6f  75 74 69 6e 65 20 73 74  |he subroutine st|
00002480  61 72 74 69 6e 67 20 61  74 0d 27 69 6e 70 75 74  |arting at.'input|
00002490  5f 63 68 61 72 61 63 74  65 72 27 20 69 73 20 65  |_character' is e|
000024a0  73 73 65 6e 74 69 61 6c  6c 79 20 74 68 61 74 20  |ssentially that |
000024b0  66 72 6f 6d 20 74 68 65  20 6c 61 73 74 20 6d 6f  |from the last mo|
000024c0  64 75 6c 65 2e 0d 54 68  65 20 73 75 62 72 6f 75  |dule..The subrou|
000024d0  74 69 6e 65 20 61 74 20  27 63 6f 6e 76 65 72 74  |tine at 'convert|
000024e0  5f 41 53 43 49 49 5f 74  6f 5f 62 69 6e 61 72 79  |_ASCII_to_binary|
000024f0  27 20 74 61 6b 65 73 20  74 68 65 20 73 74 72 69  |' takes the stri|
00002500  6e 67 0d 69 6e 20 74 68  65 20 69 6e 70 75 74 20  |ng.in the input |
00002510  62 75 66 66 65 72 20 61  6e 64 20 63 6f 6e 76 65  |buffer and conve|
00002520  72 74 73 20 69 74 20 69  6e 74 6f 20 61 20 34 20  |rts it into a 4 |
00002530  62 79 74 65 20 62 69 6e  61 72 79 0d 6e 75 6d 62  |byte binary.numb|
00002540  65 72 20 61 6e 64 20 6c  65 61 76 65 73 20 74 68  |er and leaves th|
00002550  65 20 72 65 73 75 6c 74  20 69 6e 20 34 20 62 79  |e result in 4 by|
00002560  74 65 73 20 6f 66 20 6d  65 6d 6f 72 79 20 73 74  |tes of memory st|
00002570  61 72 74 69 6e 67 0d 61  74 20 27 64 69 67 69 74  |arting.at 'digit|
00002580  5f 77 73 27 2e 0d 0d 54  68 65 20 63 6f 6e 76 65  |_ws'...The conve|
00002590  72 73 69 6f 6e 20 73 75  62 72 6f 75 74 69 6e 65  |rsion subroutine|
000025a0  20 69 73 20 61 74 20 6c  69 6e 65 20 31 35 35 30  | is at line 1550|
000025b0  2e 20 20 4e 6f 74 65 20  74 68 61 74 20 74 68 65  |.  Note that the|
000025c0  0d 77 6f 72 6b 73 70 61  63 65 20 6d 75 73 74 20  |.workspace must |
000025d0  62 65 20 63 6c 65 61 72  65 64 20 62 65 66 6f 72  |be cleared befor|
000025e0  65 20 75 73 65 2e 20 20  49 20 68 61 76 65 20 62  |e use.  I have b|
000025f0  65 65 6e 20 6b 6e 6f 77  6e 20 74 6f 0d 66 6f 72  |een known to.for|
00002600  67 65 74 20 74 6f 20 64  6f 20 74 68 69 73 20 77  |get to do this w|
00002610  69 74 68 20 73 69 6c 6c  79 20 72 65 73 75 6c 74  |ith silly result|
00002620  73 21 20 20 54 68 65 20  73 69 67 6e 20 66 6c 61  |s!  The sign fla|
00002630  67 20 69 73 0d 63 6c 65  61 72 65 64 20 61 6c 73  |g is.cleared als|
00002640  6f 2e 0d 0d 57 65 20 67  6f 20 74 68 72 6f 75 67  |o...We go throug|
00002650  68 20 74 68 65 20 73 74  72 69 6e 67 20 69 6e 20  |h the string in |
00002660  74 68 65 20 69 6e 70 75  74 20 62 75 66 66 65 72  |the input buffer|
00002670  20 61 20 63 68 61 72 61  63 74 65 72 20 61 74 0d  | a character at.|
00002680  61 20 74 69 6d 65 20 75  73 69 6e 67 20 58 20 61  |a time using X a|
00002690  73 20 61 20 63 6f 75 6e  74 65 72 2f 69 6e 64 65  |s a counter/inde|
000026a0  78 2e 20 20 49 66 20 61  20 63 68 61 72 61 63 74  |x.  If a charact|
000026b0  65 72 20 69 73 20 6e 6f  74 0d 62 65 74 77 65 65  |er is not.betwee|
000026c0  6e 20 30 20 61 6e 64 20  39 20 77 65 20 62 72 61  |n 0 and 9 we bra|
000026d0  6e 63 68 20 74 6f 20 27  6e 6f 74 5f 6e 75 6d 62  |nch to 'not_numb|
000026e0  65 72 27 2e 20 20 54 68  65 72 65 2c 20 69 66 20  |er'.  There, if |
000026f0  77 65 20 61 72 65 0d 6c  6f 6f 6b 69 6e 67 20 61  |we are.looking a|
00002700  74 20 74 68 65 20 66 69  72 73 74 20 63 68 61 72  |t the first char|
00002710  61 63 74 65 72 20 69 6e  20 74 68 65 20 73 74 72  |acter in the str|
00002720  69 6e 67 20 77 65 20 63  68 65 63 6b 20 66 6f 72  |ing we check for|
00002730  20 61 0d 2b 20 6f 72 20  61 20 2d 20 73 69 67 6e  | a.+ or a - sign|
00002740  20 61 6e 64 20 73 65 74  20 74 68 65 20 73 69 67  | and set the sig|
00002750  6e 20 66 6c 61 67 20 69  66 20 69 74 20 69 73 20  |n flag if it is |
00002760  61 20 6d 69 6e 75 73 2e  20 20 41 20 2b 0d 69 73  |a minus.  A +.is|
00002770  20 6a 75 73 74 20 69 67  6e 6f 72 65 64 2e 20 20  | just ignored.  |
00002780  41 6e 79 20 6f 74 68 65  72 20 63 68 61 72 61 63  |Any other charac|
00002790  74 65 72 20 77 6f 75 6c  64 20 63 61 75 73 65 20  |ter would cause |
000027a0  61 6e 0d 27 69 6e 76 61  6c 69 64 20 6e 75 6d 62  |an.'invalid numb|
000027b0  65 72 27 20 65 72 72 6f  72 20 62 75 74 20 74 68  |er' error but th|
000027c0  69 73 20 73 68 6f 75 6c  64 20 6e 6f 74 20 6f 63  |is should not oc|
000027d0  63 75 72 20 68 65 72 65  20 61 73 20 74 68 65 0d  |cur here as the.|
000027e0  69 6e 70 75 74 20 72 6f  75 74 69 6e 65 20 66 69  |input routine fi|
000027f0  6c 74 65 72 73 20 6f 74  68 65 72 20 63 68 61 72  |lters other char|
00002800  61 63 74 65 72 73 20 6f  75 74 2e 20 20 41 20 6e  |acters out.  A n|
00002810  6f 6e 20 6e 75 6d 65 72  69 63 0d 63 68 61 72 61  |on numeric.chara|
00002820  63 74 65 72 20 61 6e 79  77 68 65 72 65 20 65 6c  |cter anywhere el|
00002830  73 65 20 69 6e 20 74 68  65 20 73 74 72 69 6e 67  |se in the string|
00002840  20 69 73 20 63 6f 75 6e  74 65 64 20 61 73 0d 74  | is counted as.t|
00002850  65 72 6d 69 6e 61 74 69  6e 67 20 74 68 65 20 73  |erminating the s|
00002860  74 72 69 6e 67 2e 20 20  54 68 69 73 20 74 65 72  |tring.  This ter|
00002870  6d 69 6e 61 74 6f 72 20  77 69 6c 6c 20 75 73 75  |minator will usu|
00002880  61 6c 6c 79 20 62 65 20  61 0d 63 61 72 72 69 61  |ally be a.carria|
00002890  67 65 20 72 65 74 75 72  6e 2e 0d 0d 54 68 65 72  |ge return...Ther|
000028a0  65 20 77 65 72 65 20 74  77 6f 20 70 6f 73 73 69  |e were two possi|
000028b0  62 6c 65 20 77 61 79 73  20 6f 66 20 64 65 61 6c  |ble ways of deal|
000028c0  69 6e 67 20 77 69 74 68  20 61 20 6e 65 67 61 74  |ing with a negat|
000028d0  69 76 65 0d 6e 75 6d 62  65 72 2e 20 20 49 20 63  |ive.number.  I c|
000028e0  6f 75 6c 64 20 74 75 72  6e 20 74 68 65 20 6e 75  |ould turn the nu|
000028f0  6d 62 65 72 20 6e 65 67  61 74 69 76 65 20 61 66  |mber negative af|
00002900  74 65 72 20 69 74 0d 77  61 73 20 65 6e 74 65 72  |ter it.was enter|
00002910  65 64 20 6f 72 20 49 20  63 6f 75 6c 64 20 61 63  |ed or I could ac|
00002920  74 75 61 6c 6c 79 20 62  75 69 6c 64 20 75 70 20  |tually build up |
00002930  61 20 6e 65 67 61 74 69  76 65 20 6e 75 6d 62 65  |a negative numbe|
00002940  72 0d 64 75 72 69 6e 67  20 74 68 65 20 6e 75 6d  |r.during the num|
00002950  62 65 72 20 65 6e 74 72  79 20 72 6f 75 74 69 6e  |ber entry routin|
00002960  65 2e 20 20 49 6e 20 74  68 65 20 65 6e 64 20 49  |e.  In the end I|
00002970  20 64 65 63 69 64 65 64  20 74 6f 0d 63 6f 6e 76  | decided to.conv|
00002980  65 72 74 20 61 66 74 65  72 20 65 6e 74 72 79 2c  |ert after entry,|
00002990  20 73 69 6e 63 65 20 74  68 69 73 20 6d 61 6b 65  | since this make|
000029a0  73 20 74 68 65 20 63 6f  64 65 20 73 69 6d 70 6c  |s the code simpl|
000029b0  65 72 20 61 6e 64 0d 68  61 73 20 6f 6e 6c 79 20  |er and.has only |
000029c0  74 68 65 20 73 6c 69 67  68 74 20 73 69 64 65 20  |the slight side |
000029d0  65 66 66 65 63 74 20 6f  66 20 69 6e 76 61 6c 69  |effect of invali|
000029e0  64 61 74 69 6e 67 20 74  68 65 20 6c 61 72 67 65  |dating the large|
000029f0  73 74 0d 6e 65 67 61 74  69 76 65 20 6e 75 6d 62  |st.negative numb|
00002a00  65 72 20 28 26 38 30 30  30 30 30 30 30 29 20 61  |er (&80000000) a|
00002a10  73 20 49 20 6d 65 6e 74  69 6f 6e 65 64 20 62 65  |s I mentioned be|
00002a20  66 6f 72 65 2e 20 20 41  66 74 65 72 0d 74 68 65  |fore.  After.the|
00002a30  20 73 74 72 69 6e 67 20  68 61 73 20 62 65 65 6e  | string has been|
00002a40  20 74 65 72 6d 69 6e 61  74 65 64 2c 20 61 6e 64  | terminated, and|
00002a50  20 74 68 65 20 63 6f 64  65 20 72 65 61 63 68 65  | the code reache|
00002a60  73 20 74 68 65 0d 61 64  64 72 65 73 73 20 27 65  |s the.address 'e|
00002a70  78 69 74 5f 6e 75 6d 62  65 72 5f 63 6f 6e 76 65  |xit_number_conve|
00002a80  72 73 69 6f 6e 27 20 77  65 20 63 68 65 63 6b 20  |rsion' we check |
00002a90  74 6f 20 73 65 65 20 69  66 20 74 68 65 20 73 69  |to see if the si|
00002aa0  67 6e 0d 66 6c 61 67 20  69 73 20 73 65 74 2e 20  |gn.flag is set. |
00002ab0  20 49 66 20 69 74 20 69  73 20 74 68 65 20 6e 75  | If it is the nu|
00002ac0  6d 62 65 72 20 69 73 20  6e 65 67 61 74 69 76 65  |mber is negative|
00002ad0  20 61 6e 64 20 77 65 20  73 69 6d 70 6c 79 0d 73  | and we simply.s|
00002ae0  75 62 74 72 61 63 74 20  69 74 20 66 72 6f 6d 20  |ubtract it from |
00002af0  7a 65 72 6f 20 28 6c 69  6e 65 73 20 32 31 36 30  |zero (lines 2160|
00002b00  20 2d 20 32 32 38 30 29  2e 0d 0d 49 20 68 61 76  | - 2280)...I hav|
00002b10  65 20 70 75 74 20 74 68  65 20 6e 75 6d 65 72 69  |e put the numeri|
00002b20  63 61 6c 20 62 61 73 65  20 69 6e 20 6d 65 6d 6f  |cal base in memo|
00002b30  72 79 20 61 73 20 61 20  76 61 72 69 61 62 6c 65  |ry as a variable|
00002b40  20 74 6f 0d 6d 61 6b 65  20 63 6f 6e 76 65 72 73  | to.make convers|
00002b50  69 6f 6e 20 6f 66 20 74  68 69 73 20 72 6f 75 74  |ion of this rout|
00002b60  69 6e 65 20 74 6f 20 6f  74 68 65 72 20 62 61 73  |ine to other bas|
00002b70  65 73 20 6d 6f 72 65 0d  73 74 72 61 69 67 68 74  |es more.straight|
00002b80  66 6f 72 77 61 72 64 2e  20 20 59 6f 75 20 73 68  |forward.  You sh|
00002b90  6f 75 6c 64 20 74 72 79  20 74 6f 20 63 6f 6e 76  |ould try to conv|
00002ba0  65 72 74 20 74 6f 20 62  61 73 65 20 38 2c 20 6f  |ert to base 8, o|
00002bb0  72 0d 65 76 65 6e 20 31  36 2c 20 74 6f 20 63 68  |r.even 16, to ch|
00002bc0  65 63 6b 20 69 66 20 79  6f 75 20 75 6e 64 65 72  |eck if you under|
00002bd0  73 74 61 6e 64 20 68 6f  77 20 69 74 20 77 6f 72  |stand how it wor|
00002be0  6b 73 20 61 6e 64 20 74  68 61 74 20 49 0d 68 61  |ks and that I.ha|
00002bf0  76 65 20 65 78 70 6c 61  69 6e 65 64 20 69 74 20  |ve explained it |
00002c00  63 6c 65 61 72 6c 79 20  65 6e 6f 75 67 68 2e 20  |clearly enough. |
00002c10  20 49 6e 20 65 61 63 68  20 63 61 73 65 2c 20 6f  | In each case, o|
00002c20  66 20 63 6f 75 72 73 65  2c 0d 79 6f 75 20 77 69  |f course,.you wi|
00002c30  6c 6c 20 6e 65 65 64 20  64 69 66 66 65 72 65 6e  |ll need differen|
00002c40  74 20 63 68 61 72 61 63  74 65 72 73 2e 20 20 30  |t characters.  0|
00002c50  2d 37 20 66 6f 72 20 6f  63 74 61 6c 20 61 6e 64  |-7 for octal and|
00002c60  20 30 2d 39 0d 41 2d 46  20 66 6f 72 20 68 65 78  | 0-9.A-F for hex|
00002c70  61 64 65 63 69 6d 61 6c  2e 0d 0d 54 6f 20 70 72  |adecimal...To pr|
00002c80  6f 63 65 73 73 20 61 20  64 69 67 69 74 20 77 65  |ocess a digit we|
00002c90  20 66 69 72 73 74 20 73  75 62 74 72 61 63 74 20  | first subtract |
00002ca0  74 68 65 20 41 53 43 49  49 20 76 61 6c 75 65 20  |the ASCII value |
00002cb0  6f 66 20 27 30 27 0d 66  72 6f 6d 20 69 74 20 28  |of '0'.from it (|
00002cc0  34 38 29 20 61 6e 64 20  74 68 65 6e 20 63 61 6c  |48) and then cal|
00002cd0  6c 20 61 20 73 75 62 72  6f 75 74 69 6e 65 20 61  |l a subroutine a|
00002ce0  74 20 27 70 72 6f 63 65  73 73 5f 6e 75 6d 62 65  |t 'process_numbe|
00002cf0  72 27 2e 0d 41 73 20 74  68 65 20 63 6f 6d 6d 65  |r'..As the comme|
00002d00  6e 74 20 73 61 79 73 20  77 65 20 6d 75 6c 74 69  |nt says we multi|
00002d10  70 6c 79 20 74 68 65 20  6e 75 6d 62 65 72 20 68  |ply the number h|
00002d20  65 6c 64 20 69 6e 20 64  69 67 69 74 5f 77 73 0d  |eld in digit_ws.|
00002d30  28 65 74 20 61 6c 29 20  62 79 20 74 68 65 20 62  |(et al) by the b|
00002d40  61 73 65 20 61 6e 64 20  61 64 64 20 74 68 65 20  |ase and add the |
00002d50  6e 65 77 20 64 69 67 69  74 20 28 68 65 6c 64 20  |new digit (held |
00002d60  69 6e 0d 27 61 63 63 75  73 74 6f 72 65 27 20 74  |in.'accustore' t|
00002d70  65 6d 70 6f 72 61 72 69  6c 79 29 20 74 6f 20 70  |emporarily) to p|
00002d80  72 6f 64 75 63 65 20 61  20 6e 65 77 20 70 61 72  |roduce a new par|
00002d90  74 69 61 6c 20 72 65 73  75 6c 74 20 69 6e 0d 64  |tial result in.d|
00002da0  69 67 69 74 5f 77 73 2e  0d 0d 4e 6f 74 65 20 6c  |igit_ws...Note l|
00002db0  69 6e 65 20 32 36 33 30  2e 20 20 48 65 72 65 20  |ine 2630.  Here |
00002dc0  69 73 20 61 6e 20 65 72  72 6f 72 20 74 72 61 70  |is an error trap|
00002dd0  20 74 68 61 74 20 63 61  74 63 68 65 73 20 61 6e  | that catches an|
00002de0  79 0d 6e 75 6d 62 65 72  20 74 68 61 74 20 73 65  |y.number that se|
00002df0  74 73 20 74 68 65 20 74  6f 70 20 62 69 74 20 28  |ts the top bit (|
00002e00  62 65 63 6f 6d 65 73 20  6e 65 67 61 74 69 76 65  |becomes negative|
00002e10  29 20 64 75 72 69 6e 67  20 74 68 69 73 0d 61 64  |) during this.ad|
00002e20  64 69 74 69 6f 6e 2e 20  20 49 66 20 74 68 61 74  |dition.  If that|
00002e30  20 68 61 70 70 65 6e 73  20 74 68 65 20 6e 75 6d  | happens the num|
00002e40  62 65 72 20 68 61 73 20  6f 76 65 72 66 6c 6f 77  |ber has overflow|
00002e50  65 64 20 34 0d 62 79 74  65 73 2e 20 20 54 68 69  |ed 4.bytes.  Thi|
00002e60  73 20 69 73 20 61 6c 73  6f 20 64 6f 6e 65 20 61  |s is also done a|
00002e70  74 20 6c 69 6e 65 20 33  30 35 30 2e 20 20 49 20  |t line 3050.  I |
00002e80  68 61 76 65 20 67 69 76  65 6e 20 74 68 65 0d 61  |have given the.a|
00002e90  64 64 20 61 6e 64 20 72  6f 74 61 74 65 20 65 72  |dd and rotate er|
00002ea0  72 6f 72 20 74 72 61 70  73 20 64 69 66 66 65 72  |ror traps differ|
00002eb0  65 6e 74 20 6d 65 73 73  61 67 65 73 20 73 6f 20  |ent messages so |
00002ec0  79 6f 75 20 63 61 6e 20  73 65 65 0d 77 68 69 63  |you can see.whic|
00002ed0  68 20 6f 70 65 72 61 74  65 73 20 77 68 65 6e 20  |h operates when |
00002ee0  69 66 20 79 6f 75 20 64  65 6c 69 62 65 72 61 74  |if you deliberat|
00002ef0  65 6c 79 20 65 6e 74 65  72 20 68 75 67 65 20 6e  |ely enter huge n|
00002f00  75 6d 62 65 72 73 2e 20  0d 59 6f 75 20 6d 69 67  |umbers. .You mig|
00002f10  68 74 20 74 72 79 20 64  65 6c 65 74 69 6e 67 20  |ht try deleting |
00002f20  74 68 65 20 74 72 61 70  73 20 61 6e 64 20 73 65  |the traps and se|
00002f30  65 69 6e 67 20 77 68 61  74 20 68 61 70 70 65 6e  |eing what happen|
00002f40  73 2e 20 0d 54 68 65 20  74 72 61 70 20 61 74 20  |s. .The trap at |
00002f50  6c 69 6e 65 20 33 30 35  30 20 69 73 20 61 20 62  |line 3050 is a b|
00002f60  69 74 20 62 65 6c 74 20  61 6e 64 20 62 72 61 63  |it belt and brac|
00002f70  65 73 20 73 69 6e 63 65  20 49 20 61 6d 0d 6e 6f  |es since I am.no|
00002f80  74 20 63 6f 6e 76 69 6e  63 65 64 20 69 74 20 63  |t convinced it c|
00002f90  61 74 63 68 65 73 20 61  6e 79 74 68 69 6e 67 2e  |atches anything.|
00002fa0  0d 0d 57 65 20 73 61 76  65 20 58 20 74 6f 20 74  |..We save X to t|
00002fb0  68 65 20 73 74 61 63 6b  20 62 65 63 61 75 73 65  |he stack because|
00002fc0  20 58 20 69 73 20 68 6f  6c 64 69 6e 67 20 74 68  | X is holding th|
00002fd0  65 20 63 75 72 72 65 6e  74 0d 6f 66 66 73 65 74  |e current.offset|
00002fe0  20 64 6f 77 6e 20 74 68  65 20 69 6e 70 75 74 20  | down the input |
00002ff0  62 75 66 66 65 72 20 61  6e 64 20 73 6f 20 77 65  |buffer and so we|
00003000  20 6d 75 73 74 20 6e 6f  74 20 6c 6f 73 65 20 69  | must not lose i|
00003010  74 2e 0d 0d 54 68 65 20  27 6d 75 6c 74 5f 62 79  |t...The 'mult_by|
00003020  5f 62 61 73 65 27 20 73  75 62 72 6f 75 74 69 6e  |_base' subroutin|
00003030  65 20 75 73 65 73 20 34  20 62 79 74 65 73 20 61  |e uses 4 bytes a|
00003040  74 20 27 70 70 77 73 27  20 61 73 0d 70 61 72 74  |t 'ppws' as.part|
00003050  69 61 6c 20 70 72 6f 64  75 63 74 20 77 6f 72 6b  |ial product work|
00003060  73 70 61 63 65 20 61 6e  64 20 68 6f 6c 64 73 20  |space and holds |
00003070  74 68 65 20 6d 75 6c 74  69 70 6c 69 65 72 20 69  |the multiplier i|
00003080  6e 20 74 68 65 0d 61 63  63 75 6d 75 6c 61 74 6f  |n the.accumulato|
00003090  72 20 6d 6f 73 74 20 6f  66 20 74 68 65 20 74 69  |r most of the ti|
000030a0  6d 65 2e 20 20 49 66 20  61 20 6e 75 6d 62 65 72  |me.  If a number|
000030b0  20 72 6f 74 61 74 65 73  20 74 6f 20 73 65 74 0d  | rotates to set.|
000030c0  74 68 65 20 74 6f 70 20  62 69 74 20 74 68 65 6e  |the top bit then|
000030d0  20 77 65 20 68 61 76 65  20 61 6e 6f 74 68 65 72  | we have another|
000030e0  20 6f 76 65 72 66 6c 6f  77 20 73 69 74 75 61 74  | overflow situat|
000030f0  69 6f 6e 20 61 6e 64 20  74 68 61 74 0d 69 73 20  |ion and that.is |
00003100  74 72 61 70 70 65 64 20  69 6e 20 6c 69 6e 65 20  |trapped in line |
00003110  33 31 36 30 2e 20 20 4f  74 68 65 72 77 69 73 65  |3160.  Otherwise|
00003120  20 74 68 69 73 20 73 65  63 74 69 6f 6e 20 6f 66  | this section of|
00003130  20 63 6f 64 65 20 69 73  0d 61 20 73 74 72 61 69  | code is.a strai|
00003140  67 68 74 66 6f 72 77 61  72 64 20 6d 75 6c 74 69  |ghtforward multi|
00003150  70 6c 69 63 61 74 69 6f  6e 20 77 68 65 72 65 20  |plication where |
00003160  74 68 65 20 6d 75 6c 74  69 70 6c 69 65 72 20 69  |the multiplier i|
00003170  73 0d 6f 6e 6c 79 20 61  20 62 79 74 65 20 69 6e  |s.only a byte in|
00003180  20 73 69 7a 65 20 61 6e  64 20 74 68 65 20 6d 75  | size and the mu|
00003190  6c 74 69 70 6c 69 63 61  6e 64 20 69 73 20 34 20  |ltiplicand is 4 |
000031a0  62 79 74 65 73 20 69 6e  20 73 69 7a 65 2e 0d 0d  |bytes in size...|
000031b0  49 20 77 61 6e 74 65 64  20 74 6f 20 70 75 74 20  |I wanted to put |
000031c0  74 68 65 20 66 69 6e 61  6c 20 72 65 73 75 6c 74  |the final result|
000031d0  20 62 61 63 6b 20 69 6e  20 64 69 67 69 74 5f 77  | back in digit_w|
000031e0  73 20 73 6f 20 6c 69 6e  65 73 0d 33 32 37 30 20  |s so lines.3270 |
000031f0  74 6f 20 33 33 34 30 20  63 6f 70 79 20 69 74 20  |to 3340 copy it |
00003200  61 63 72 6f 73 73 20 74  68 65 72 65 2e 20 20 54  |across there.  T|
00003210  68 65 20 42 41 53 49 43  20 72 6f 75 74 69 6e 65  |he BASIC routine|
00003220  0d 62 65 74 77 65 65 6e  20 6c 69 6e 65 20 33 34  |.between line 34|
00003230  33 30 20 61 6e 64 20 33  34 36 30 20 65 6e 61 62  |30 and 3460 enab|
00003240  6c 65 73 20 79 6f 75 20  74 6f 20 63 68 65 63 6b  |les you to check|
00003250  20 74 68 65 20 72 65 73  75 6c 74 73 2e 0d 0d 54  | the results...T|
00003260  68 65 20 6e 65 78 74 20  6d 6f 64 75 6c 65 20 77  |he next module w|
00003270  69 6c 6c 20 64 65 61 6c  20 77 69 74 68 20 6d 75  |ill deal with mu|
00003280  6c 74 69 2d 62 79 74 65  20 6d 75 6c 74 69 70 6c  |lti-byte multipl|
00003290  69 63 61 74 69 6f 6e 2c  0d 61 6c 73 6f 20 63 61  |ication,.also ca|
000032a0  6c 6c 65 64 20 6d 75 6c  74 69 70 6c 65 20 70 72  |lled multiple pr|
000032b0  65 63 69 73 69 6f 6e 20  6d 75 6c 74 69 70 6c 69  |ecision multipli|
000032c0  63 61 74 69 6f 6e 2c 20  69 6e 20 61 20 6d 6f 72  |cation, in a mor|
000032d0  65 0d 67 65 6e 65 72 61  6c 20 77 61 79 2e 0d     |e.general way..|
000032df
30-01-88/T\OSB12.m0
30-01-88/T\OSB12.m1
30-01-88/T\OSB12.m2
30-01-88/T\OSB12.m4
30-01-88/T\OSB12.m5