Re-do Mult.asm
x1phosura x1phosura@x1phosura.zone
Sat, 11 Dec 2021 17:44:03 -0800
1 files changed,
43 insertions(+),
1 deletions(-)
jump to
M
projects/04/mult/Mult.asm
→
projects/04/mult/Mult.asm
@@ -9,4 +9,46 @@ //
// This program only needs to handle arguments that satisfy // R0 >= 0, R1 >= 0, and R0*R1 < 32768. -// Put your code here.+// Put your code here. + +// Repeated addition, use R3 as temp +// R2 = 0 +// for (R3 = R0; R3 > 0; --R3) +// R2 += R1 + + // R2 = 0 + @R2 + M=0 + + // R3 = R0 + @R0 + D=M + @R3 + M=D + +(ADD_LOOP) + // D=R3, if D == 0, goto END + @R3 + D=M + @END + D;JEQ + + // D = R1 + @R1 + D=M + + // R2 += D + @R2 + M=D+M + + // --R3 + @R3 + M=M-1 + + @ADD_LOOP + 0;JMP + +(END) + @END + 0;JMP +