Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. __declspec(naked) void asm_factorial(int& n) {
  5.     __asm {
  6.         mov eax, [esp + 4]
  7.         mov ebx, eax
  8.         push ebx
  9.         mov ebx, [eax]
  10.     StartLoop:
  11.         dec ebx
  12.         imul eax, ebx
  13.         cmp ebx, 1
  14.         jg StartLoop
  15.         pop ebx
  16.         push eax
  17.         mov eax, [ebx]
  18.         mov ebx, eax
  19.         pop eax
  20.         mov [eax], ebx
  21.         ret
  22.     }
  23. }
  24.  
  25. int main(int argc, char* argv[]) {
  26.     int test = 4;
  27.     asm_factorial(test);
  28.     printf("factorial result: %i\n", test);
  29.  
  30.     system("PAUSE");
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement