Reputation: 1
In Marie simulator, how would I multiply 3 positive numbers (Ex. 21 19 and 23) and store the result to a variable product using a loop? I'm new to Marie and can't figure this out. Thanks!
Upvotes: 0
Views: 3204
Reputation:
I used two variables Sum1 and Sum2 for the iterations. Sum1 adds the first variable by the count of the second variable. This total is then added by the count of the third variable. The result at the end is your product
.
For example:
2 x 3 x 4
2 + 2 + 2 = 6 (Sum1
add 2, 3 times)
6 + 6 + 6 + 6 = 24 (Sum2
add 6, 4 times)
Input
Store A
Input
Store B
Input
Store C
Load B
Store Count /Set count for B times
Loop1, Load A
Add Sum1
Output /Track process
Store Sum1
Load Count
Subt One
Store Count
Skipcond 800
Jump Count2
Jump Loop1
Count2, Load C
Store Count /Set count for C times
Loop2, Load Sum1
Add Sum2
Store Sum2 /Final Sum2 == Product
Output /Track process
Load Count
Subt One
Store Count
Skipcond 800
Jump End
Jump Loop2
End, Load Sum2
Output
Halt
A, Dec 0
B, Dec 0
C, Dec 0
Sum1, Dec 0
Sum2, Dec 0
Count, Dec 0
One, Dec 1
Upvotes: 0