about summary refs log tree commit diff stats
path: root/archive/3.transect/factorial.k2
blob: 792697735c2b34a26f2566f47af20d9c1baff3f8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# compute the factorial of 5, and return the result in the exit code

fn factorial n : int -> result/EAX : int [
  result/EAX <- copy 1
  {
    compare n, 1
    break-if <=
    var tmp/EBX : int
    tmp/EBX <- copy n
    tmp/EBX <- subtract 1
    var tmp2/EAX : int
    tmp2/EAX <- call factorial, tmp/EBX
    result/EAX <- multiply tmp2/EAX, n
  }
  return result/EAX
]