mov r1,0 // sometimes, xor r1,r1 needs less program space and/or time mov r2,N loop: // do something with r1 inc r1 // may or may not set flags, depending on the implementation cmp r1,r2 // often imlemented as sub r1,r2 but without actually writing the result back to the register, just setting flags jne loop // if implemented as sub r1,r2, jne (jump if not rqual) is equal to jnz (jump if not zero) #### xor r1,r1 loop: // do something with r1 inc r1 cmp r1,N jne loop #### mov r1,N loop: // do something with r1 dec r1 // must set/clear zero flag depending on value of r1 jnz loop