/* asm_arg.s * * author marco corvi * date june 2003 * licence GPL (see www.gnu.org for details) * * Description. * assembly routine that shows how to handle the args array in C * */ .data .section .rodata .Lout: .string "ARGC %d \n" .Larg: .string "ARG %d: %s\n" .text .align 4 .globl main .type main,@function main: pushl %ebp /* push Frame Pointer on the stack */ movl %esp, %ebp /* save Stack Pointer in Frame Pointer */ pushl %edx pushl %ecx pushl %ebx pushl %eax movl 8(%ebp), %ecx /* move the parameter in the register EAX */ pushl %ecx pushl $.Lout /* push the (address of the) format string */ call printf addl $4, %esp popl %ecx /* ECX now contains argc */ movl 12(%ebp), %ebx /* EBX now contains &argv */ xorl %edx, %edx /* clear EDX */ argloop: push %ecx /* Save ECX */ pushl (%ebx) /* push third arg: argv address */ pushl %edx /* push second arg: index */ pushl $.Larg /* push first arg: format */ call printf addl $4, %esp /* discard first arg */ popl %edx /* retrieve second arg: index */ incl %edx addl $4, %esp /* discar third arg */ popl %ecx /* Restore ECX */ addl $4, %ebx /* move argv pointer to next string */ loop argloop popl %eax popl %ebx popl %ecx movl %ebp, %esp popl %ebp ret Lfmain: .size main,Lfmain-main