-
-
Save kgabis/1209854 to your computer and use it in GitHub Desktop.
Hello world x5 in C, assembly (-O0) and optimized assembly (-O3) from gcc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void hello(int i); | |
int main(int argc, char * argv[]) | |
{ | |
hello(5); | |
} | |
void hello(int i) | |
{ | |
int j; | |
for(j=0;j<i;j++) | |
printf("Hello, world!\n"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.file "hw2.c" | |
.def ___main; .scl 2; .type 32; .endef | |
.text | |
.globl _main | |
.def _main; .scl 2; .type 32; .endef | |
_main: | |
pushl %ebp | |
movl %esp, %ebp | |
andl $-16, %esp | |
subl $16, %esp | |
call ___main | |
movl $5, (%esp) | |
call _hello | |
leave | |
ret | |
.section .rdata,"dr" | |
LC0: | |
.ascii "Hello, world!\0" | |
.text | |
.globl _hello | |
.def _hello; .scl 2; .type 32; .endef | |
_hello: | |
pushl %ebp | |
movl %esp, %ebp | |
subl $40, %esp | |
movl $0, -12(%ebp) | |
jmp L3 | |
L4: | |
movl $LC0, (%esp) | |
call _puts | |
incl -12(%ebp) | |
L3: | |
movl -12(%ebp), %eax | |
cmpl 8(%ebp), %eax | |
jl L4 | |
leave | |
ret | |
.def _puts; .scl 2; .type 32; .endef |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.file "hw2.c" | |
.def ___main; .scl 2; .type 32; .endef | |
.section .rdata,"dr" | |
LC0: | |
.ascii "Hello, world!\0" | |
.text | |
.p2align 2,,3 | |
.globl _main | |
.def _main; .scl 2; .type 32; .endef | |
_main: | |
pushl %ebp | |
movl %esp, %ebp | |
andl $-16, %esp | |
subl $16, %esp | |
call ___main | |
movl $LC0, (%esp) | |
call _puts | |
movl $LC0, (%esp) | |
call _puts | |
movl $LC0, (%esp) | |
call _puts | |
movl $LC0, (%esp) | |
call _puts | |
movl $LC0, (%esp) | |
call _puts | |
leave | |
ret | |
.p2align 2,,3 | |
.globl _hello | |
.def _hello; .scl 2; .type 32; .endef | |
_hello: | |
pushl %ebp | |
movl %esp, %ebp | |
pushl %esi | |
pushl %ebx | |
subl $16, %esp | |
movl 8(%ebp), %esi | |
testl %esi, %esi | |
jle L2 | |
xorl %ebx, %ebx | |
.p2align 2,,3 | |
L4: | |
movl $LC0, (%esp) | |
call _puts | |
incl %ebx | |
cmpl %ebx, %esi | |
jg L4 | |
L2: | |
addl $16, %esp | |
popl %ebx | |
popl %esi | |
leave | |
ret | |
.def _puts; .scl 2; .type 32; .endef |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment