Home » Archimedes archive » Acorn User » AU 1996-Xmas.adf » Regulars » StarInfo/Booker/Russian

StarInfo/Booker/Russian

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 User » AU 1996-Xmas.adf » Regulars
Filename: StarInfo/Booker/Russian
Read OK:
File size: 0640 bytes
Load address: 0000
Exec address: 0000
File contents
   10REM Russian medieval multiplication using 6502 code
   20REM by Andrew Booker 3/6/96
   30
   40
   50REM multiplies 2 two byte integers to give a four
   60REM byte result. Note that because the second number
   70REM is always doubled, it requires four bytes to
   80REM store it, not two.
   90
  100first=&70:second=&72:result=&76
  110FOR pass=0 TO 2 STEP2
  120P%=&900
  130[OPT pass
  140.loop
  150
  160\ check for first no. being odd
  170LDA first
  180ROR A
  190BCC notodd
  200\ add second to the result
  210CLC
  220LDA second  :ADC result  :STA result
  230LDA second+1:ADC result+1:STA result+1
  240LDA second+2:ADC result+2:STA result+2
  250LDA second+3:ADC result+3:STA result+3
  260
  270.notodd
  280\ halve first number
  290CLC
  300ROR first+1
  310ROR first
  320
  330\ double second number
  340CLC
  350ROL second
  360ROL second+1
  370ROL second+2
  380ROL second+3
  390
  400\ see if first number is now zero
  410\ (if it is, then we will have just done
  420\  the addition for when it was one, and
  430\  therefore we need to stop now)
  440LDA first  :CMP #0:BNE loop
  450LDA first+1:CMP #0:BNE loop
  460
  470\ exit
  480RTS
  490]:NEXT
  500
  510
  520
  530
  540PRINT"Enter integer numbers to multiply:"
  550PRINT"(between 1 and 32767)"
  560INPUT"First number :"first%
  570INPUT"Second number:"second%
  580
  590REM numbers must be in the range 1-32767 to make
  600REM sure the final 4 byte integer does not appear
  610REM to BASIC as being negative (ie top bit set)
  620IF first%<1      THEN first%=1
  630IF first%>32767  THEN first%=32767
  640IF second%<1     THEN second%=1
  650IF second%>32767 THEN second%=32767
  660
  670!first=first%
  680!second=second%
  690!result=0
  700CALL &900
  710
  720PRINT;first%;" * ";second%;" = ";!result

5� Russian medieval multiplication using 6502 code
� by Andrew Booker 3/6/96

