all repos — nand2tetris @ cd6d60e361f05422bdada321e09e6b1d48e11d16

my nand2tetris progress

Re-do Mult.asm
x1phosura x1phosura@x1phosura.zone
Sat, 11 Dec 2021 17:44:03 -0800
commit

cd6d60e361f05422bdada321e09e6b1d48e11d16

parent

eba8ddfc31c4a7ad1a1cfdd0b3e9663b5e3f0312

1 files changed, 43 insertions(+), 1 deletions(-)

jump to
M projects/04/mult/Mult.asmprojects/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 +