Modify this Mult.asm program to
@R2
M=0 // set r2 = to 0
@R0
D=M
@count
M=D // count = to r's
(LOOP)
@count
D=M // set d equal to count
@END
D;JEQ // if count = 0, go to the end
@R1
D=M // D=R1
@R2
M=D+M // add R1 to sum
@count
M=M-1 // decrement the count
@LOOP
0;JMP // jump to the loop
(END)
@END
0;JMP
// Multiplies R0 and R1 and stores the result in R2.
// (R0, R1, R2 refer to RAM[0], RAM[1], and RAM[2],
respectively.)
// 2, 3
// Put your code here.
// bail early
@R2
M = 0
@R0
D = M
@END
D;JEQ
@R1
D = M
@END
D;JEQ
@R1
D = M
@i
M = D // set up counter - count down from R1
(LOOP)
@R0
D = M
@R2
M = M + D
@i
M = M - 1
@i
D = M
@loop
D;JEQ
@end
D;JMP
(END)
@end
0;JMP
OUTPUT
| RAM[0] | RAM[1] | RAM[2] |
| 0 | 0 | 0 |
| 1 | 0 | 0 |
| 0 | 2 | 0 |
| 3 | 1 | 3 |
| 2 | 4 | 2 |
| 6 | 7 | 6 |
Get Answers For Free
Most questions answered within 1 hours.