Home » Archimedes archive » Acorn Computing » 1995 03.adf » 9503 » TechForum/Barnett/DivMod16

TechForum/Barnett/DivMod16

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 » Archimedes archive » Acorn Computing » 1995 03.adf » 9503
Filename: TechForum/Barnett/DivMod16
Read OK:
File size: 01F3 bytes
Load address: 0000
Exec address: 0000
File contents
   10REM M.R.A.Barnett
   20REM 17 Nov 1994
   30
   40REM Divides dividend (0 .. 65535) in 'dnd' by divisor (1 .. 65535) in 'dsr'
   50REM Returns quotient in 'dnd' and remainder in 'dsr'
   60
   70DEF FNDivMod16(dnd, dsr)
   80LOCAL I%
   90IF dnd = dsr THEN ERROR 0, "Needs 2 different registers"
  100[OPT pass%
  110 MOV dsr,dsr,LSL #16
  120 SUB dsr,dsr,#1
  130]
  140FOR I% = 1 TO 16
  150  [OPT pass%
  160   RSBS dnd,dsr,dnd,LSL #1
  170   ADDCC dnd,dnd,dsr
  180 ]
  190NEXT
  200[OPT pass%
  210 MOV dsr,dnd,LSR #16
  220 BIC dnd,dnd,dsr,LSL #16
  230]
  240=0

� M.R.A.Barnett
� 17 Nov 1994

(M� Divides dividend (0 .. 65535) in 'dnd' by divisor (1 .. 65535) in 'dsr'
26� Returns quotient in 'dnd' and remainder in 'dsr'
<
F� �DivMod16(dnd, dsr)
P� I%
Z4� dnd = dsr � � 0, "Needs 2 different registers"
d[OPT pass%
n MOV dsr,dsr,LSL #16
x SUB dsr,dsr,#1
�]
�� I% = 1 � 16
�  [OPT pass%
�   RSBS dnd,dsr,dnd,LSL #1
�   ADDCC dnd,dnd,dsr
� ]
��
�[OPT pass%
� MOV dsr,dnd,LSR #16
� BIC dnd,dnd,dsr,LSL #16
�]
�=0
�
00000000  0d 00 0a 13 f4 20 4d 2e  52 2e 41 2e 42 61 72 6e  |..... M.R.A.Barn|
00000010  65 74 74 0d 00 14 11 f4  20 31 37 20 4e 6f 76 20  |ett..... 17 Nov |
00000020  31 39 39 34 0d 00 1e 04  0d 00 28 4d f4 20 44 69  |1994......(M. Di|
00000030  76 69 64 65 73 20 64 69  76 69 64 65 6e 64 20 28  |vides dividend (|
00000040  30 20 2e 2e 20 36 35 35  33 35 29 20 69 6e 20 27  |0 .. 65535) in '|
00000050  64 6e 64 27 20 62 79 20  64 69 76 69 73 6f 72 20  |dnd' by divisor |
00000060  28 31 20 2e 2e 20 36 35  35 33 35 29 20 69 6e 20  |(1 .. 65535) in |
00000070  27 64 73 72 27 0d 00 32  36 f4 20 52 65 74 75 72  |'dsr'..26. Retur|
00000080  6e 73 20 71 75 6f 74 69  65 6e 74 20 69 6e 20 27  |ns quotient in '|
00000090  64 6e 64 27 20 61 6e 64  20 72 65 6d 61 69 6e 64  |dnd' and remaind|
000000a0  65 72 20 69 6e 20 27 64  73 72 27 0d 00 3c 04 0d  |er in 'dsr'..<..|
000000b0  00 46 19 dd 20 a4 44 69  76 4d 6f 64 31 36 28 64  |.F.. .DivMod16(d|
000000c0  6e 64 2c 20 64 73 72 29  0d 00 50 08 ea 20 49 25  |nd, dsr)..P.. I%|
000000d0  0d 00 5a 34 e7 20 64 6e  64 20 3d 20 64 73 72 20  |..Z4. dnd = dsr |
000000e0  8c 20 85 20 30 2c 20 22  4e 65 65 64 73 20 32 20  |. . 0, "Needs 2 |
000000f0  64 69 66 66 65 72 65 6e  74 20 72 65 67 69 73 74  |different regist|
00000100  65 72 73 22 0d 00 64 0e  5b 4f 50 54 20 70 61 73  |ers"..d.[OPT pas|
00000110  73 25 0d 00 6e 18 20 4d  4f 56 20 64 73 72 2c 64  |s%..n. MOV dsr,d|
00000120  73 72 2c 4c 53 4c 20 23  31 36 0d 00 78 13 20 53  |sr,LSL #16..x. S|
00000130  55 42 20 64 73 72 2c 64  73 72 2c 23 31 0d 00 82  |UB dsr,dsr,#1...|
00000140  05 5d 0d 00 8c 11 e3 20  49 25 20 3d 20 31 20 b8  |.]..... I% = 1 .|
00000150  20 31 36 0d 00 96 10 20  20 5b 4f 50 54 20 70 61  | 16....  [OPT pa|
00000160  73 73 25 0d 00 a0 1e 20  20 20 52 53 42 53 20 64  |ss%....   RSBS d|
00000170  6e 64 2c 64 73 72 2c 64  6e 64 2c 4c 53 4c 20 23  |nd,dsr,dnd,LSL #|
00000180  31 0d 00 aa 18 20 20 20  41 44 44 43 43 20 64 6e  |1....   ADDCC dn|
00000190  64 2c 64 6e 64 2c 64 73  72 0d 00 b4 06 20 5d 0d  |d,dnd,dsr.... ].|
000001a0  00 be 05 ed 0d 00 c8 0e  5b 4f 50 54 20 70 61 73  |........[OPT pas|
000001b0  73 25 0d 00 d2 18 20 4d  4f 56 20 64 73 72 2c 64  |s%.... MOV dsr,d|
000001c0  6e 64 2c 4c 53 52 20 23  31 36 0d 00 dc 1c 20 42  |nd,LSR #16.... B|
000001d0  49 43 20 64 6e 64 2c 64  6e 64 2c 64 73 72 2c 4c  |IC dnd,dnd,dsr,L|
000001e0  53 4c 20 23 31 36 0d 00  e6 05 5d 0d 00 f0 06 3d  |SL #16....]....=|
000001f0  30 0d ff                                          |0..|
000001f3