Comparison and jump instruction as a single instruction

Is there a way to compare and go into one command:

C code:
1. while(i<10)
2. {i++}

Build Code: (eax=0)(ecx=10)

  • .while:
  • cmp eax, ecx
  • jge .endofwhile
  • add eax, 1
  • jmp .while
  • .endofwhile:

Is there a way that I can do lines 2 and 3 in one instruction?

+1
source share
2 answers

Yes, you can have a test and a branch considered as one instruction, and the way to do this is to write them as two instructions, like you, use a modern Intel processor and follow a few simple rules (the branch instruction must be in the same 16-byte line of code that ends with a test instruction, the two instructions should not be separated by any other instruction, ...).

The mechanism is called macro-fusion . For more information, including the exact conditions under which macro summation is applied, see the Agner Fog manual, page 82.

+6
source

Is there a way that I can do lines 2 and 3 in one instruction?

If you are allowed to change the C code to read the opposite:

 1. i = 10; 2. while(--i >= 0); 

Then you can use (one) LOOP opcode .

LOOP is an old instruction, so it can be deprecated on newer (Pentium ++) processors: where "deprecated" I mean "is still supported, but slower than using more primitive opcodes like those given in Pascal’s answer. "

+6
source

Source: https://habr.com/ru/post/1499661/


All Articles