https://github.com/akkartik/mu/blob/master/069allocate.subx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 == data
20
21
22 Heap:
23
24 0/imm32
25
26 0/imm32
27
28
29 Heap-size:
30 0x200000/imm32/2MB
31
32
33
34 == code
35
36
37
38
39
40
41 Entry:
42
43
44
45 68/push Heap/imm32
46 68/push Heap-size/imm32
47
48 e8/call new-segment/disp32
49
50 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
51
52 e8/call run-tests/disp32
53 $array-equal-main:end:
54
55 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/ebx Num-test-failures/disp32
56 b8/copy-to-eax 1/imm32/exit
57 cd/syscall 0x80/imm8
58
59
60
61 allocate:
62
63 55/push-ebp
64 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
65
66 51/push-ecx
67 52/push-edx
68
69 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 1/r32/ecx 8/disp8 .
70
71 8b/copy 0/mod/indirect 1/rm32/ecx . . . 0/r32/eax . .
72
73
74 89/copy 3/mod/direct 2/rm32/edx . . . 0/r32/eax . .
75 03/add 1/mod/*+disp8 5/rm32/ebp . . . 2/r32/edx 0xc/disp8 .
76 3b/compare 1/mod/*+disp8 1/rm32/ecx . . . 2/r32/edx 4/disp8 .
77 73/jump-if-greater-or-equal-signed $allocate:abort/disp8
78 $allocate:commit:
79
80 89/copy 0/mod/indirect 1/rm32/ecx . . . 2/r32/edx . .
81 $allocate:end:
82
83 5a/pop-to-edx
84 59/pop-to-ecx
85
86 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
87 5d/pop-to-ebp
88 c3/return
89
90 $allocate:abort:
91
92
93 68/push "allocate: failed to allocate\n"/imm32
94 68/push 2/imm32/stderr
95
96 e8/call _write/disp32
97
98 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
99
100 bb/copy-to-ebx 1/imm32
101 b8/copy-to-eax 1/imm32/exit
102 cd/syscall 0x80/imm8
103
104
105 test-allocate-success:
106
107 55/push-ebp
108 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
109
110 68/push 0xf/imm32/limit
111 68/push 0xb/imm32/curr
112 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . .
113
114
115 68/push 3/imm32
116 51/push-ecx
117
118 e8/call allocate/disp32
119
120 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
121
122
123 68/push "F - test-allocate-success: returns current pointer of allocation descriptor"/imm32
124 68/push 0xb/imm32
125 50/push-eax
126
127 e8/call check-ints-equal/disp32
128
129 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
130
131
132 68/push "F - test-allocate-success: updates allocation descriptor"/imm32
133 68/push 0xe/imm32
134 ff 6/subop/push 0/mod/indirect 1/rm32/ecx . . . . . .
135
136 e8/call check-ints-equal/disp32
137
138 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
139
140 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
141 5d/pop-to-ebp
142 c3/return
143
144 _pending-test-allocate-failure:
145
146 55/push-ebp
147 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
148
149 68/push 0xf/imm32/limit
150 68/push 0xb/imm32/curr
151 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . .
152
153
154 68/push 6/imm32
155 51/push-ecx
156
157 e8/call allocate/disp32
158
159 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
160
161
162 68/push "F - test-allocate-failure: returns null"/imm32
163 68/push 0/imm32
164 50/push-eax
165
166 e8/call check-ints-equal/disp32
167
168 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
169
170
171
172 68/push "F - test-allocate-failure: updates allocation descriptor"/imm32
173 68/push 0xb/imm32
174 ff 6/subop/push 0/mod/indirect 1/rm32/ecx . . . . . .
175
176 e8/call check-ints-equal/disp32
177
178 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
179
180 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
181 5d/pop-to-ebp
182 c3/return
183
184
185 allocate-region:
186
187 55/push-ebp
188 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
189
190 51/push-ecx
191
192
193 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 .
194 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
195
196 e8/call allocate/disp32
197
198 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
199
200 3d/compare-eax-and 0/imm32
201 74/jump-if-equal $allocate-region:abort/disp8
202
203
204 89/copy 3/mod/direct 1/rm32/ecx . . . 0/r32/eax . .
205 81 0/subop/add 3/mod/direct 1/rm32/ecx . . . . . 8/imm32
206 89/copy 0/mod/indirect 0/rm32/eax . . . 1/r32/ecx . .
207
208 89/copy 3/mod/direct 1/rm32/ecx . . . 0/r32/eax . .
209 03/add 1/mod/*+disp8 5/rm32/ebp . . . 1/r32/ecx 0xc/disp8 .
210 89/copy 1/mod/*+disp8 0/rm32/eax . . . 1/r32/ecx 4/disp8 .
211
212 59/pop-to-ecx
213
214 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
215 5d/pop-to-ebp
216 c3/return
217
218
219
220
221
222
223
224 $allocate-region:abort:
225
226
227 68/push "allocate-region: failed to allocate\n"/imm32
228 68/push 2/imm32/stderr
229
230 e8/call _write/disp32
231
232 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
233
234 bb/copy-to-ebx 1/imm32
235 b8/copy-to-eax 1/imm32/exit
236 cd/syscall 0x80/imm8
237
238
239