The question I need answered is, why is there a comparison failure at line 9 but not at line 8? I am new to Hack assembly language and am still learning the basics but am confused as to why the CPU Emulator would pass line 8 but not line 9.
2nd question:
How can I could I fix this to support the multiplication of negative values?
The program multiplies R0 and R1 and stores the result in R2. (R0, R1, R2 refer to RAM[0], RAM[1], and RAM[2], respectively.)
Mult.asm:
0 @2
1 M=0
2 @0
3 D=M
4 @8
5 D;JNE
6 @19
7 0;JMP
8 @2
9 D=M
10 @1
11 D=D+M
12 @2
13 M=D
14 @0
15 D=M-1
16 M=D
17 @8
18 D;JGT
19 @19
20 0;JMP
Mult.cmp:
| RAM[0] | RAM[1] | RAM[2] |
| 0 | 0 | 0 |
| 1 | 0 | 0 |
| 0 | 2 | 0 |
| 3 | 1 | 3 |
| 2 | 4 | 8 |
| 6 | 7 | 42 |
| 6 | -7 | -42 |
| -6 | 7 | -42 |