Assembly language Learning Series for loop implementation

Source: Internet
Author: User

If the assembly language to achieve the following C language functions, the compilation environment Ubuntu14.04 (32-bit).

#include <stdio.h>intFact_for (intN) {    inti; intresult =1;  for(i =2; I <= N; i++) Result*=i; returnresult;}intMain () {printf ("%d\n", Fact_for (3)); return 0;}
    • Code FOR.S
. Section. DataN:.int 3        format:. Asciz"%d\n". Section. Text.global _start_start:PUSHL%ebp movl%esp,%EBP Subl $8,%esp movl N,%ecx movl%ecx, (%ESP)Pagerfact_for pushl%eax pushl $formatPagerprintf MOVL $0, (%ESP)PagerExitfact_for:PUSHL%ebp movl%esp,%ebp pushl%ebx movl8(%EBP),%edx #get n movl $1,%eax #init result MOVL $2,%ecx #init iCMP%ecx,%edxJL. Done.Loop:        Imul%ecx,%eaxInc%ecxCMP%ecx,%edxJge. Loop.Done :popl%ebx popl%ebpret        
    • Compile

As For.s-o FOR.O

    • Link

Ld-lc-i/lib/ld-linux.so.2 For.o-o for

    • Perform

./for

Assembly language Learning series for loop implementation

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.