https://github.com/akkartik/mu/blob/master/apps/factorial2.subx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 == code
22
23 factorial:
24
25 55/push-ebp
26 89/<- %ebp 4/r32/esp
27 53/push-ebx
28
29 b8/copy-to-eax 1/imm32
30 81 7/subop/compare *(ebp+8) 1/imm32
31 7e/jump-if-<= $factorial:end/disp8
32
33 8b/-> *(ebp+8) 3/r32/ebx
34 4b/decrement-ebx
35
36
37 53/push-ebx
38
39 e8/call factorial/disp32
40
41 81 0/subop/add %esp 4/imm32
42
43 f7 4/subop/multiply-into-eax *(ebp+8)
44
45 $factorial:end:
46
47 5b/pop-to-ebx
48 89/<- %esp 5/r32/ebp
49 5d/pop-to-ebp
50 c3/return
51
52 test-factorial:
53
54
55 68/push 5/imm32
56
57 e8/call factorial/disp32
58
59 81 0/subop/add %esp 4/imm32
60
61
62 68/push "F - test-factorial"/imm32
63 68/push 0x78/imm32/expected-120
64 50/push-eax
65
66 e8/call check-ints-equal/disp32
67
68 81 0/subop/add %esp 0xc/imm32
69
70 c3/return
71
72 Entry:
73
74 89/<- %ebp 4/r32/esp
75
76
77
78
79 68/push Heap/imm32
80 ff 6/subop/push *Heap-size
81
82 e8/call new-segment/disp32
83
84 81 0/subop/add %esp 8/imm32
85
86
87
88 81 7/subop/compare *ebp 1/imm32
89 7e/jump-if-<= $run-main/disp8
90
91
92
93 68/push "test"/imm32
94 ff 6/subop/push *(ebp+8)
95
96 e8/call kernel-string-equal?/disp32
97
98 81 0/subop/add %esp 8/imm32
99
100 3d/compare-eax-and 0/imm32/false
101 74/jump-if-= $run-main/disp8
102
103 e8/call run-tests/disp32
104
105 8b/-> *Num-test-failures 3/r32/ebx
106 eb/jump $main:end/disp8
107 $run-main:
108
109
110
111 68/push 5/imm32
112
113 e8/call factorial/disp32
114
115 81 0/subop/add %esp 4/imm32
116
117 89/<- %ebx 0/r32/eax
118 $main:end:
119 e8/call syscall_exit/disp32