开发者

LOOP, LOOPE, LOOPNE?

开发者 https://www.devze.com 2022-12-11 15:23 出处:网络
What\'s the difference between the assembly instructions LOOP, LOOPE and LOOP开发者_Go百科NE?LOOP decrements ecx and checks if ecx is not zero, if that condition is met it jumps at specified label, ot

What's the difference between the assembly instructions LOOP, LOOPE and LOOP开发者_Go百科NE?


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.


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.


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 ;)


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

0

精彩评论

暂无评论...
验证码 换一张
取 消