program RecurseTest {
section module {
}
section data {
int rax = 0
int rbx = 0
int rcx = 0
int rdx = 0
ptr arg0 = null
string str_0 = "Count: "
string str_1 = "Factorial("
string str_2 = ") = "
string fmt_int = "%lld "
string fmt_str = "%s "
string newline = "\n"
int i = 0
ptr Countdown_msg = null
int Countdown_n = 0
int Factorial_n = 0
int __funcret_Factorial = 0
}
section code {
start:
mov arg0, str_0
mov rbx, 5
call PROC_Countdown
print newline
mov i, 1
FOR_0:
cmp i, 10
jg ENDFOR_1
print fmt_str, str_1
print fmt_int, i
print fmt_str, str_2
mov rbx, i
call FUNC_Factorial
mov rbx, rax
print fmt_int, rbx
print newline
FOR_CONTINUE_2:
add i, 1
jmp FOR_0
ENDFOR_1:
done
function PROC_Countdown:
mov Countdown_msg, arg0
mov Countdown_n, rbx
cmp Countdown_n, 0
jle ELSE_3
print fmt_str, Countdown_msg
print fmt_int, Countdown_n
print newline
mov rcx, Countdown_n
sub rcx, 1
push rbx
mov arg0, Countdown_msg
mov rbx, rcx
push Countdown_msg
push Countdown_n
call PROC_Countdown
pop Countdown_n
pop Countdown_msg
pop rbx
ELSE_3:
PROC_END_Countdown:
ret
function FUNC_Factorial:
mov Factorial_n, rbx
cmp Factorial_n, 1
jg ELSE_7
mov __funcret_Factorial, 1
jmp ENDIF_8
ELSE_7:
mov rcx, Factorial_n
sub rcx, 1
push rbx
mov rbx, rcx
push Factorial_n
call FUNC_Factorial
pop Factorial_n
pop rbx
mov rdx, rax
mov __funcret_Factorial, Factorial_n
mul __funcret_Factorial, rdx
ENDIF_8:
FUNC_END_Factorial:
mov rax, __funcret_Factorial
ret
}
}