BSCS

Loop instructions

Loop instructions– do not change flags.

The loop instruction uses the value in the CL register to determine how often it will have to run the same code. Every time the code is executed, the loop decreases the value in CL by one until it is zero and the loop ends. The loop will run the code three times and therefore place 3 in the CL register.

Loop instructions

loop label

In 16-bit mode, loop decrements register CX and compares it
with 0 leaving the flags unchanged. If new CX ≠ 0, jumps to
the label. Otherwise the program execution continues with the
next instruction.
Label is at the first instruction of the loop. It must be short.
In 32-bit mode, loop decrements and tests register ECX.

  • decrement register CX and compare it with 0. If the new
    contents of register CX ≠ 0 a ZF = 1, jump to the label.
  • decrement register CX and compare it with 0. If the new
    contents of register CX ≠ 0 a ZF = 0, jump to the label.

Example

Read characters typed on the keyboard and store them to
variable IOBuffer until ENTER is pressed or MaxNumber
characters are typed.

Leave a Reply

Your email address will not be published. Required fields are marked *