Assembly Language Learning Series print array 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>intMain () {intA[] = {3,0,5,1,4,6,2,9,8,7}; inti;  for(i =0; i<Ten; i++) printf ("%d\n", A[i]); return 0;}
    • Code
. Section. Dataarray:.int 3,0,5,1,4,6,2,9,8,7        Len:.int Ten        format:. Asciz"%d\n". Section. Text.global _start_start:PUSHL%ebp movl%esp,%EBP Subl $ -,%esp #allocate space movl $array,%edx movl%edx, (%ESP) #store &array on the stack Movl Len,%ecx movl%ecx,4(%ESP) #store len on the stackPagerParray Addl $ -,%esp popl%ebp MOVL $0, (%ESP) #deallocate spacePagerExitParray:PUSHL%ebp movl%esp,%EBPPush%EBX MOVL8(%EBP),%edx #get &array movl A(%EBP),%ebx #get len Movl $0,%ecx #计数器i初始化为0CMP%ecx,%ebxJle. Done.Loop:movl (%edx,%ECX,4),%eaxPagerPrintInc%ecx #i每次加1CMP%ecx,%ebxJG. Loop.Done :popl%ebx popl%ebpret        Print:pushl%edx pushl%ecx pushl%eax pushl $formatPagerprintf Addl $8,%esp popl%ecx popl%edxret        
    • Compile

As Parray.s-o parray.o

    • Link

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

    • Perform

./parray

Assembly Language Learning Series print array 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.