summaryrefslogtreecommitdiff
path: root/base/Factorial.opt.vaporm
blob: fb5f8e6d72fce5b6949e313be7edb02f8adbaf83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const empty_Fac

func Main [in 0, out 0, local 0]
  $a0 = :empty_Fac
  $a1 = 10
  call :Fac.ComputeFac
  $t0 = $v0
  PrintIntS($t0)
  ret

func Fac.ComputeFac [in 0, out 0, local 1]
  local[0] = $s0
  $t0 = $a0
  $s0 = $a1
  $t1 = LtS($s0 1)
  if0 $t1 goto :if1_else
  $t1 = 1
  goto :if1_end
if1_else:
  $t2 = Sub($s0 1)
  $a0 = $t0
  $a1 = $t2
  call :Fac.ComputeFac
  $t2 = $v0
  $t1 = MulS($s0 $t2)
if1_end:
  $v0 = $t1
  $s0 = local[0]
  ret