Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2018
85
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.         mov eax, [ebx]
  17.         mov [ebx], eax
  18.         ret
  19.     }
  20. }
  21.  
  22. int main(int argc, char* argv[]) {
  23.     int test = 4;
  24.     asm_factorial(test);
  25.     printf("factorial result: %i\n", test);
  26.  
  27.     system("PAUSE");
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement