Couple corrections I think:
- Register 4 should be set to zero before incrementing in instruction 2.
- inst. 4 should compare 0,4 , register 1 is unknown at this pt.
- inst. 3 should jump to 5
- inst. 4 should compare 0,4 , register 1 is unknown at this pt.
- inst. 3 should jump to 5
r4 could be zeroed, but I was lazy and assumed that as long as it's greater than zero it doesn't matter (since it's always compared to zero).
Instruction 4 should be cmp(3,4) to force a jump to 9.
EDIT: Although thinking about it, it doesn't make much difference. It has the same effect as doing cmp(0,4) since you know r4 > 0 and r0 == 0.
Thanks!