Linux Platform x86 compilation (ix): cyclic instruction

Source: Internet
Author: User

"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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.