Skip to content

Commit

Permalink
Chapter 4 multiplication passing test.
Browse files Browse the repository at this point in the history
  • Loading branch information
floehopper committed Jan 13, 2015
1 parent dbe0792 commit 509ba5f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
24 changes: 23 additions & 1 deletion projects/04/mult/Mult.asm
Expand Up @@ -6,4 +6,26 @@
// 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.
// set R2 to 0
@R2
M=0
(LOOP)
// jump to "end" if R0 is zero
@R0
D=M
@END
D;JEQ
// add R1 to R2
@R1
D=M
@R2
M=D+M
// decrement R0
@R0
M=M-1
// jump to "loop"
@LOOP
0;JMP
(END)
@END
0;JMP
16 changes: 16 additions & 0 deletions projects/04/mult/Mult.hack
@@ -0,0 +1,16 @@
0000000000000010
1110101010001000
0000000000000000
1111110000010000
0000000000001110
1110001100000010
0000000000000001
1111110000010000
0000000000000010
1111000010001000
0000000000000000
1111110010001000
0000000000000010
1110101010000111
0000000000001110
1110101010000111
7 changes: 7 additions & 0 deletions 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 |

0 comments on commit 509ba5f

Please sign in to comment.