https://github.com/akkartik/mu/blob/master/apps/factorial.mu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 fn factorial n: int -> _/eax: int {
20 compare n, 1
21
22 {
23 break-if->
24 return 1
25 }
26
27 var tmp/ecx: int <- copy n
28 tmp <- decrement
29 var result/eax: int <- factorial tmp
30 result <- multiply n
31 return result
32 }
33
34 fn test-factorial {
35 var result/eax: int <- factorial 5
36 check-ints-equal result, 0x78, "F - test-factorial"
37 }
38
39 fn main args-on-stack: (addr array (addr array byte)) -> _/ebx: int {
40 var args/eax: (addr array addr array byte) <- copy args-on-stack
41
42 var len/ecx: int <- length args
43
44 compare len, 1
45 {
46 break-if->
47 var exit-status/eax: int <- factorial 5
48 return exit-status
49 }
50
51 var tmp2/ecx: (addr addr array byte) <- index args, 1
52 var tmp3/eax: boolean <- string-equal? *tmp2, "test"
53 compare tmp3, 0
54 {
55 break-if-=
56 run-tests
57
58 }
59 return 0
60 }