optimizing example
/*
* #include <stdio.h>
*
* int
* main (void)
* {
* int i;
* for (i = 0; i < 10; i++)
* printf ("%d ", i);
* return 0;
* }
*/
.file "ex.c"
.section .rodata
.LC0:
.string "%d "
.text
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
andl $-16, %esp
subl $32, %esp
movl $0, 28(%esp)
jmp .L2
.L3:
movl $.LC0, %eax
movl 28(%esp), %edx
movl %edx, 4(%esp)
movl %eax, (%esp)
call printf
addl $1, 28(%esp)
.L2:
cmpl $9, 28(%esp)
jle .L3
movl $0, %eax
leave
ret
.size main, .-main
.ident "GCC: (GNU) 4.5.1"
.section .note.GNU-stack,"",@progbits
.file "ex.c"The first file has as comment the c program that generates it.
.section .rodata
.LC0:
.string "%d "
.text
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
andl $-16, %esp
subl $32, %esp
movl $0, 4(%esp)
jmp .L2
.L3:
movl $.LC0, %eax
movl %eax, (%esp)
call printf
incl 4(%esp)
.L2:
cmpl $9, 4(%esp)
jle .L3
movl $0, %eax
leave
ret
.size main, .-main
.ident "GCC: (GNU) 4.5.1"
.section .note.GNU-stack,"",@progbits
The second one is the same, but with some modifications that I made..
reducing the number of instructions and replacing an add
with an inc intruction. Assembly world is really fun!!
Oh yes.. I extend SH to get a poorly gas syntaxhighlighter (:
I guess this is my first real work with free community!!
here is the post announcement: http://alexgorbatchev.com/forums/viewtopic.php?f=2&t=77 and
here is the project page http://github.com/gkos/gas-brush
I'm felling really happy with this!! Maybe tomorrow I speak about downseq project (:
Cheers!