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