Terminating Condition in Rectangle.asm

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Terminating Condition in Rectangle.asm

EstudianteCurioso

In the lecture about Rectangle.asm, the loop is implemented as such:


@0
D=M
@n
M=D

@i
M=0

(LOOP)
@i
D=M
@n
D=D-M
@END
D;JGT

Let's assume n (user input in R0) is 10, then when the terminating condition is met, which is i-n=i-10>0, or i>10, we have already looped through i from 0..10; in other words, before terminating the loop, we have eleven is:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

In such a case, we draw 11 lines rather than 10 lines.

My thought is that here it should be

@END
D;JEQ

just like the previous example before Rectangle.asm.
Please kindly advise if I missed or misunderstood anything. Thanks!