Home » Archimedes archive » Acorn User » AU 1996-02.adf » Regulars » StarInfo/Wells/Russian
StarInfo/Wells/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-02.adf » Regulars |
| Filename: | StarInfo/Wells/Russian |
| Read OK: | ✔ |
| File size: | 04F8 bytes |
| Load address: | 0000 |
| Exec address: | 0000 |
File contents
10REM ARM Program to carry out multiplication of any long numbers 20REM using the Russian peasant method. 30REM Written by Jonathan Wells 40REM 15th April 1995 50 60DIM Long_Multiplication 256 70 80first = 1 :REM B% 90second = 2 :REM C% 100answer = 0 110 120FOR pass% = 0 TO 3 STEP 3 130P%=Long_Multiplication 140[ 150OPT pass% 160MOV answer,#0 170TST first,#%01 ;See if multiplicand odd 180ADDNE answer,answer,second ;If odd then add multiplier to the answer 190 ;register 200.loop1 210MOV first,first,LSR#1 ;Divides the multiplicand by 2 ignoring 220 ;the remainders 230MOV second,second,LSL#1 ;Multiplies the multiplier by 2 240TST first,#%01 ;See if halved multiplicand odd 250ADDNE answer,answer,second ;If odd then add doubled multiplier to the 260 ;answer register 270CMP first,#1 ;See if halved multiplicand is equal to one 280BNE loop1 290MOV PC,R14 300] 310NEXT pass% 320 330CLS 340REPEAT 350PRINT "Numbers input must be > 1 and integers" 360PRINT "Press ESCAPE to finish" 370INPUT "Multiplicand",B% 380INPUT "Multiplier",C% 390result=USR(Long_Multiplication) 400PRINT "answer is = "result 410UNTIL FALSE 420END
A� ARM Program to carry out multiplication of any long numbers '� using the Russian peasant method. � Written by Jonathan Wells (� 15th April 1995 2 <� Long_Multiplication 256 F Pfirst = 1 :� B% Zsecond = 2 :� C% danswer = 0 n x� pass% = 0 � 3 � 3 �P%=Long_Multiplication �[ � OPT pass% �MOV answer,#0 �>TST first,#%01 ;See if multiplicand odd �OADDNE answer,answer,second ;If odd then add multiplier to the answer �/ ;register � .loop1 �MMOV first,first,LSR#1 ;Divides the multiplicand by 2 ignoring �5 ;the remainders �EMOV second,second,LSL#1 ;Multiplies the multiplier by 2 �ETST first,#%01 ;See if halved multiplicand odd �PADDNE answer,answer,second ;If odd then add doubled multiplier to the 6 ;answer register QCMP first,#1 ;See if halved multiplicand is equal to one BNE loop1 "MOV PC,R14 ,] 6� pass% @ J� T� ^.� "Numbers input must be > 1 and integers" h� "Press ESCAPE to finish" r� "Multiplicand",B% |� "Multiplier",C% �!result=�(Long_Multiplication) �� "answer is = "result �� � �� �
00000000 0d 00 0a 41 f4 20 41 52 4d 20 50 72 6f 67 72 61 |...A. ARM Progra| 00000010 6d 20 74 6f 20 63 61 72 72 79 20 6f 75 74 20 6d |m to carry out m| 00000020 75 6c 74 69 70 6c 69 63 61 74 69 6f 6e 20 6f 66 |ultiplication of| 00000030 20 61 6e 79 20 6c 6f 6e 67 20 6e 75 6d 62 65 72 | any long number| 00000040 73 0d 00 14 27 f4 20 75 73 69 6e 67 20 74 68 65 |s...'. using the| 00000050 20 52 75 73 73 69 61 6e 20 70 65 61 73 61 6e 74 | Russian peasant| 00000060 20 6d 65 74 68 6f 64 2e 0d 00 1e 1f f4 20 57 72 | method...... Wr| 00000070 69 74 74 65 6e 20 62 79 20 4a 6f 6e 61 74 68 61 |itten by Jonatha| 00000080 6e 20 57 65 6c 6c 73 0d 00 28 15 f4 20 31 35 74 |n Wells..(.. 15t| 00000090 68 20 41 70 72 69 6c 20 31 39 39 35 0d 00 32 04 |h April 1995..2.| 000000a0 0d 00 3c 1d de 20 4c 6f 6e 67 5f 4d 75 6c 74 69 |..<.. Long_Multi| 000000b0 70 6c 69 63 61 74 69 6f 6e 20 32 35 36 0d 00 46 |plication 256..F| 000000c0 04 0d 00 50 17 66 69 72 73 74 20 3d 20 31 20 20 |...P.first = 1 | 000000d0 20 20 20 3a f4 20 42 25 0d 00 5a 17 73 65 63 6f | :. B%..Z.seco| 000000e0 6e 64 20 3d 20 32 20 20 20 20 3a f4 20 43 25 0d |nd = 2 :. C%.| 000000f0 00 64 0e 61 6e 73 77 65 72 20 3d 20 30 0d 00 6e |.d.answer = 0..n| 00000100 04 0d 00 78 17 e3 20 70 61 73 73 25 20 3d 20 30 |...x.. pass% = 0| 00000110 20 b8 20 33 20 88 20 33 0d 00 82 1a 50 25 3d 4c | . 3 . 3....P%=L| 00000120 6f 6e 67 5f 4d 75 6c 74 69 70 6c 69 63 61 74 69 |ong_Multiplicati| 00000130 6f 6e 0d 00 8c 05 5b 0d 00 96 0d 4f 50 54 20 70 |on....[....OPT p| 00000140 61 73 73 25 0d 00 a0 11 4d 4f 56 20 61 6e 73 77 |ass%....MOV answ| 00000150 65 72 2c 23 30 0d 00 aa 3e 54 53 54 20 20 66 69 |er,#0...>TST fi| 00000160 72 73 74 2c 23 25 30 31 20 20 20 20 20 20 20 20 |rst,#%01 | 00000170 20 20 20 20 20 20 20 20 20 20 20 3b 53 65 65 20 | ;See | 00000180 69 66 20 6d 75 6c 74 69 70 6c 69 63 61 6e 64 20 |if multiplicand | 00000190 6f 64 64 0d 00 b4 4f 41 44 44 4e 45 20 61 6e 73 |odd...OADDNE ans| 000001a0 77 65 72 2c 61 6e 73 77 65 72 2c 73 65 63 6f 6e |wer,answer,secon| 000001b0 64 20 20 20 20 20 20 20 20 3b 49 66 20 6f 64 64 |d ;If odd| 000001c0 20 74 68 65 6e 20 61 64 64 20 6d 75 6c 74 69 70 | then add multip| 000001d0 6c 69 65 72 20 74 6f 20 74 68 65 20 61 6e 73 77 |lier to the answ| 000001e0 65 72 0d 00 be 2f 20 20 20 20 20 20 20 20 20 20 |er.../ | 000001f0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | 00000200 20 20 20 20 20 20 20 20 3b 72 65 67 69 73 74 65 | ;registe| 00000210 72 0d 00 c8 0a 2e 6c 6f 6f 70 31 0d 00 d2 4d 4d |r.....loop1...MM| 00000220 4f 56 20 66 69 72 73 74 2c 66 69 72 73 74 2c 4c |OV first,first,L| 00000230 53 52 23 31 20 20 20 20 20 20 20 20 20 20 20 20 |SR#1 | 00000240 20 3b 44 69 76 69 64 65 73 20 74 68 65 20 6d 75 | ;Divides the mu| 00000250 6c 74 69 70 6c 69 63 61 6e 64 20 62 79 20 32 20 |ltiplicand by 2 | 00000260 69 67 6e 6f 72 69 6e 67 0d 00 dc 35 20 20 20 20 |ignoring...5 | 00000270 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | 00000280 20 20 20 20 20 20 20 20 20 20 20 20 20 20 3b 74 | ;t| 00000290 68 65 20 72 65 6d 61 69 6e 64 65 72 73 0d 00 e6 |he remainders...| 000002a0 45 4d 4f 56 20 73 65 63 6f 6e 64 2c 73 65 63 6f |EMOV second,seco| 000002b0 6e 64 2c 4c 53 4c 23 31 20 20 20 20 20 20 20 20 |nd,LSL#1 | 000002c0 20 20 20 3b 4d 75 6c 74 69 70 6c 69 65 73 20 74 | ;Multiplies t| 000002d0 68 65 20 6d 75 6c 74 69 70 6c 69 65 72 20 62 79 |he multiplier by| 000002e0 20 32 0d 00 f0 45 54 53 54 20 20 66 69 72 73 74 | 2...ETST first| 000002f0 2c 23 25 30 31 20 20 20 20 20 20 20 20 20 20 20 |,#%01 | 00000300 20 20 20 20 20 20 20 20 3b 53 65 65 20 69 66 20 | ;See if | 00000310 68 61 6c 76 65 64 20 6d 75 6c 74 69 70 6c 69 63 |halved multiplic| 00000320 61 6e 64 20 6f 64 64 0d 00 fa 50 41 44 44 4e 45 |and odd...PADDNE| 00000330 20 61 6e 73 77 65 72 2c 61 6e 73 77 65 72 2c 73 | answer,answer,s| 00000340 65 63 6f 6e 64 20 20 20 20 20 20 20 20 3b 49 66 |econd ;If| 00000350 20 6f 64 64 20 74 68 65 6e 20 61 64 64 20 64 6f | odd then add do| 00000360 75 62 6c 65 64 20 6d 75 6c 74 69 70 6c 69 65 72 |ubled multiplier| 00000370 20 74 6f 20 74 68 65 0d 01 04 36 20 20 20 20 20 | to the...6 | 00000380 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | 00000390 20 20 20 20 20 20 20 20 20 20 20 20 20 3b 61 6e | ;an| 000003a0 73 77 65 72 20 72 65 67 69 73 74 65 72 0d 01 0e |swer register...| 000003b0 51 43 4d 50 20 66 69 72 73 74 2c 23 31 20 20 20 |QCMP first,#1 | 000003c0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | 000003d0 20 20 20 3b 53 65 65 20 69 66 20 68 61 6c 76 65 | ;See if halve| 000003e0 64 20 6d 75 6c 74 69 70 6c 69 63 61 6e 64 20 69 |d multiplicand i| 000003f0 73 20 65 71 75 61 6c 20 74 6f 20 6f 6e 65 0d 01 |s equal to one..| 00000400 18 0d 42 4e 45 20 6c 6f 6f 70 31 0d 01 22 0e 4d |..BNE loop1..".M| 00000410 4f 56 20 50 43 2c 52 31 34 0d 01 2c 05 5d 0d 01 |OV PC,R14..,.]..| 00000420 36 0b ed 20 70 61 73 73 25 0d 01 40 04 0d 01 4a |6.. pass%..@...J| 00000430 05 db 0d 01 54 05 f5 0d 01 5e 2e f1 20 22 4e 75 |....T....^.. "Nu| 00000440 6d 62 65 72 73 20 69 6e 70 75 74 20 6d 75 73 74 |mbers input must| 00000450 20 62 65 20 3e 20 31 20 61 6e 64 20 69 6e 74 65 | be > 1 and inte| 00000460 67 65 72 73 22 0d 01 68 1e f1 20 22 50 72 65 73 |gers"..h.. "Pres| 00000470 73 20 45 53 43 41 50 45 20 74 6f 20 66 69 6e 69 |s ESCAPE to fini| 00000480 73 68 22 0d 01 72 17 e8 20 22 4d 75 6c 74 69 70 |sh"..r.. "Multip| 00000490 6c 69 63 61 6e 64 22 2c 42 25 0d 01 7c 15 e8 20 |licand",B%..|.. | 000004a0 22 4d 75 6c 74 69 70 6c 69 65 72 22 2c 43 25 0d |"Multiplier",C%.| 000004b0 01 86 21 72 65 73 75 6c 74 3d ba 28 4c 6f 6e 67 |..!result=.(Long| 000004c0 5f 4d 75 6c 74 69 70 6c 69 63 61 74 69 6f 6e 29 |_Multiplication)| 000004d0 0d 01 90 1a f1 20 22 61 6e 73 77 65 72 20 69 73 |..... "answer is| 000004e0 20 3d 20 22 72 65 73 75 6c 74 0d 01 9a 07 fd 20 | = "result..... | 000004f0 a3 0d 01 a4 05 e0 0d ff |........| 000004f8
.