Home » CEEFAX disks » telesoftware5.adl » 20-02-88/T\OSB14

20-02-88/T\OSB14

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: 20-02-88/T\OSB14
Read OK:
File size: 1A61 bytes
Load address: 0000
Exec address: FFFFFFFF
File contents
OSBITS - An Exploration of the BBC Micro at Machine Level

By Programmer

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


Part 14: Binary to ASCII Conversion

This module brings us around to division and I'll introduce
it by way of a routine to take a 4 byte number in memory and
print out it's value as a decimal number in ASCII.

Unlike input we have no error conditions to worry about
since there are only four bytes (the routine can be expanded
as required) and the number can be either negative or
positive.

If it is negative we will first note its sign and then
convert to positive for processing.

The processing goes like this:

Take the number and divide it by the base, in this case 10

Take the remainder (which represents the number of units)
and it will be a binary value between 0 and 9.  Add &30 to
it, which converts it to the ASCII code for its number 0-9
and put it into a buffer.

Divide the answer to the last division by 10, which leaves
us the number of 10s in the remainder .... and so on around
the loop.

We do this until the answer on division by 10 is zero.

But how do we divide in machine code?

For this exercise I'll go for the simplest algorithm, which
is essentially long division.  So let's divide 10101101 by
101 (173 by 5).  This should give us the result 34 remainder
3. We use conventional long division but remembering that we
only need to remember the 'one times table'!  This gives us
the following:

                       100010
                    ---------
               101 | 10101101
                     101
                     ---
                       00110 
                         101 
                         --- 
                          011

We could continue this division beyond the 'binary' point
which will give you an indication of how we will produce
real (as opposed to integer) numbers later on.

Effectively we are shifting (or rotating in 6502 terms)
along the dividend until we have shifted out a number
greater than the divisor.  We then subtract the divisor from
that part of the dividend.  We put a zero into the result
for each time we shift unless we can subtract in which case
we put in a one.

Starting again with the remainder from that last subtraction
we add bits onto it by shifting further along the dividend
until we have again produced a number greater than the
divisor .... and so on.  Because we are dividing by a number
less than 256 we can use the accumulator for some of this
work.

So here is an algorithm based on that long division.

    Set accumulator and result to zero
    Loop starts here
      Rotate result left
      Rotate dividend left into accumulator
      If accumulator is < divisor repeat loop
      If accumulator is >= divisor then:
          Add one to result
          Subtract divisor from accumulator
    Repeat loop until finished

You know when you are finished because you are counting the
number of bits in the dividend.  When you finish the result
contains the DIV part and the accumulator contains the
remainder or MOD part.

This division fits into the whole output routine as follows:

    Check the sign of the number to be output
    If -ve set the sign flag and subtract number from zero
    Output loop starts here
      If dividend is now zero then print out number from
        buffer and finish
      Divide number by 10 (again) and put remainder into
        buffer as ASCII
    Repeat the output loop    

This essentially is how the output routine works.  The
assembly program is annotated and should explain itself.
The number is entered using BASIC indirection operators
again but you could add on the input routine from module 12.

The subroutine at 'div_by_base' divides the number remaining
in 'dividend' by 10 and puts it back in 'dividend' with the
remainder in the accumulator ready for &30 to be added and
the ASCII value stored in the buffer.  As we proceed the Y
register points to the right place in the buffer.  Note that
we work backwards from the end to the beginning of the
number.

The buffer is finally printed out at 'print_characters'
which moves forwards along the buffer from the point where
the Y register finished moving backwards while loading
digits into the buffer.  This is unlikely to be the front of
the buffer unless the number is very large.  Note also that
there could be a minus sign at the first occupied position
in the buffer.  I put a zero byte (a null) at the end of the
buffer space early in the program so you can use a BEQ to
find the end of your number and stop printing.

There is a simple method employed to see if a multi-byte
number is zero.  If you logically OR all the bytes together
you will get a zero result only if each byte individually
was zero (since A OR B is only zero if both A and B are
zero).  This is used at the start of 'output_character_loop'
to see if there is anything left in the source number in
'dividend'.  This checking avoids any leading zeros
appearing in the number.

There's another similar trick, which I have not used here,
but it can be used to see if the product or quotient of two
numbers is negative or positive.  If you EOR the most
significant bytes together then the top bit of the result is
clear if they have the same sign (i.e. the product or
quotient is positive) and set if the opposite is true.  This
means a BPL or BMI (which effectively looks at the top bit)
can be used to control the action of the program at this
point.

There is a simple change you can make to the division
routine.  As it is at the moment the result and the dividend
are separate words but you will notice that as the dividend
is rotated left into the accumulator, bit by bit, empty bits
are added at the right.  At the same time the result is
being rotated left and meaningful bits are added at the
right.

The change to make is to combine the two.  This way you will
not have to clear the result space at the beginning, only
one word will be rotated instead of two, and you will not
have to transfer the contents of the workspaces at the end
of the division routine.

This leads to an algorithm like this:

    Set accumulator to zero
    Loop starts here
    Rotate dividend/result left into accumulator
    If accumulator is < divisor repeat loop
    If accumulator is >= divisor then:
        Add one to dividend/result
        Subtract divisor from accumulator
    Repeat loop until finished

It is simple to make this change but it speeds things up and
also removes the need for one of the workspace words
('result').  'dividend' now will start holding the dividend
but will gradually, bit by bit, become the result.  This is
the method I will use in a general routine next time, but
you could try modifying this module for yourself.
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 0d 0d 0d 50  61 72 74 20 31 34 3a 20  |.......Part 14: |
00000090  42 69 6e 61 72 79 20 74  6f 20 41 53 43 49 49 20  |Binary to ASCII |
000000a0  43 6f 6e 76 65 72 73 69  6f 6e 0d 0d 54 68 69 73  |Conversion..This|
000000b0  20 6d 6f 64 75 6c 65 20  62 72 69 6e 67 73 20 75  | module brings u|
000000c0  73 20 61 72 6f 75 6e 64  20 74 6f 20 64 69 76 69  |s around to divi|
000000d0  73 69 6f 6e 20 61 6e 64  20 49 27 6c 6c 20 69 6e  |sion and I'll in|
000000e0  74 72 6f 64 75 63 65 0d  69 74 20 62 79 20 77 61  |troduce.it by wa|
000000f0  79 20 6f 66 20 61 20 72  6f 75 74 69 6e 65 20 74  |y of a routine t|
00000100  6f 20 74 61 6b 65 20 61  20 34 20 62 79 74 65 20  |o take a 4 byte |
00000110  6e 75 6d 62 65 72 20 69  6e 20 6d 65 6d 6f 72 79  |number in memory|
00000120  20 61 6e 64 0d 70 72 69  6e 74 20 6f 75 74 20 69  | and.print out i|
00000130  74 27 73 20 76 61 6c 75  65 20 61 73 20 61 20 64  |t's value as a d|
00000140  65 63 69 6d 61 6c 20 6e  75 6d 62 65 72 20 69 6e  |ecimal number in|
00000150  20 41 53 43 49 49 2e 0d  0d 55 6e 6c 69 6b 65 20  | ASCII...Unlike |
00000160  69 6e 70 75 74 20 77 65  20 68 61 76 65 20 6e 6f  |input we have no|
00000170  20 65 72 72 6f 72 20 63  6f 6e 64 69 74 69 6f 6e  | error condition|
00000180  73 20 74 6f 20 77 6f 72  72 79 20 61 62 6f 75 74  |s to worry about|
00000190  0d 73 69 6e 63 65 20 74  68 65 72 65 20 61 72 65  |.since there are|
000001a0  20 6f 6e 6c 79 20 66 6f  75 72 20 62 79 74 65 73  | only four bytes|
000001b0  20 28 74 68 65 20 72 6f  75 74 69 6e 65 20 63 61  | (the routine ca|
000001c0  6e 20 62 65 20 65 78 70  61 6e 64 65 64 0d 61 73  |n be expanded.as|
000001d0  20 72 65 71 75 69 72 65  64 29 20 61 6e 64 20 74  | required) and t|
000001e0  68 65 20 6e 75 6d 62 65  72 20 63 61 6e 20 62 65  |he number can be|
000001f0  20 65 69 74 68 65 72 20  6e 65 67 61 74 69 76 65  | either negative|
00000200  20 6f 72 0d 70 6f 73 69  74 69 76 65 2e 0d 0d 49  | or.positive...I|
00000210  66 20 69 74 20 69 73 20  6e 65 67 61 74 69 76 65  |f it is negative|
00000220  20 77 65 20 77 69 6c 6c  20 66 69 72 73 74 20 6e  | we will first n|
00000230  6f 74 65 20 69 74 73 20  73 69 67 6e 20 61 6e 64  |ote its sign and|
00000240  20 74 68 65 6e 0d 63 6f  6e 76 65 72 74 20 74 6f  | then.convert to|
00000250  20 70 6f 73 69 74 69 76  65 20 66 6f 72 20 70 72  | positive for pr|
00000260  6f 63 65 73 73 69 6e 67  2e 0d 0d 54 68 65 20 70  |ocessing...The p|
00000270  72 6f 63 65 73 73 69 6e  67 20 67 6f 65 73 20 6c  |rocessing goes l|
00000280  69 6b 65 20 74 68 69 73  3a 0d 0d 54 61 6b 65 20  |ike this:..Take |
00000290  74 68 65 20 6e 75 6d 62  65 72 20 61 6e 64 20 64  |the number and d|
000002a0  69 76 69 64 65 20 69 74  20 62 79 20 74 68 65 20  |ivide it by the |
000002b0  62 61 73 65 2c 20 69 6e  20 74 68 69 73 20 63 61  |base, in this ca|
000002c0  73 65 20 31 30 0d 0d 54  61 6b 65 20 74 68 65 20  |se 10..Take the |
000002d0  72 65 6d 61 69 6e 64 65  72 20 28 77 68 69 63 68  |remainder (which|
000002e0  20 72 65 70 72 65 73 65  6e 74 73 20 74 68 65 20  | represents the |
000002f0  6e 75 6d 62 65 72 20 6f  66 20 75 6e 69 74 73 29  |number of units)|
00000300  0d 61 6e 64 20 69 74 20  77 69 6c 6c 20 62 65 20  |.and it will be |
00000310  61 20 62 69 6e 61 72 79  20 76 61 6c 75 65 20 62  |a binary value b|
00000320  65 74 77 65 65 6e 20 30  20 61 6e 64 20 39 2e 20  |etween 0 and 9. |
00000330  20 41 64 64 20 26 33 30  20 74 6f 0d 69 74 2c 20  | Add &30 to.it, |
00000340  77 68 69 63 68 20 63 6f  6e 76 65 72 74 73 20 69  |which converts i|
00000350  74 20 74 6f 20 74 68 65  20 41 53 43 49 49 20 63  |t to the ASCII c|
00000360  6f 64 65 20 66 6f 72 20  69 74 73 20 6e 75 6d 62  |ode for its numb|
00000370  65 72 20 30 2d 39 0d 61  6e 64 20 70 75 74 20 69  |er 0-9.and put i|
00000380  74 20 69 6e 74 6f 20 61  20 62 75 66 66 65 72 2e  |t into a buffer.|
00000390  0d 0d 44 69 76 69 64 65  20 74 68 65 20 61 6e 73  |..Divide the ans|
000003a0  77 65 72 20 74 6f 20 74  68 65 20 6c 61 73 74 20  |wer to the last |
000003b0  64 69 76 69 73 69 6f 6e  20 62 79 20 31 30 2c 20  |division by 10, |
000003c0  77 68 69 63 68 20 6c 65  61 76 65 73 0d 75 73 20  |which leaves.us |
000003d0  74 68 65 20 6e 75 6d 62  65 72 20 6f 66 20 31 30  |the number of 10|
000003e0  73 20 69 6e 20 74 68 65  20 72 65 6d 61 69 6e 64  |s in the remaind|
000003f0  65 72 20 2e 2e 2e 2e 20  61 6e 64 20 73 6f 20 6f  |er .... and so o|
00000400  6e 20 61 72 6f 75 6e 64  0d 74 68 65 20 6c 6f 6f  |n around.the loo|
00000410  70 2e 0d 0d 57 65 20 64  6f 20 74 68 69 73 20 75  |p...We do this u|
00000420  6e 74 69 6c 20 74 68 65  20 61 6e 73 77 65 72 20  |ntil the answer |
00000430  6f 6e 20 64 69 76 69 73  69 6f 6e 20 62 79 20 31  |on division by 1|
00000440  30 20 69 73 20 7a 65 72  6f 2e 0d 0d 42 75 74 20  |0 is zero...But |
00000450  68 6f 77 20 64 6f 20 77  65 20 64 69 76 69 64 65  |how do we divide|
00000460  20 69 6e 20 6d 61 63 68  69 6e 65 20 63 6f 64 65  | in machine code|
00000470  3f 0d 0d 46 6f 72 20 74  68 69 73 20 65 78 65 72  |?..For this exer|
00000480  63 69 73 65 20 49 27 6c  6c 20 67 6f 20 66 6f 72  |cise I'll go for|
00000490  20 74 68 65 20 73 69 6d  70 6c 65 73 74 20 61 6c  | the simplest al|
000004a0  67 6f 72 69 74 68 6d 2c  20 77 68 69 63 68 0d 69  |gorithm, which.i|
000004b0  73 20 65 73 73 65 6e 74  69 61 6c 6c 79 20 6c 6f  |s essentially lo|
000004c0  6e 67 20 64 69 76 69 73  69 6f 6e 2e 20 20 53 6f  |ng division.  So|
000004d0  20 6c 65 74 27 73 20 64  69 76 69 64 65 20 31 30  | let's divide 10|
000004e0  31 30 31 31 30 31 20 62  79 0d 31 30 31 20 28 31  |101101 by.101 (1|
000004f0  37 33 20 62 79 20 35 29  2e 20 20 54 68 69 73 20  |73 by 5).  This |
00000500  73 68 6f 75 6c 64 20 67  69 76 65 20 75 73 20 74  |should give us t|
00000510  68 65 20 72 65 73 75 6c  74 20 33 34 20 72 65 6d  |he result 34 rem|
00000520  61 69 6e 64 65 72 0d 33  2e 20 57 65 20 75 73 65  |ainder.3. We use|
00000530  20 63 6f 6e 76 65 6e 74  69 6f 6e 61 6c 20 6c 6f  | conventional lo|
00000540  6e 67 20 64 69 76 69 73  69 6f 6e 20 62 75 74 20  |ng division but |
00000550  72 65 6d 65 6d 62 65 72  69 6e 67 20 74 68 61 74  |remembering that|
00000560  20 77 65 0d 6f 6e 6c 79  20 6e 65 65 64 20 74 6f  | we.only need to|
00000570  20 72 65 6d 65 6d 62 65  72 20 74 68 65 20 27 6f  | remember the 'o|
00000580  6e 65 20 74 69 6d 65 73  20 74 61 62 6c 65 27 21  |ne times table'!|
00000590  20 20 54 68 69 73 20 67  69 76 65 73 20 75 73 0d  |  This gives us.|
000005a0  74 68 65 20 66 6f 6c 6c  6f 77 69 6e 67 3a 0d 0d  |the following:..|
000005b0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
000005c0  20 20 20 20 20 20 20 31  30 30 30 31 30 0d 20 20  |       100010.  |
000005d0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
000005e0  20 20 2d 2d 2d 2d 2d 2d  2d 2d 2d 0d 20 20 20 20  |  ---------.    |
000005f0  20 20 20 20 20 20 20 20  20 20 20 31 30 31 20 7c  |           101 ||
00000600  20 31 30 31 30 31 31 30  31 0d 20 20 20 20 20 20  | 10101101.      |
00000610  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 31  |               1|
00000620  30 31 0d 20 20 20 20 20  20 20 20 20 20 20 20 20  |01.             |
00000630  20 20 20 20 20 20 20 20  2d 2d 2d 0d 20 20 20 20  |        ---.    |
00000640  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000650  20 20 20 30 30 31 31 30  20 0d 20 20 20 20 20 20  |   00110 .      |
00000660  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000670  20 20 20 31 30 31 20 0d  20 20 20 20 20 20 20 20  |   101 .        |
00000680  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000690  20 2d 2d 2d 20 0d 20 20  20 20 20 20 20 20 20 20  | --- .          |
000006a0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
000006b0  30 31 31 0d 0d 57 65 20  63 6f 75 6c 64 20 63 6f  |011..We could co|
000006c0  6e 74 69 6e 75 65 20 74  68 69 73 20 64 69 76 69  |ntinue this divi|
000006d0  73 69 6f 6e 20 62 65 79  6f 6e 64 20 74 68 65 20  |sion beyond the |
000006e0  27 62 69 6e 61 72 79 27  20 70 6f 69 6e 74 0d 77  |'binary' point.w|
000006f0  68 69 63 68 20 77 69 6c  6c 20 67 69 76 65 20 79  |hich will give y|
00000700  6f 75 20 61 6e 20 69 6e  64 69 63 61 74 69 6f 6e  |ou an indication|
00000710  20 6f 66 20 68 6f 77 20  77 65 20 77 69 6c 6c 20  | of how we will |
00000720  70 72 6f 64 75 63 65 0d  72 65 61 6c 20 28 61 73  |produce.real (as|
00000730  20 6f 70 70 6f 73 65 64  20 74 6f 20 69 6e 74 65  | opposed to inte|
00000740  67 65 72 29 20 6e 75 6d  62 65 72 73 20 6c 61 74  |ger) numbers lat|
00000750  65 72 20 6f 6e 2e 0d 0d  45 66 66 65 63 74 69 76  |er on...Effectiv|
00000760  65 6c 79 20 77 65 20 61  72 65 20 73 68 69 66 74  |ely we are shift|
00000770  69 6e 67 20 28 6f 72 20  72 6f 74 61 74 69 6e 67  |ing (or rotating|
00000780  20 69 6e 20 36 35 30 32  20 74 65 72 6d 73 29 0d  | in 6502 terms).|
00000790  61 6c 6f 6e 67 20 74 68  65 20 64 69 76 69 64 65  |along the divide|
000007a0  6e 64 20 75 6e 74 69 6c  20 77 65 20 68 61 76 65  |nd until we have|
000007b0  20 73 68 69 66 74 65 64  20 6f 75 74 20 61 20 6e  | shifted out a n|
000007c0  75 6d 62 65 72 0d 67 72  65 61 74 65 72 20 74 68  |umber.greater th|
000007d0  61 6e 20 74 68 65 20 64  69 76 69 73 6f 72 2e 20  |an the divisor. |
000007e0  20 57 65 20 74 68 65 6e  20 73 75 62 74 72 61 63  | We then subtrac|
000007f0  74 20 74 68 65 20 64 69  76 69 73 6f 72 20 66 72  |t the divisor fr|
00000800  6f 6d 0d 74 68 61 74 20  70 61 72 74 20 6f 66 20  |om.that part of |
00000810  74 68 65 20 64 69 76 69  64 65 6e 64 2e 20 20 57  |the dividend.  W|
00000820  65 20 70 75 74 20 61 20  7a 65 72 6f 20 69 6e 74  |e put a zero int|
00000830  6f 20 74 68 65 20 72 65  73 75 6c 74 0d 66 6f 72  |o the result.for|
00000840  20 65 61 63 68 20 74 69  6d 65 20 77 65 20 73 68  | each time we sh|
00000850  69 66 74 20 75 6e 6c 65  73 73 20 77 65 20 63 61  |ift unless we ca|
00000860  6e 20 73 75 62 74 72 61  63 74 20 69 6e 20 77 68  |n subtract in wh|
00000870  69 63 68 20 63 61 73 65  0d 77 65 20 70 75 74 20  |ich case.we put |
00000880  69 6e 20 61 20 6f 6e 65  2e 0d 0d 53 74 61 72 74  |in a one...Start|
00000890  69 6e 67 20 61 67 61 69  6e 20 77 69 74 68 20 74  |ing again with t|
000008a0  68 65 20 72 65 6d 61 69  6e 64 65 72 20 66 72 6f  |he remainder fro|
000008b0  6d 20 74 68 61 74 20 6c  61 73 74 20 73 75 62 74  |m that last subt|
000008c0  72 61 63 74 69 6f 6e 0d  77 65 20 61 64 64 20 62  |raction.we add b|
000008d0  69 74 73 20 6f 6e 74 6f  20 69 74 20 62 79 20 73  |its onto it by s|
000008e0  68 69 66 74 69 6e 67 20  66 75 72 74 68 65 72 20  |hifting further |
000008f0  61 6c 6f 6e 67 20 74 68  65 20 64 69 76 69 64 65  |along the divide|
00000900  6e 64 0d 75 6e 74 69 6c  20 77 65 20 68 61 76 65  |nd.until we have|
00000910  20 61 67 61 69 6e 20 70  72 6f 64 75 63 65 64 20  | again produced |
00000920  61 20 6e 75 6d 62 65 72  20 67 72 65 61 74 65 72  |a number greater|
00000930  20 74 68 61 6e 20 74 68  65 0d 64 69 76 69 73 6f  | than the.diviso|
00000940  72 20 2e 2e 2e 2e 20 61  6e 64 20 73 6f 20 6f 6e  |r .... and so on|
00000950  2e 20 20 42 65 63 61 75  73 65 20 77 65 20 61 72  |.  Because we ar|
00000960  65 20 64 69 76 69 64 69  6e 67 20 62 79 20 61 20  |e dividing by a |
00000970  6e 75 6d 62 65 72 0d 6c  65 73 73 20 74 68 61 6e  |number.less than|
00000980  20 32 35 36 20 77 65 20  63 61 6e 20 75 73 65 20  | 256 we can use |
00000990  74 68 65 20 61 63 63 75  6d 75 6c 61 74 6f 72 20  |the accumulator |
000009a0  66 6f 72 20 73 6f 6d 65  20 6f 66 20 74 68 69 73  |for some of this|
000009b0  0d 77 6f 72 6b 2e 0d 0d  53 6f 20 68 65 72 65 20  |.work...So here |
000009c0  69 73 20 61 6e 20 61 6c  67 6f 72 69 74 68 6d 20  |is an algorithm |
000009d0  62 61 73 65 64 20 6f 6e  20 74 68 61 74 20 6c 6f  |based on that lo|
000009e0  6e 67 20 64 69 76 69 73  69 6f 6e 2e 0d 0d 20 20  |ng division...  |
000009f0  20 20 53 65 74 20 61 63  63 75 6d 75 6c 61 74 6f  |  Set accumulato|
00000a00  72 20 61 6e 64 20 72 65  73 75 6c 74 20 74 6f 20  |r and result to |
00000a10  7a 65 72 6f 0d 20 20 20  20 4c 6f 6f 70 20 73 74  |zero.    Loop st|
00000a20  61 72 74 73 20 68 65 72  65 0d 20 20 20 20 20 20  |arts here.      |
00000a30  52 6f 74 61 74 65 20 72  65 73 75 6c 74 20 6c 65  |Rotate result le|
00000a40  66 74 0d 20 20 20 20 20  20 52 6f 74 61 74 65 20  |ft.      Rotate |
00000a50  64 69 76 69 64 65 6e 64  20 6c 65 66 74 20 69 6e  |dividend left in|
00000a60  74 6f 20 61 63 63 75 6d  75 6c 61 74 6f 72 0d 20  |to accumulator. |
00000a70  20 20 20 20 20 49 66 20  61 63 63 75 6d 75 6c 61  |     If accumula|
00000a80  74 6f 72 20 69 73 20 3c  20 64 69 76 69 73 6f 72  |tor is < divisor|
00000a90  20 72 65 70 65 61 74 20  6c 6f 6f 70 0d 20 20 20  | repeat loop.   |
00000aa0  20 20 20 49 66 20 61 63  63 75 6d 75 6c 61 74 6f  |   If accumulato|
00000ab0  72 20 69 73 20 3e 3d 20  64 69 76 69 73 6f 72 20  |r is >= divisor |
00000ac0  74 68 65 6e 3a 0d 20 20  20 20 20 20 20 20 20 20  |then:.          |
00000ad0  41 64 64 20 6f 6e 65 20  74 6f 20 72 65 73 75 6c  |Add one to resul|
00000ae0  74 0d 20 20 20 20 20 20  20 20 20 20 53 75 62 74  |t.          Subt|
00000af0  72 61 63 74 20 64 69 76  69 73 6f 72 20 66 72 6f  |ract divisor fro|
00000b00  6d 20 61 63 63 75 6d 75  6c 61 74 6f 72 0d 20 20  |m accumulator.  |
00000b10  20 20 52 65 70 65 61 74  20 6c 6f 6f 70 20 75 6e  |  Repeat loop un|
00000b20  74 69 6c 20 66 69 6e 69  73 68 65 64 0d 0d 59 6f  |til finished..Yo|
00000b30  75 20 6b 6e 6f 77 20 77  68 65 6e 20 79 6f 75 20  |u know when you |
00000b40  61 72 65 20 66 69 6e 69  73 68 65 64 20 62 65 63  |are finished bec|
00000b50  61 75 73 65 20 79 6f 75  20 61 72 65 20 63 6f 75  |ause you are cou|
00000b60  6e 74 69 6e 67 20 74 68  65 0d 6e 75 6d 62 65 72  |nting the.number|
00000b70  20 6f 66 20 62 69 74 73  20 69 6e 20 74 68 65 20  | of bits in the |
00000b80  64 69 76 69 64 65 6e 64  2e 20 20 57 68 65 6e 20  |dividend.  When |
00000b90  79 6f 75 20 66 69 6e 69  73 68 20 74 68 65 20 72  |you finish the r|
00000ba0  65 73 75 6c 74 0d 63 6f  6e 74 61 69 6e 73 20 74  |esult.contains t|
00000bb0  68 65 20 44 49 56 20 70  61 72 74 20 61 6e 64 20  |he DIV part and |
00000bc0  74 68 65 20 61 63 63 75  6d 75 6c 61 74 6f 72 20  |the accumulator |
00000bd0  63 6f 6e 74 61 69 6e 73  20 74 68 65 0d 72 65 6d  |contains the.rem|
00000be0  61 69 6e 64 65 72 20 6f  72 20 4d 4f 44 20 70 61  |ainder or MOD pa|
00000bf0  72 74 2e 0d 0d 54 68 69  73 20 64 69 76 69 73 69  |rt...This divisi|
00000c00  6f 6e 20 66 69 74 73 20  69 6e 74 6f 20 74 68 65  |on fits into the|
00000c10  20 77 68 6f 6c 65 20 6f  75 74 70 75 74 20 72 6f  | whole output ro|
00000c20  75 74 69 6e 65 20 61 73  20 66 6f 6c 6c 6f 77 73  |utine as follows|
00000c30  3a 0d 0d 20 20 20 20 43  68 65 63 6b 20 74 68 65  |:..    Check the|
00000c40  20 73 69 67 6e 20 6f 66  20 74 68 65 20 6e 75 6d  | sign of the num|
00000c50  62 65 72 20 74 6f 20 62  65 20 6f 75 74 70 75 74  |ber to be output|
00000c60  0d 20 20 20 20 49 66 20  2d 76 65 20 73 65 74 20  |.    If -ve set |
00000c70  74 68 65 20 73 69 67 6e  20 66 6c 61 67 20 61 6e  |the sign flag an|
00000c80  64 20 73 75 62 74 72 61  63 74 20 6e 75 6d 62 65  |d subtract numbe|
00000c90  72 20 66 72 6f 6d 20 7a  65 72 6f 0d 20 20 20 20  |r from zero.    |
00000ca0  4f 75 74 70 75 74 20 6c  6f 6f 70 20 73 74 61 72  |Output loop star|
00000cb0  74 73 20 68 65 72 65 0d  20 20 20 20 20 20 49 66  |ts here.      If|
00000cc0  20 64 69 76 69 64 65 6e  64 20 69 73 20 6e 6f 77  | dividend is now|
00000cd0  20 7a 65 72 6f 20 74 68  65 6e 20 70 72 69 6e 74  | zero then print|
00000ce0  20 6f 75 74 20 6e 75 6d  62 65 72 20 66 72 6f 6d  | out number from|
00000cf0  0d 20 20 20 20 20 20 20  20 62 75 66 66 65 72 20  |.        buffer |
00000d00  61 6e 64 20 66 69 6e 69  73 68 0d 20 20 20 20 20  |and finish.     |
00000d10  20 44 69 76 69 64 65 20  6e 75 6d 62 65 72 20 62  | Divide number b|
00000d20  79 20 31 30 20 28 61 67  61 69 6e 29 20 61 6e 64  |y 10 (again) and|
00000d30  20 70 75 74 20 72 65 6d  61 69 6e 64 65 72 20 69  | put remainder i|
00000d40  6e 74 6f 0d 20 20 20 20  20 20 20 20 62 75 66 66  |nto.        buff|
00000d50  65 72 20 61 73 20 41 53  43 49 49 0d 20 20 20 20  |er as ASCII.    |
00000d60  52 65 70 65 61 74 20 74  68 65 20 6f 75 74 70 75  |Repeat the outpu|
00000d70  74 20 6c 6f 6f 70 20 20  20 20 0d 0d 54 68 69 73  |t loop    ..This|
00000d80  20 65 73 73 65 6e 74 69  61 6c 6c 79 20 69 73 20  | essentially is |
00000d90  68 6f 77 20 74 68 65 20  6f 75 74 70 75 74 20 72  |how the output r|
00000da0  6f 75 74 69 6e 65 20 77  6f 72 6b 73 2e 20 20 54  |outine works.  T|
00000db0  68 65 0d 61 73 73 65 6d  62 6c 79 20 70 72 6f 67  |he.assembly prog|
00000dc0  72 61 6d 20 69 73 20 61  6e 6e 6f 74 61 74 65 64  |ram is annotated|
00000dd0  20 61 6e 64 20 73 68 6f  75 6c 64 20 65 78 70 6c  | and should expl|
00000de0  61 69 6e 20 69 74 73 65  6c 66 2e 0d 54 68 65 20  |ain itself..The |
00000df0  6e 75 6d 62 65 72 20 69  73 20 65 6e 74 65 72 65  |number is entere|
00000e00  64 20 75 73 69 6e 67 20  42 41 53 49 43 20 69 6e  |d using BASIC in|
00000e10  64 69 72 65 63 74 69 6f  6e 20 6f 70 65 72 61 74  |direction operat|
00000e20  6f 72 73 0d 61 67 61 69  6e 20 62 75 74 20 79 6f  |ors.again but yo|
00000e30  75 20 63 6f 75 6c 64 20  61 64 64 20 6f 6e 20 74  |u could add on t|
00000e40  68 65 20 69 6e 70 75 74  20 72 6f 75 74 69 6e 65  |he input routine|
00000e50  20 66 72 6f 6d 20 6d 6f  64 75 6c 65 20 31 32 2e  | from module 12.|
00000e60  0d 0d 54 68 65 20 73 75  62 72 6f 75 74 69 6e 65  |..The subroutine|
00000e70  20 61 74 20 27 64 69 76  5f 62 79 5f 62 61 73 65  | at 'div_by_base|
00000e80  27 20 64 69 76 69 64 65  73 20 74 68 65 20 6e 75  |' divides the nu|
00000e90  6d 62 65 72 20 72 65 6d  61 69 6e 69 6e 67 0d 69  |mber remaining.i|
00000ea0  6e 20 27 64 69 76 69 64  65 6e 64 27 20 62 79 20  |n 'dividend' by |
00000eb0  31 30 20 61 6e 64 20 70  75 74 73 20 69 74 20 62  |10 and puts it b|
00000ec0  61 63 6b 20 69 6e 20 27  64 69 76 69 64 65 6e 64  |ack in 'dividend|
00000ed0  27 20 77 69 74 68 20 74  68 65 0d 72 65 6d 61 69  |' with the.remai|
00000ee0  6e 64 65 72 20 69 6e 20  74 68 65 20 61 63 63 75  |nder in the accu|
00000ef0  6d 75 6c 61 74 6f 72 20  72 65 61 64 79 20 66 6f  |mulator ready fo|
00000f00  72 20 26 33 30 20 74 6f  20 62 65 20 61 64 64 65  |r &30 to be adde|
00000f10  64 20 61 6e 64 0d 74 68  65 20 41 53 43 49 49 20  |d and.the ASCII |
00000f20  76 61 6c 75 65 20 73 74  6f 72 65 64 20 69 6e 20  |value stored in |
00000f30  74 68 65 20 62 75 66 66  65 72 2e 20 20 41 73 20  |the buffer.  As |
00000f40  77 65 20 70 72 6f 63 65  65 64 20 74 68 65 20 59  |we proceed the Y|
00000f50  0d 72 65 67 69 73 74 65  72 20 70 6f 69 6e 74 73  |.register points|
00000f60  20 74 6f 20 74 68 65 20  72 69 67 68 74 20 70 6c  | to the right pl|
00000f70  61 63 65 20 69 6e 20 74  68 65 20 62 75 66 66 65  |ace in the buffe|
00000f80  72 2e 20 20 4e 6f 74 65  20 74 68 61 74 0d 77 65  |r.  Note that.we|
00000f90  20 77 6f 72 6b 20 62 61  63 6b 77 61 72 64 73 20  | work backwards |
00000fa0  66 72 6f 6d 20 74 68 65  20 65 6e 64 20 74 6f 20  |from the end to |
00000fb0  74 68 65 20 62 65 67 69  6e 6e 69 6e 67 20 6f 66  |the beginning of|
00000fc0  20 74 68 65 0d 6e 75 6d  62 65 72 2e 0d 0d 54 68  | the.number...Th|
00000fd0  65 20 62 75 66 66 65 72  20 69 73 20 66 69 6e 61  |e buffer is fina|
00000fe0  6c 6c 79 20 70 72 69 6e  74 65 64 20 6f 75 74 20  |lly printed out |
00000ff0  61 74 20 27 70 72 69 6e  74 5f 63 68 61 72 61 63  |at 'print_charac|
00001000  74 65 72 73 27 0d 77 68  69 63 68 20 6d 6f 76 65  |ters'.which move|
00001010  73 20 66 6f 72 77 61 72  64 73 20 61 6c 6f 6e 67  |s forwards along|
00001020  20 74 68 65 20 62 75 66  66 65 72 20 66 72 6f 6d  | the buffer from|
00001030  20 74 68 65 20 70 6f 69  6e 74 20 77 68 65 72 65  | the point where|
00001040  0d 74 68 65 20 59 20 72  65 67 69 73 74 65 72 20  |.the Y register |
00001050  66 69 6e 69 73 68 65 64  20 6d 6f 76 69 6e 67 20  |finished moving |
00001060  62 61 63 6b 77 61 72 64  73 20 77 68 69 6c 65 20  |backwards while |
00001070  6c 6f 61 64 69 6e 67 0d  64 69 67 69 74 73 20 69  |loading.digits i|
00001080  6e 74 6f 20 74 68 65 20  62 75 66 66 65 72 2e 20  |nto the buffer. |
00001090  20 54 68 69 73 20 69 73  20 75 6e 6c 69 6b 65 6c  | This is unlikel|
000010a0  79 20 74 6f 20 62 65 20  74 68 65 20 66 72 6f 6e  |y to be the fron|
000010b0  74 20 6f 66 0d 74 68 65  20 62 75 66 66 65 72 20  |t of.the buffer |
000010c0  75 6e 6c 65 73 73 20 74  68 65 20 6e 75 6d 62 65  |unless the numbe|
000010d0  72 20 69 73 20 76 65 72  79 20 6c 61 72 67 65 2e  |r is very large.|
000010e0  20 20 4e 6f 74 65 20 61  6c 73 6f 20 74 68 61 74  |  Note also that|
000010f0  0d 74 68 65 72 65 20 63  6f 75 6c 64 20 62 65 20  |.there could be |
00001100  61 20 6d 69 6e 75 73 20  73 69 67 6e 20 61 74 20  |a minus sign at |
00001110  74 68 65 20 66 69 72 73  74 20 6f 63 63 75 70 69  |the first occupi|
00001120  65 64 20 70 6f 73 69 74  69 6f 6e 0d 69 6e 20 74  |ed position.in t|
00001130  68 65 20 62 75 66 66 65  72 2e 20 20 49 20 70 75  |he buffer.  I pu|
00001140  74 20 61 20 7a 65 72 6f  20 62 79 74 65 20 28 61  |t a zero byte (a|
00001150  20 6e 75 6c 6c 29 20 61  74 20 74 68 65 20 65 6e  | null) at the en|
00001160  64 20 6f 66 20 74 68 65  0d 62 75 66 66 65 72 20  |d of the.buffer |
00001170  73 70 61 63 65 20 65 61  72 6c 79 20 69 6e 20 74  |space early in t|
00001180  68 65 20 70 72 6f 67 72  61 6d 20 73 6f 20 79 6f  |he program so yo|
00001190  75 20 63 61 6e 20 75 73  65 20 61 20 42 45 51 20  |u can use a BEQ |
000011a0  74 6f 0d 66 69 6e 64 20  74 68 65 20 65 6e 64 20  |to.find the end |
000011b0  6f 66 20 79 6f 75 72 20  6e 75 6d 62 65 72 20 61  |of your number a|
000011c0  6e 64 20 73 74 6f 70 20  70 72 69 6e 74 69 6e 67  |nd stop printing|
000011d0  2e 0d 0d 54 68 65 72 65  20 69 73 20 61 20 73 69  |...There is a si|
000011e0  6d 70 6c 65 20 6d 65 74  68 6f 64 20 65 6d 70 6c  |mple method empl|
000011f0  6f 79 65 64 20 74 6f 20  73 65 65 20 69 66 20 61  |oyed to see if a|
00001200  20 6d 75 6c 74 69 2d 62  79 74 65 0d 6e 75 6d 62  | multi-byte.numb|
00001210  65 72 20 69 73 20 7a 65  72 6f 2e 20 20 49 66 20  |er is zero.  If |
00001220  79 6f 75 20 6c 6f 67 69  63 61 6c 6c 79 20 4f 52  |you logically OR|
00001230  20 61 6c 6c 20 74 68 65  20 62 79 74 65 73 20 74  | all the bytes t|
00001240  6f 67 65 74 68 65 72 0d  79 6f 75 20 77 69 6c 6c  |ogether.you will|
00001250  20 67 65 74 20 61 20 7a  65 72 6f 20 72 65 73 75  | get a zero resu|
00001260  6c 74 20 6f 6e 6c 79 20  69 66 20 65 61 63 68 20  |lt only if each |
00001270  62 79 74 65 20 69 6e 64  69 76 69 64 75 61 6c 6c  |byte individuall|
00001280  79 0d 77 61 73 20 7a 65  72 6f 20 28 73 69 6e 63  |y.was zero (sinc|
00001290  65 20 41 20 4f 52 20 42  20 69 73 20 6f 6e 6c 79  |e A OR B is only|
000012a0  20 7a 65 72 6f 20 69 66  20 62 6f 74 68 20 41 20  | zero if both A |
000012b0  61 6e 64 20 42 20 61 72  65 0d 7a 65 72 6f 29 2e  |and B are.zero).|
000012c0  20 20 54 68 69 73 20 69  73 20 75 73 65 64 20 61  |  This is used a|
000012d0  74 20 74 68 65 20 73 74  61 72 74 20 6f 66 20 27  |t the start of '|
000012e0  6f 75 74 70 75 74 5f 63  68 61 72 61 63 74 65 72  |output_character|
000012f0  5f 6c 6f 6f 70 27 0d 74  6f 20 73 65 65 20 69 66  |_loop'.to see if|
00001300  20 74 68 65 72 65 20 69  73 20 61 6e 79 74 68 69  | there is anythi|
00001310  6e 67 20 6c 65 66 74 20  69 6e 20 74 68 65 20 73  |ng left in the s|
00001320  6f 75 72 63 65 20 6e 75  6d 62 65 72 20 69 6e 0d  |ource number in.|
00001330  27 64 69 76 69 64 65 6e  64 27 2e 20 20 54 68 69  |'dividend'.  Thi|
00001340  73 20 63 68 65 63 6b 69  6e 67 20 61 76 6f 69 64  |s checking avoid|
00001350  73 20 61 6e 79 20 6c 65  61 64 69 6e 67 20 7a 65  |s any leading ze|
00001360  72 6f 73 0d 61 70 70 65  61 72 69 6e 67 20 69 6e  |ros.appearing in|
00001370  20 74 68 65 20 6e 75 6d  62 65 72 2e 0d 0d 54 68  | the number...Th|
00001380  65 72 65 27 73 20 61 6e  6f 74 68 65 72 20 73 69  |ere's another si|
00001390  6d 69 6c 61 72 20 74 72  69 63 6b 2c 20 77 68 69  |milar trick, whi|
000013a0  63 68 20 49 20 68 61 76  65 20 6e 6f 74 20 75 73  |ch I have not us|
000013b0  65 64 20 68 65 72 65 2c  0d 62 75 74 20 69 74 20  |ed here,.but it |
000013c0  63 61 6e 20 62 65 20 75  73 65 64 20 74 6f 20 73  |can be used to s|
000013d0  65 65 20 69 66 20 74 68  65 20 70 72 6f 64 75 63  |ee if the produc|
000013e0  74 20 6f 72 20 71 75 6f  74 69 65 6e 74 20 6f 66  |t or quotient of|
000013f0  20 74 77 6f 0d 6e 75 6d  62 65 72 73 20 69 73 20  | two.numbers is |
00001400  6e 65 67 61 74 69 76 65  20 6f 72 20 70 6f 73 69  |negative or posi|
00001410  74 69 76 65 2e 20 20 49  66 20 79 6f 75 20 45 4f  |tive.  If you EO|
00001420  52 20 74 68 65 20 6d 6f  73 74 0d 73 69 67 6e 69  |R the most.signi|
00001430  66 69 63 61 6e 74 20 62  79 74 65 73 20 74 6f 67  |ficant bytes tog|
00001440  65 74 68 65 72 20 74 68  65 6e 20 74 68 65 20 74  |ether then the t|
00001450  6f 70 20 62 69 74 20 6f  66 20 74 68 65 20 72 65  |op bit of the re|
00001460  73 75 6c 74 20 69 73 0d  63 6c 65 61 72 20 69 66  |sult is.clear if|
00001470  20 74 68 65 79 20 68 61  76 65 20 74 68 65 20 73  | they have the s|
00001480  61 6d 65 20 73 69 67 6e  20 28 69 2e 65 2e 20 74  |ame sign (i.e. t|
00001490  68 65 20 70 72 6f 64 75  63 74 20 6f 72 0d 71 75  |he product or.qu|
000014a0  6f 74 69 65 6e 74 20 69  73 20 70 6f 73 69 74 69  |otient is positi|
000014b0  76 65 29 20 61 6e 64 20  73 65 74 20 69 66 20 74  |ve) and set if t|
000014c0  68 65 20 6f 70 70 6f 73  69 74 65 20 69 73 20 74  |he opposite is t|
000014d0  72 75 65 2e 20 20 54 68  69 73 0d 6d 65 61 6e 73  |rue.  This.means|
000014e0  20 61 20 42 50 4c 20 6f  72 20 42 4d 49 20 28 77  | a BPL or BMI (w|
000014f0  68 69 63 68 20 65 66 66  65 63 74 69 76 65 6c 79  |hich effectively|
00001500  20 6c 6f 6f 6b 73 20 61  74 20 74 68 65 20 74 6f  | looks at the to|
00001510  70 20 62 69 74 29 0d 63  61 6e 20 62 65 20 75 73  |p bit).can be us|
00001520  65 64 20 74 6f 20 63 6f  6e 74 72 6f 6c 20 74 68  |ed to control th|
00001530  65 20 61 63 74 69 6f 6e  20 6f 66 20 74 68 65 20  |e action of the |
00001540  70 72 6f 67 72 61 6d 20  61 74 20 74 68 69 73 0d  |program at this.|
00001550  70 6f 69 6e 74 2e 0d 0d  54 68 65 72 65 20 69 73  |point...There is|
00001560  20 61 20 73 69 6d 70 6c  65 20 63 68 61 6e 67 65  | a simple change|
00001570  20 79 6f 75 20 63 61 6e  20 6d 61 6b 65 20 74 6f  | you can make to|
00001580  20 74 68 65 20 64 69 76  69 73 69 6f 6e 0d 72 6f  | the division.ro|
00001590  75 74 69 6e 65 2e 20 20  41 73 20 69 74 20 69 73  |utine.  As it is|
000015a0  20 61 74 20 74 68 65 20  6d 6f 6d 65 6e 74 20 74  | at the moment t|
000015b0  68 65 20 72 65 73 75 6c  74 20 61 6e 64 20 74 68  |he result and th|
000015c0  65 20 64 69 76 69 64 65  6e 64 0d 61 72 65 20 73  |e dividend.are s|
000015d0  65 70 61 72 61 74 65 20  77 6f 72 64 73 20 62 75  |eparate words bu|
000015e0  74 20 79 6f 75 20 77 69  6c 6c 20 6e 6f 74 69 63  |t you will notic|
000015f0  65 20 74 68 61 74 20 61  73 20 74 68 65 20 64 69  |e that as the di|
00001600  76 69 64 65 6e 64 0d 69  73 20 72 6f 74 61 74 65  |vidend.is rotate|
00001610  64 20 6c 65 66 74 20 69  6e 74 6f 20 74 68 65 20  |d left into the |
00001620  61 63 63 75 6d 75 6c 61  74 6f 72 2c 20 62 69 74  |accumulator, bit|
00001630  20 62 79 20 62 69 74 2c  20 65 6d 70 74 79 20 62  | by bit, empty b|
00001640  69 74 73 0d 61 72 65 20  61 64 64 65 64 20 61 74  |its.are added at|
00001650  20 74 68 65 20 72 69 67  68 74 2e 20 20 41 74 20  | the right.  At |
00001660  74 68 65 20 73 61 6d 65  20 74 69 6d 65 20 74 68  |the same time th|
00001670  65 20 72 65 73 75 6c 74  20 69 73 0d 62 65 69 6e  |e result is.bein|
00001680  67 20 72 6f 74 61 74 65  64 20 6c 65 66 74 20 61  |g rotated left a|
00001690  6e 64 20 6d 65 61 6e 69  6e 67 66 75 6c 20 62 69  |nd meaningful bi|
000016a0  74 73 20 61 72 65 20 61  64 64 65 64 20 61 74 20  |ts are added at |
000016b0  74 68 65 0d 72 69 67 68  74 2e 0d 0d 54 68 65 20  |the.right...The |
000016c0  63 68 61 6e 67 65 20 74  6f 20 6d 61 6b 65 20 69  |change to make i|
000016d0  73 20 74 6f 20 63 6f 6d  62 69 6e 65 20 74 68 65  |s to combine the|
000016e0  20 74 77 6f 2e 20 20 54  68 69 73 20 77 61 79 20  | two.  This way |
000016f0  79 6f 75 20 77 69 6c 6c  0d 6e 6f 74 20 68 61 76  |you will.not hav|
00001700  65 20 74 6f 20 63 6c 65  61 72 20 74 68 65 20 72  |e to clear the r|
00001710  65 73 75 6c 74 20 73 70  61 63 65 20 61 74 20 74  |esult space at t|
00001720  68 65 20 62 65 67 69 6e  6e 69 6e 67 2c 20 6f 6e  |he beginning, on|
00001730  6c 79 0d 6f 6e 65 20 77  6f 72 64 20 77 69 6c 6c  |ly.one word will|
00001740  20 62 65 20 72 6f 74 61  74 65 64 20 69 6e 73 74  | be rotated inst|
00001750  65 61 64 20 6f 66 20 74  77 6f 2c 20 61 6e 64 20  |ead of two, and |
00001760  79 6f 75 20 77 69 6c 6c  20 6e 6f 74 0d 68 61 76  |you will not.hav|
00001770  65 20 74 6f 20 74 72 61  6e 73 66 65 72 20 74 68  |e to transfer th|
00001780  65 20 63 6f 6e 74 65 6e  74 73 20 6f 66 20 74 68  |e contents of th|
00001790  65 20 77 6f 72 6b 73 70  61 63 65 73 20 61 74 20  |e workspaces at |
000017a0  74 68 65 20 65 6e 64 0d  6f 66 20 74 68 65 20 64  |the end.of the d|
000017b0  69 76 69 73 69 6f 6e 20  72 6f 75 74 69 6e 65 2e  |ivision routine.|
000017c0  0d 0d 54 68 69 73 20 6c  65 61 64 73 20 74 6f 20  |..This leads to |
000017d0  61 6e 20 61 6c 67 6f 72  69 74 68 6d 20 6c 69 6b  |an algorithm lik|
000017e0  65 20 74 68 69 73 3a 0d  0d 20 20 20 20 53 65 74  |e this:..    Set|
000017f0  20 61 63 63 75 6d 75 6c  61 74 6f 72 20 74 6f 20  | accumulator to |
00001800  7a 65 72 6f 0d 20 20 20  20 4c 6f 6f 70 20 73 74  |zero.    Loop st|
00001810  61 72 74 73 20 68 65 72  65 0d 20 20 20 20 52 6f  |arts here.    Ro|
00001820  74 61 74 65 20 64 69 76  69 64 65 6e 64 2f 72 65  |tate dividend/re|
00001830  73 75 6c 74 20 6c 65 66  74 20 69 6e 74 6f 20 61  |sult left into a|
00001840  63 63 75 6d 75 6c 61 74  6f 72 0d 20 20 20 20 49  |ccumulator.    I|
00001850  66 20 61 63 63 75 6d 75  6c 61 74 6f 72 20 69 73  |f accumulator is|
00001860  20 3c 20 64 69 76 69 73  6f 72 20 72 65 70 65 61  | < divisor repea|
00001870  74 20 6c 6f 6f 70 0d 20  20 20 20 49 66 20 61 63  |t loop.    If ac|
00001880  63 75 6d 75 6c 61 74 6f  72 20 69 73 20 3e 3d 20  |cumulator is >= |
00001890  64 69 76 69 73 6f 72 20  74 68 65 6e 3a 0d 20 20  |divisor then:.  |
000018a0  20 20 20 20 20 20 41 64  64 20 6f 6e 65 20 74 6f  |      Add one to|
000018b0  20 64 69 76 69 64 65 6e  64 2f 72 65 73 75 6c 74  | dividend/result|
000018c0  0d 20 20 20 20 20 20 20  20 53 75 62 74 72 61 63  |.        Subtrac|
000018d0  74 20 64 69 76 69 73 6f  72 20 66 72 6f 6d 20 61  |t divisor from a|
000018e0  63 63 75 6d 75 6c 61 74  6f 72 0d 20 20 20 20 52  |ccumulator.    R|
000018f0  65 70 65 61 74 20 6c 6f  6f 70 20 75 6e 74 69 6c  |epeat loop until|
00001900  20 66 69 6e 69 73 68 65  64 0d 0d 49 74 20 69 73  | finished..It is|
00001910  20 73 69 6d 70 6c 65 20  74 6f 20 6d 61 6b 65 20  | simple to make |
00001920  74 68 69 73 20 63 68 61  6e 67 65 20 62 75 74 20  |this change but |
00001930  69 74 20 73 70 65 65 64  73 20 74 68 69 6e 67 73  |it speeds things|
00001940  20 75 70 20 61 6e 64 0d  61 6c 73 6f 20 72 65 6d  | up and.also rem|
00001950  6f 76 65 73 20 74 68 65  20 6e 65 65 64 20 66 6f  |oves the need fo|
00001960  72 20 6f 6e 65 20 6f 66  20 74 68 65 20 77 6f 72  |r one of the wor|
00001970  6b 73 70 61 63 65 20 77  6f 72 64 73 0d 28 27 72  |kspace words.('r|
00001980  65 73 75 6c 74 27 29 2e  20 20 27 64 69 76 69 64  |esult').  'divid|
00001990  65 6e 64 27 20 6e 6f 77  20 77 69 6c 6c 20 73 74  |end' now will st|
000019a0  61 72 74 20 68 6f 6c 64  69 6e 67 20 74 68 65 20  |art holding the |
000019b0  64 69 76 69 64 65 6e 64  0d 62 75 74 20 77 69 6c  |dividend.but wil|
000019c0  6c 20 67 72 61 64 75 61  6c 6c 79 2c 20 62 69 74  |l gradually, bit|
000019d0  20 62 79 20 62 69 74 2c  20 62 65 63 6f 6d 65 20  | by bit, become |
000019e0  74 68 65 20 72 65 73 75  6c 74 2e 20 20 54 68 69  |the result.  Thi|
000019f0  73 20 69 73 0d 74 68 65  20 6d 65 74 68 6f 64 20  |s is.the method |
00001a00  49 20 77 69 6c 6c 20 75  73 65 20 69 6e 20 61 20  |I will use in a |
00001a10  67 65 6e 65 72 61 6c 20  72 6f 75 74 69 6e 65 20  |general routine |
00001a20  6e 65 78 74 20 74 69 6d  65 2c 20 62 75 74 0d 79  |next time, but.y|
00001a30  6f 75 20 63 6f 75 6c 64  20 74 72 79 20 6d 6f 64  |ou could try mod|
00001a40  69 66 79 69 6e 67 20 74  68 69 73 20 6d 6f 64 75  |ifying this modu|
00001a50  6c 65 20 66 6f 72 20 79  6f 75 72 73 65 6c 66 2e  |le for yourself.|
00001a60  0d                                                |.|
00001a61
20-02-88/T\OSB14.m0
20-02-88/T\OSB14.m1
20-02-88/T\OSB14.m2
20-02-88/T\OSB14.m4
20-02-88/T\OSB14.m5