https://github.com/akkartik/mu/blob/master/apps/factorial3.subx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 == code
17
18 Entry:
19
20 89/<- %ebp 4/r32/esp
21
22
23 (new-segment Heap-size Heap)
24
25
26
27 81 7/subop/compare *ebp 1/imm32
28 7e/jump-if-lesser-or-equal $run-main/disp8
29
30 (kernel-string-equal? *(ebp+8) "test")
31
32 3d/compare-eax-and 0/imm32
33 74/jump-if-equal $run-main/disp8
34
35 (run-tests)
36
37 8b/-> *Num-test-failures 3/r32/ebx
38 eb/jump $main:end/disp8
39 $run-main:
40
41 (factorial 5)
42
43 89/<- %ebx 0/r32/eax
44 $main:end:
45 b8/copy-to-eax 1/imm32/exit
46 cd/syscall 0x80/imm8
47
48 factorial:
49
50 55/push-ebp
51 89/<- %ebp 4/r32/esp
52
53 53/push-ebx
54
55 b8/copy-to-eax 1/imm32
56 81 7/subop/compare *(ebp+8) 1/imm32
57 7e/jump-if-<= $factorial:end/disp8
58
59 8b/-> *(ebp+8) 3/r32/ebx
60 4b/decrement-ebx
61
62 (factorial %ebx)
63
64 f7 4/subop/multiply-into-eax *(ebp+8)
65
66 $factorial:end:
67
68 5b/pop-to-ebx
69
70 89/<- %esp 5/r32/ebp
71 5d/pop-to-ebp
72 c3/return
73
74 test-factorial:
75 (factorial 5)
76 (check-ints-equal %eax 0x78 "F - test-factorial")
77 c3/return