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
28 51/push-ecx
29
30 b8/copy-to-eax 1/imm32
31 81 7/subop/compare *(ebp+8) 1/imm32
32 7e/jump-if-<= $factorial:end/disp8
33
34 8b/-> *(ebp+8) 1/r32/ecx
35 49/decrement-ecx
36
37
38 51/push-ecx
39
40 e8/call factorial/disp32
41
42 81 0/subop/add %esp 4/imm32
43
44 f7 4/subop/multiply-into-eax *(ebp+8)
45
46 $factorial:end:
47
48 59/pop-to-ecx
49
50 89/<- %esp 5/r32/ebp
51 5d/pop-to-ebp
52 c3/return
53
54 test-factorial:
55
56
57 68/push 5/imm32
58
59 e8/call factorial/disp32
60
61 81 0/subop/add %esp 4/imm32
62
63
64 68/push "F - test-factorial"/imm32
65 68/push 0x78/imm32/expected-120
66 50/push-eax
67
68 e8/call check-ints-equal/disp32
69
70 81 0/subop/add %esp 0xc/imm32
71
72 c3/return
73
74 Entry:
75
76 89/<- %ebp 4/r32/esp
77
78
79
80
81 68/push Heap/imm32
82 ff 6/subop/push *Heap-size
83
84 e8/call new-segment/disp32
85
86 81 0/subop/add %esp 8/imm32
87
88
89 81 7/subop/compare *ebp 1/imm32
90 7f/jump-if-> $main:run-tests/disp8
91
92 68/push 5/imm32
93
94 e8/call factorial/disp32
95
96 81 0/subop/add %esp 4/imm32
97
98 89/<- %ebx 0/r32/eax
99 eb/jump $main:end/disp8
100 $main:run-tests:
101
102
103
104
105 68/push "test"/imm32
106 ff 6/subop/push *(ebp+8)
107
108 e8/call kernel-string-equal?/disp32
109
110 81 0/subop/add %esp 8/imm32
111
112 3d/compare-eax-and 0/imm32/false
113 74/jump-if-= $main:do-nothing/disp8
114
115 e8/call run-tests/disp32
116
117 8b/-> *Num-test-failures 3/r32/ebx
118 eb/jump $main:end/disp8
119 $main:do-nothing:
120 bb/copy-to-ebx 0/imm32
121 $main:end:
122 e8/call syscall_exit/disp32