[04/mult] Multiply is possible

This commit is contained in:
Nemo 2020-05-27 19:44:30 +05:30
parent 56eb3699a4
commit 37c0f41a4a
4 changed files with 61 additions and 2 deletions

View File

@ -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 |

View File

@ -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;

View File

@ -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.
@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

View File

@ -0,0 +1,18 @@
0000000000000010
1110101010001000
0000000000000000
1111110000010000
0000000000010000
1110001100000010
0000000000000010
1111110000010000
0000000000000001
1111000010010000
0000000000000010
1110001100001000
0000000000000000
1111110010001000
0000000000000010
1110101010000111
0000000000010000
1110101010000111