; External functions
extern exit, printcp, printi64

; entry point
global _start:

; Factorial of 
mov rdi, fo
mov esi, @fo
call printcp

push 20

mov rdi, [rsp]
call printi64

; is equal to
mov rdi, ise
mov esi, @ise
call printcp

mov rdi, [rsp]
call factorial
mov rdi, rax
call printi64

; exit
call exit

; rdi - number
factorial:
cmp rdi, 1
je _eq1
mov rax, rdi
mov rcx, rdi
_fact:
dec rcx
cmp rcx, 0
je _eq
mov rbx, rcx
imul rbx
jmp _fact
_eq:
ret

_eq1:
mov rax, 1
ret

;section .data
fo db "Factorial of " ;13
ise db " is equal to " ;13
