https://github.com/akkartik/mu/blob/master/apps/factorial.subx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 == code
17
18
19
20
21 factorial:
22
23 55/push-ebp
24 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
25 53/push-ebx
26
27 b8/copy-to-eax 1/imm32
28 81 7/subop/compare 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 1/imm32
29 7e/jump-if-<= $factorial:end/disp8
30
31 8b/copy 1/mod/*+disp8 5/rm32/ebp . . 3/r32/ebx 8/disp8 .
32 4b/decrement-ebx
33
34
35 53/push-ebx
36
37 e8/call factorial/disp32
38
39 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
40
41 f7 4/subop/multiply 1/mod/*+disp8 5/rm32/ebp . . 8/disp8 .
42
43 $factorial:end:
44
45 5b/pop-to-ebx
46 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
47 5d/pop-to-ebp
48 c3/return
49
50 test-factorial:
51
52
53 68/push 5/imm32
54
55 e8/call factorial/disp32
56
57 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
58
59
60 68/push "F - test-factorial"/imm32
61 68/push 0x78/imm32/expected-120
62 50/push-eax
63
64 e8/call check-ints-equal/disp32
65
66 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
67
68 c3/return
69
70 Entry:
71
72 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
73
74
75
76
77 68/push Heap/imm32
78 ff 6/subop/push 0/mod/indirect 5/rm32/.disp32 . . . Heap-size/disp32
79
80 e8/call new-segment/disp32
81
82 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
83
84
85
86 81 7/subop/compare 1/mod/*+disp8 5/rm32/ebp . . . . 0/disp8 1/imm32
87 7e/jump-if-<= $run-main/disp8
88
89
90
91 68/push "test"/imm32
92 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
93
94 e8/call kernel-string-equal?/disp32
95
96 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
97
98 3d/compare-eax-and 0/imm32/false
99 74/jump-if-= $run-main/disp8
100
101 e8/call run-tests/disp32
102
103 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/ebx Num-test-failures/disp32
104 eb/jump $main:end/disp8
105 $run-main:
106
107
108
109 68/push 5/imm32
110
111 e8/call factorial/disp32
112
113 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
114
115 81 5/subop/subtract 3/mod/direct 4/rm32/esp . . . . . 0xa/imm32
116 68/push 0xa/imm32/decimal-digits-in-32bit-number
117 68/push 0/imm32/read
118 68/push 0/imm32/write
119 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . .
120
121
122 50/push-eax
123 51/push-ecx
124
125 e8/call write-int32-decimal/disp32
126
127 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
128
129
130 51/push-ecx
131 68/push 2/imm32/stderr
132
133 e8/call write-stream/disp32
134
135 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
136
137
138 68/push Newline/imm32
139 68/push 2/imm32/stderr
140
141 e8/call write/disp32
142
143 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
144
145 89/copy 3/mod/direct 3/rm32/ebx . . . 0/r32/eax . .
146 $main:end:
147 e8/call syscall_exit/disp32
148
149