nunos
nunos

Reputation: 21389

LOOP, LOOPE, LOOPNE?

What's the difference between the assembly instructions LOOP, LOOPE and LOOPNE?

Upvotes: 10

Views: 32446

Answers (4)

DednDave
DednDave

Reputation: 19

The LOOP instructions, as well as JCXZ/JECXZ are a bit slow; however, they still have their place in modern code.

High speed is not always a concern in loops. For example, if we are executing a loop only once during program init and the iteration count is small, the time required will not be noticed.

Another example is a loop where Windows API functions are called; the time spent in the API call probably makes the LOOP execution time trivial. Again, this applies when the iteration count is small.

Consider these instructions as "another tool in your toolbox"; use the right tool for the job ;)

Upvotes: 1

starblue
starblue

Reputation: 56772

Have you tried looking it up in an instruction set reference, for example in this one by Intel?

Upvotes: 0

Matthew Jones
Matthew Jones

Reputation: 26190

Time for a Google Books Reference

EDIT: Synopsis from link: LOOPE and LOOPNE are essentially LOOP instructions with one additional check. LOOPE loops "while zero flag," meaning it will loop as long as zero flag ZF is one and the increment is not reached, and LOOPNE loops "while not zero flag," meaning it continues the loop as long as ZF is zero and the increment is not reached. Keep in mind that neither of these instructions inherently affect the status of ZF.

Upvotes: 5

sharptooth
sharptooth

Reputation: 170499

LOOP decrements ecx and checks if ecx is not zero, if that condition is met it jumps at specified label, otherwise falls through.

LOOPE decrements ecx and checks that ecx is not zero and ZF is set - if these conditions are met, it jumps at label, otherwise falls through.

LOOPNE is same as LOOPE except that it requires ZF to be not set (i.e be zero) to do the jump.

Upvotes: 21

Related Questions