diff --git a/projects/04/mult/Mult.out b/projects/04/mult/Mult.out new file mode 100644 index 0000000..e31b5df --- /dev/null +++ b/projects/04/mult/Mult.out @@ -0,0 +1,7 @@ +| RAM[0] | RAM[1] | RAM[2] | +| 0 | 0 | 0 | +| 1 | 0 | 0 | +| 0 | 2 | 0 | +| 3 | 1 | 3 | +| 2 | 4 | 8 | +| 6 | 7 | 42 | diff --git a/projects/04/mult/Mult.tst b/projects/04/mult/Mult.tst index 65a99fd..313451c 100644 --- a/projects/04/mult/Mult.tst +++ b/projects/04/mult/Mult.tst @@ -3,7 +3,7 @@ // by Nisan and Schocken, MIT Press. // File name: projects/04/mult/Mult.tst -load Mult.hack, +load mult.hack, output-file Mult.out, compare-to Mult.cmp, output-list RAM[0]%D2.6.2 RAM[1]%D2.6.2 RAM[2]%D2.6.2; diff --git a/projects/04/mult/mult.asm b/projects/04/mult/mult.asm index 8781f7a..a8b660c 100644 --- a/projects/04/mult/mult.asm +++ b/projects/04/mult/mult.asm @@ -6,4 +6,38 @@ // Multiplies R0 and R1 and stores the result in R2. // (R0, R1, R2 refer to RAM[0], RAM[1], and RAM[2], respectively.) -// Put your code here. \ No newline at end of file +@R2 +M=0 + +// Put your code here. +(LOOP) + +@R0 +D=M +// Jump to end if R0 = 0 +@END +D;JEQ + +@R2 +D=M + +@R1 +// Increase D by R1 +D=D+M + +// Save final value back to result + +@R2 +M=D + +// R0=R0-1 +@R0 +M=M-1 + +// Otherwise, go to loop +@LOOP +0;JMP + +(END) +@END +0;JMP diff --git a/projects/04/mult/mult.hack b/projects/04/mult/mult.hack new file mode 100644 index 0000000..80cdc35 --- /dev/null +++ b/projects/04/mult/mult.hack @@ -0,0 +1,18 @@ +0000000000000010 +1110101010001000 +0000000000000000 +1111110000010000 +0000000000010000 +1110001100000010 +0000000000000010 +1111110000010000 +0000000000000001 +1111000010010000 +0000000000000010 +1110001100001000 +0000000000000000 +1111110010001000 +0000000000000010 +1110101010000111 +0000000000010000 +1110101010000111