Created
January 12, 2013 18:09
-
-
Save Chris--B/4519674 to your computer and use it in GitHub Desktop.
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
int factorial(int n) | |
{ | |
if(n == 0) { | |
return 1; | |
} else { | |
return n * factorial (n - 1); | |
} | |
} |
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
21.file "foo.c" | |
.text | |
.globl _factorial | |
.def _factorial; .scl 2; .type 32; .endef | |
_factorial: | |
pushl %ebp | |
movl %esp, %ebp | |
subl $24, %esp | |
cmpl $0, 8(%ebp) | |
jne L2 | |
movl $1, %eax | |
jmp L3 | |
L2: | |
movl 8(%ebp), %eax | |
decl %eax | |
movl %eax, (%esp) | |
call _factorial | |
imull 8(%ebp), %eax | |
L3: | |
leave | |
ret |
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
21.file "foo.c" | |
.text | |
.p2align 2,,3 | |
.globl _factorial | |
.def _factorial; .scl 2; .type 32; .endef | |
_factorial: | |
pushl %ebp | |
movl %esp, %ebp | |
movl 8(%ebp), %edx | |
testl %edx, %edx | |
je L4 | |
movl $1, %eax | |
.p2align 2,,3 | |
L3: | |
imull %edx, %eax | |
decl %edx | |
jne L3 | |
leave | |
ret | |
L4: | |
movl $1, %eax | |
leave | |
ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment