"Copyright Notice: respect for the original, reproduced please retain the source: blog.csdn.net/shallnet, the article only for learning Exchange, do not use for commercial purposes"
loops are also a way to change the order in which instructions are executed, repeating the execution until the condition is met. We can use conditional jump directives to create loops, but in fact there is a simpler series of loop instructions in assembly language. The loop instruction uses the ECX register as the counter, which automatically decrements its value as the execution of the loop instruction, and does not affect the flag bit of the EFlags register, when the ECX register value arrives 0 o'clock, the 0 flag is not set. The loop instruction is as follows: Loop (loop until the ECX register is 0), Loope/loopz ( Loop until the ECX register is 0 or no ZF flag set ), LOOPNE/LOOPNZ ( Loop until the ECX register is 0 or the ZF flag is set) ). The Loope/loopz and LOOPNE/LOOPNZ directives provide additional functionality to monitor the 0 flag. The instruction is used in the following format:Loop AddrAddr is the label name of the program code location to jump to. You must set the number of times the iteration is executed in the ECX register before the loop begins. as follows:
<span style= "Font-family:microsoft Yahei;" ># loop.s.section text.globl _start_start: movl $,%ecx MOVL $,%eaxhere_loop: addl%ecx,%eax Loop Here_loop movl%eax,%EBX movl $,%eax int $0x80</span>
the program simply loops the sum of 0 to 10 and the program returns the accumulated value. Make, the results of the operation are as follows:
$ make as-o loop.o loop.s--gstabsld-o loop loop.o$./loop $ echo $?55$
Linux Platform x86 compilation (ix): cyclic instruction