; factorial_long.asm test with test_factorial_long.c main program ; // factorial_long.c the simplest example of a recursive function ; // a recursive function is a function that calls itself ; long int factorial_long(long int n) // n! is n factorial = 1*2*...*(n-1)*n ; { ; if( n <= 1 ) return 1; // must have a way to stop recursion ; return n * factorial_long(n-1); // factorial calls factorial with n-1 ; } // n * (n-1) * (n-2) * ... * (1) ; // note: "C" makes 1 be 1l long global factorial_long section .text factorial_long: ; extreamly efficient version mov rax, 1 ; default return cmp rdi, 1 ; compare n to 1 jle done ; normal case n * factorial_long(n-1) push rdi ; save n for multiply sub rdi, 1 ; n-1 call factorial_long ; rax has factorial_long(n-1) pop rdi imul rax,rdi ; ?? ; n*factorial_long(n-1) in rax done: ret ; return with result in rax ; end factorial_long.asm