|
When testing Mult.asm, I get a comparison error on line 5 because R2 always remains 0. Not sure what I am doing wrong, but I am assuming it is a syntax problem. The idea is to loop for the range of R1, add R1 to the current value of R2, update the counter until the counter is > R0 and then when the counter is > R0 terminate the program by entering the infinite loop (like in the book and other examples).
// Pseudocode
// for i in R0
// if (counter > R0)
// Terminate program
// R2 = R2 + R1
// counter = counter + 1
// goto beginning of for loop
// Initalise counter, R0, R1, R2 to 0
@counter
M=0
@R0
M=0
@R1
M=0
@R2
M=0
(LOOP)
// if (counter > R0) goto TERMINATE
@counter
D=M
@R0
D=D-M // Difference between counter and R0; counter - R0
@TERMINATE
D;JGT
// R2 = R2 + R1
@R2
D=M
@R1
D=D+M
@R2
M=D
// counter++
@counter
M=M+1
// goto LOOP
@LOOP
D;JLT
(TERMINATE)
@TERMINATE
0;JMP
|