Last active
March 17, 2016 09:17
-
-
Save fujidig/d9992bd0fe940ea8c1eb 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
BITS 32 | |
segment .text | |
global _factorial | |
_factorial: | |
push ebp | |
mov ebp, esp | |
push ebx | |
mov ebx, [ebp+8] | |
cmp ebx, 0 | |
jnz .l1 | |
mov eax, 1 | |
pop ebx | |
pop ebp | |
ret | |
.l1: | |
mov eax, ebx | |
dec eax | |
push eax | |
call _factorial | |
add esp, 4 | |
imul eax, ebx | |
pop ebx | |
pop ebp | |
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
testfact.exe: testfact.obj factorial.obj | |
link testfact.obj factorial.obj | |
testfact.obj: testfact.c | |
cl /c testfact.c | |
factorial.obj: factorial.asm | |
nasm -f win32 factorial.asm | |
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> | |
int factorial(int n); | |
int main() | |
{ | |
printf("%d\n", factorial(10)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment