0

as we know, the loop X instruction is going over X until ECX = 0.

My question - What the loop instruction do first: decrement the ECX, or check if ECX == 0.

Meaning, what of the below is corect

first

   ECX = ECX - 1;
   if ECX > 0
       go to X

second

   if ECX > 0 {
       ECX = ECX - 1;
       fo to x; }

Thanks.

Adam Sh
  • 8,137
  • 22
  • 60
  • 75

1 Answers1

4

The first. From Intel's manual 2A:

Each time the LOOP instruction is executed, the count register is decremented, then checked for 0. If the count is 0, the loop is terminated and program execution continues with the instruction following the LOOP instruction. If the count is not zero, a near jump is performed to the destination (target) operand, which is presumably the instruction at the beginning of the loop.

harold
  • 61,398
  • 6
  • 86
  • 164