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