A recursive function calls itself (directly or indirectly). E.g.
def fact(n):
if n == 1:
return 1
else:
return n * fact(n-1)
A non-recursive function does not call itself. E.g.
def fact(n):
factn = 1
for i in range(1, n+1):
factn *= i
return factn
A nonrecursive function call in python like
f(a, b)
gets translated into
li a <avalue>
li b <bvalue>
li cont afterCall
j f
afterCallL:
A recursive function call in python like
<prest>
recurse(n)
<postst>
gets translated into
<prest>
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; statements to save working registers go here
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
li n <nvalue>
li cont afterCall
j recurse
afterCallL:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; statements to retrieve working registers go here
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
<postst>
if using caller-saved method.
Exercise. Translate the function call
<prest>
recurse(n)
<postst>
into assembly code assuming the callee-saved method is used.