Is there a way I can compare and jump in one instruction:
C code:
1. while(i<10)
2. {i++}
Assembly code: (eax=0)(ecx=10)
.while:cmp eax, ecxjge .endofwhileadd eax, 1jmp .while.endofwhile:
Is there a way i can do line 2 and 3 in one instruction?
Yes, you can have the test and branch treated as a single instruction, and the way to do this is to write them as two instructions like you did, to use a modern Intel processor and to follow a few simple rules (the branch instruction must be contained in the same 16-bytes line of code that the test instruction ends, the two instructions must not be separated by any other instruction, …).
The mechanism is called macro-fusion. More detailed information including the precise conditions in which macro-fusion apply is available from Agner Fog’s manual, page 82.