Ethiopian multiplication: Difference between revisions
Content added Content deleted
m (→{{header|XBasic}}: Title in comment) |
(→{{header|ASIC}}: Added) |
||
Line 705: | Line 705: | ||
=={{header|BASIC}}== |
=={{header|BASIC}}== |
||
==={{header|ASIC}}=== |
|||
<lang basic> |
|||
REM Ethiopian multiplication |
|||
X = 17 |
|||
Y = 34 |
|||
TOT = 0 |
|||
WHILE X >= 1 |
|||
PRINT X; |
|||
PRINT " "; |
|||
A = X |
|||
GOSUB CHECKEVEN: |
|||
IF ISEVEN = 0 THEN |
|||
TOT = TOT + Y |
|||
PRINT Y; |
|||
ENDIF |
|||
PRINT |
|||
A = X |
|||
GOSUB HALVE: |
|||
X = A |
|||
A = Y |
|||
GOSUB DOUBLE: |
|||
Y = A |
|||
WEND |
|||
PRINT "= "; |
|||
PRINT TOT |
|||
END |
|||
REM Subroutines are required, though |
|||
REM they complicate the code |
|||
DOUBLE: |
|||
A = 2 * A |
|||
RETURN |
|||
HALVE: |
|||
A = A / 2 |
|||
RETURN |
|||
CHECKEVEN: |
|||
REM ISEVEN - result (0 if A odd, 1 otherwise) |
|||
ISEVEN = A MOD 2 |
|||
ISEVEN = 1 - ISEVEN |
|||
RETURN |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
17 34 |
|||
8 |
|||
4 |
|||
2 |
|||
1 544 |
|||
= 578 |
|||
</pre> |
|||
==={{header|BASIC}}=== |
==={{header|BASIC}}=== |