(
23� multiplies 2 two byte integers to give a four
<6� byte result. Note that because the second number
F2� is always doubled, it requires four bytes to
P� store it, not two.
Z
d#first=&70:second=&72:result=&76
n� pass=0 � 2 �2
xP%=&900
�
[OPT pass
�	.loop
�
�#\ check for first no. being odd
�
LDA first
�	ROR A
�BCC notodd
�\ add second to the result
�CLC
�(LDA second  :ADC result  :STA result
�*LDA second+1:ADC result+1:STA result+1
�*LDA second+2:ADC result+2:STA result+2
�*LDA second+3:ADC result+3:STA result+3

.notodd
\ halve first number
"CLC
,ROR first+1
6
ROR first
@
J\ double second number
TCLC
^ROL second
hROL second+1
rROL second+2
|ROL second+3
�
�%\ see if first number is now zero
�,\ (if it is, then we will have just done
�,\  the addition for when it was one, and
�%\  therefore we need to stop now)
�LDA first  :CMP #0:BNE loop
�LDA first+1:CMP #0:BNE loop
�
�
\ exit
�RTS
�]:�
�
�


)�"Enter integer numbers to multiply:"
&�"(between 1 and 32767)"
0�"First number :"first%
:�"Second number:"second%
D
N2� numbers must be in the range 1-32767 to make
X3� sure the final 4 byte integer does not appear
b1� to BASIC as being negative (ie top bit set)
l� first%<1      � first%=1
v"� first%>32767  � first%=32767
�� second%<1     � second%=1
�#� second%>32767 � second%=32767
�
�!first=first%
�!second=second%
�
!result=0
�
� &900
�
�(�;first%;" * ";second%;" = ";!result
�
00000000  0d 00 0a 35 f4 20 52 75  73 73 69 61 6e 20 6d 65  |...5. Russian me|
00000010  64 69 65 76 61 6c 20 6d  75 6c 74 69 70 6c 69 63  |dieval multiplic|
00000020  61 74 69 6f 6e 20 75 73  69 6e 67 20 36 35 30 32  |ation using 6502|
00000030  20 63 6f 64 65 0d 00 14  1d f4 20 62 79 20 41 6e  | code..... by An|
00000040  64 72 65 77 20 42 6f 6f  6b 65 72 20 33 2f 36 2f  |drew Booker 3/6/|
00000050  39 36 0d 00 1e 04 0d 00  28 04 0d 00 32 33 f4 20  |96......(...23. |
00000060  6d 75 6c 74 69 70 6c 69  65 73 20 32 20 74 77 6f  |multiplies 2 two|
00000070  20 62 79 74 65 20 69 6e  74 65 67 65 72 73 20 74  | byte integers t|
00000080  6f 20 67 69 76 65 20 61  20 66 6f 75 72 0d 00 3c  |o give a four..<|
00000090  36 f4 20 62 79 74 65 20  72 65 73 75 6c 74 2e 20  |6. byte result. |
000000a0  4e 6f 74 65 20 74 68 61  74 20 62 65 63 61 75 73  |Note that becaus|
000000b0  65 20 74 68 65 20 73 65  63 6f 6e 64 20 6e 75 6d  |e the second num|
000000c0  62 65 72 0d 00 46 32 f4  20 69 73 20 61 6c 77 61  |ber..F2. is alwa|
000000d0  79 73 20 64 6f 75 62 6c  65 64 2c 20 69 74 20 72  |ys doubled, it r|
000000e0  65 71 75 69 72 65 73 20  66 6f 75 72 20 62 79 74  |equires four byt|
000000f0  65 73 20 74 6f 0d 00 50  18 f4 20 73 74 6f 72 65  |es to..P.. store|
00000100  20 69 74 2c 20 6e 6f 74  20 74 77 6f 2e 0d 00 5a  | it, not two...Z|
00000110  04 0d 00 64 23 66 69 72  73 74 3d 26 37 30 3a 73  |...d#first=&70:s|
00000120  65 63 6f 6e 64 3d 26 37  32 3a 72 65 73 75 6c 74  |econd=&72:result|
00000130  3d 26 37 36 0d 00 6e 13  e3 20 70 61 73 73 3d 30  |=&76..n.. pass=0|
00000140  20 b8 20 32 20 88 32 0d  00 78 0b 50 25 3d 26 39  | . 2 .2..x.P%=&9|
00000150  30 30 0d 00 82 0d 5b 4f  50 54 20 70 61 73 73 0d  |00....[OPT pass.|
00000160  00 8c 09 2e 6c 6f 6f 70  0d 00 96 04 0d 00 a0 23  |....loop.......#|
00000170  5c 20 63 68 65 63 6b 20  66 6f 72 20 66 69 72 73  |\ check for firs|
00000180  74 20 6e 6f 2e 20 62 65  69 6e 67 20 6f 64 64 0d  |t no. being odd.|
00000190  00 aa 0d 4c 44 41 20 66  69 72 73 74 0d 00 b4 09  |...LDA first....|
000001a0  52 4f 52 20 41 0d 00 be  0e 42 43 43 20 6e 6f 74  |ROR A....BCC not|
000001b0  6f 64 64 0d 00 c8 1e 5c  20 61 64 64 20 73 65 63  |odd....\ add sec|
000001c0  6f 6e 64 20 74 6f 20 74  68 65 20 72 65 73 75 6c  |ond to the resul|
000001d0  74 0d 00 d2 07 43 4c 43  0d 00 dc 28 4c 44 41 20  |t....CLC...(LDA |
000001e0  73 65 63 6f 6e 64 20 20  3a 41 44 43 20 72 65 73  |second  :ADC res|
000001f0  75 6c 74 20 20 3a 53 54  41 20 72 65 73 75 6c 74  |ult  :STA result|
00000200  0d 00 e6 2a 4c 44 41 20  73 65 63 6f 6e 64 2b 31  |...*LDA second+1|
00000210  3a 41 44 43 20 72 65 73  75 6c 74 2b 31 3a 53 54  |:ADC result+1:ST|
00000220  41 20 72 65 73 75 6c 74  2b 31 0d 00 f0 2a 4c 44  |A result+1...*LD|
00000230  41 20 73 65 63 6f 6e 64  2b 32 3a 41 44 43 20 72  |A second+2:ADC r|
00000240  65 73 75 6c 74 2b 32 3a  53 54 41 20 72 65 73 75  |esult+2:STA resu|
00000250  6c 74 2b 32 0d 00 fa 2a  4c 44 41 20 73 65 63 6f  |lt+2...*LDA seco|
00000260  6e 64 2b 33 3a 41 44 43  20 72 65 73 75 6c 74 2b  |nd+3:ADC result+|
00000270  33 3a 53 54 41 20 72 65  73 75 6c 74 2b 33 0d 01  |3:STA result+3..|
00000280  04 04 0d 01 0e 0b 2e 6e  6f 74 6f 64 64 0d 01 18  |.......notodd...|
00000290  18 5c 20 68 61 6c 76 65  20 66 69 72 73 74 20 6e  |.\ halve first n|
000002a0  75 6d 62 65 72 0d 01 22  07 43 4c 43 0d 01 2c 0f  |umber..".CLC..,.|
000002b0  52 4f 52 20 66 69 72 73  74 2b 31 0d 01 36 0d 52  |ROR first+1..6.R|
000002c0  4f 52 20 66 69 72 73 74  0d 01 40 04 0d 01 4a 1a  |OR first..@...J.|
000002d0  5c 20 64 6f 75 62 6c 65  20 73 65 63 6f 6e 64 20  |\ double second |
000002e0  6e 75 6d 62 65 72 0d 01  54 07 43 4c 43 0d 01 5e  |number..T.CLC..^|
000002f0  0e 52 4f 4c 20 73 65 63  6f 6e 64 0d 01 68 10 52  |.ROL second..h.R|
00000300  4f 4c 20 73 65 63 6f 6e  64 2b 31 0d 01 72 10 52  |OL second+1..r.R|
00000310  4f 4c 20 73 65 63 6f 6e  64 2b 32 0d 01 7c 10 52  |OL second+2..|.R|
00000320  4f 4c 20 73 65 63 6f 6e  64 2b 33 0d 01 86 04 0d  |OL second+3.....|
00000330  01 90 25 5c 20 73 65 65  20 69 66 20 66 69 72 73  |..%\ see if firs|
00000340  74 20 6e 75 6d 62 65 72  20 69 73 20 6e 6f 77 20  |t number is now |
00000350  7a 65 72 6f 0d 01 9a 2c  5c 20 28 69 66 20 69 74  |zero...,\ (if it|
00000360  20 69 73 2c 20 74 68 65  6e 20 77 65 20 77 69 6c  | is, then we wil|
00000370  6c 20 68 61 76 65 20 6a  75 73 74 20 64 6f 6e 65  |l have just done|
00000380  0d 01 a4 2c 5c 20 20 74  68 65 20 61 64 64 69 74  |...,\  the addit|
00000390  69 6f 6e 20 66 6f 72 20  77 68 65 6e 20 69 74 20  |ion for when it |
000003a0  77 61 73 20 6f 6e 65 2c  20 61 6e 64 0d 01 ae 25  |was one, and...%|
000003b0  5c 20 20 74 68 65 72 65  66 6f 72 65 20 77 65 20  |\  therefore we |
000003c0  6e 65 65 64 20 74 6f 20  73 74 6f 70 20 6e 6f 77  |need to stop now|
000003d0  29 0d 01 b8 1f 4c 44 41  20 66 69 72 73 74 20 20  |)....LDA first  |
000003e0  3a 43 4d 50 20 23 30 3a  42 4e 45 20 6c 6f 6f 70  |:CMP #0:BNE loop|
000003f0  0d 01 c2 1f 4c 44 41 20  66 69 72 73 74 2b 31 3a  |....LDA first+1:|
00000400  43 4d 50 20 23 30 3a 42  4e 45 20 6c 6f 6f 70 0d  |CMP #0:BNE loop.|
00000410  01 cc 04 0d 01 d6 0a 5c  20 65 78 69 74 0d 01 e0  |.......\ exit...|
00000420  07 52 54 53 0d 01 ea 07  5d 3a ed 0d 01 f4 04 0d  |.RTS....]:......|
00000430  01 fe 04 0d 02 08 04 0d  02 12 04 0d 02 1c 29 f1  |..............).|
00000440  22 45 6e 74 65 72 20 69  6e 74 65 67 65 72 20 6e  |"Enter integer n|
00000450  75 6d 62 65 72 73 20 74  6f 20 6d 75 6c 74 69 70  |umbers to multip|
00000460  6c 79 3a 22 0d 02 26 1c  f1 22 28 62 65 74 77 65  |ly:"..&.."(betwe|
00000470  65 6e 20 31 20 61 6e 64  20 33 32 37 36 37 29 22  |en 1 and 32767)"|
00000480  0d 02 30 1b e8 22 46 69  72 73 74 20 6e 75 6d 62  |..0.."First numb|
00000490  65 72 20 3a 22 66 69 72  73 74 25 0d 02 3a 1c e8  |er :"first%..:..|
000004a0  22 53 65 63 6f 6e 64 20  6e 75 6d 62 65 72 3a 22  |"Second number:"|
000004b0  73 65 63 6f 6e 64 25 0d  02 44 04 0d 02 4e 32 f4  |second%..D...N2.|
000004c0  20 6e 75 6d 62 65 72 73  20 6d 75 73 74 20 62 65  | numbers must be|
000004d0  20 69 6e 20 74 68 65 20  72 61 6e 67 65 20 31 2d  | in the range 1-|
000004e0  33 32 37 36 37 20 74 6f  20 6d 61 6b 65 0d 02 58  |32767 to make..X|
000004f0  33 f4 20 73 75 72 65 20  74 68 65 20 66 69 6e 61  |3. sure the fina|
00000500  6c 20 34 20 62 79 74 65  20 69 6e 74 65 67 65 72  |l 4 byte integer|
00000510  20 64 6f 65 73 20 6e 6f  74 20 61 70 70 65 61 72  | does not appear|
00000520  0d 02 62 31 f4 20 74 6f  20 42 41 53 49 43 20 61  |..b1. to BASIC a|
00000530  73 20 62 65 69 6e 67 20  6e 65 67 61 74 69 76 65  |s being negative|
00000540  20 28 69 65 20 74 6f 70  20 62 69 74 20 73 65 74  | (ie top bit set|
00000550  29 0d 02 6c 1e e7 20 66  69 72 73 74 25 3c 31 20  |)..l.. first%<1 |
00000560  20 20 20 20 20 8c 20 66  69 72 73 74 25 3d 31 0d  |     . first%=1.|
00000570  02 76 22 e7 20 66 69 72  73 74 25 3e 33 32 37 36  |.v". first%>3276|
00000580  37 20 20 8c 20 66 69 72  73 74 25 3d 33 32 37 36  |7  . first%=3276|
00000590  37 0d 02 80 1f e7 20 73  65 63 6f 6e 64 25 3c 31  |7..... second%<1|
000005a0  20 20 20 20 20 8c 20 73  65 63 6f 6e 64 25 3d 31  |     . second%=1|
000005b0  0d 02 8a 23 e7 20 73 65  63 6f 6e 64 25 3e 33 32  |...#. second%>32|
000005c0  37 36 37 20 8c 20 73 65  63 6f 6e 64 25 3d 33 32  |767 . second%=32|
000005d0  37 36 37 0d 02 94 04 0d  02 9e 11 21 66 69 72 73  |767........!firs|
000005e0  74 3d 66 69 72 73 74 25  0d 02 a8 13 21 73 65 63  |t=first%....!sec|
000005f0  6f 6e 64 3d 73 65 63 6f  6e 64 25 0d 02 b2 0d 21  |ond=second%....!|
00000600  72 65 73 75 6c 74 3d 30  0d 02 bc 0a d6 20 26 39  |result=0..... &9|
00000610  30 30 0d 02 c6 04 0d 02  d0 28 f1 3b 66 69 72 73  |00.......(.;firs|
00000620  74 25 3b 22 20 2a 20 22  3b 73 65 63 6f 6e 64 25  |t%;" * ";second%|
00000630  3b 22 20 3d 20 22 3b 21  72 65 73 75 6c 74 0d ff  |;" = ";!result..|
00000640