Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- __declspec(naked) void asm_factorial(int& n) {
- __asm {
- mov eax, [esp + 4]
- mov ebx, eax
- push ebx
- mov ebx, [eax]
- StartLoop:
- dec ebx
- imul eax, ebx
- cmp ebx, 1
- jg StartLoop
- pop ebx
- mov eax, [ebx]
- mov [ebx], eax
- ret
- }
- }
- int main(int argc, char* argv[]) {
- int test = 4;
- asm_factorial(test);
- printf("factorial result: %i\n", test);
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement