!lm12
!rm76
On Dividing by Ten...............................Jim Church

Some time ago you asked readers to come up with subroutines to divide by ten (or multiply by one-tenth).  I may have come up with the smallest one, although it is certainly not the fastest.

By using SWEET-16 to merely subtract 10 over and over, until the remainder is less than 10, and counting the number of subtractions, I can divide a 16-bit value by ten in a 10-byte subroutine!

In fact, you can divide by any 16-bit value.  My program assumes the divisor is in $02,03 and the dividend is in  $04,05.  These are the Sweet-16 registers 1 and 2.  The quotient will be left in $04,05; the remainder will be in $00,01.

I used a copy of Sweet-16 in RAM, from the source code on the S-C Assembler II disk.  If you use the copy in the Integer BASIC ROM's, or in the RAM card Integer BASIC, change line 1130 to "SW16 .EQ $F689".

Here is the program listing:
