CSC448: Code Generation: Simplified Example [64/133] |
GCC's output can be simplified:
.global _main .text .align 4 _main: pushl %ebp movl %esp, %ebp subl $8, %esp movl $3, -4(%ebp) jmp lab2 lab1: pushl -4(%ebp) pushl $somenameforthestring call _printf addl $8, %esp leal -4(%ebp), %eax decl (%eax) lab2: cmpl $0, -4(%ebp) jns lab1 movl $0, %eax leave ret .section .rodata somenameforthestring: .string "%d\n"
$ gcc -o loop simplified-loop.s $ ./loop 3 2 1 0
For Linux (note underscore changes):
.global main .text .align 4 main: pushl %ebp movl %esp, %ebp subl $8, %esp movl $3, -4(%ebp) jmp lab2 lab1: pushl -4(%ebp) pushl $somenameforthestring call printf addl $8, %esp leal -4(%ebp), %eax decl (%eax) lab2: cmpl $0, -4(%ebp) jns lab1 movl $0, %eax leave ret .section .rodata somenameforthestring: .string "%d\n"