https://github.com/akkartik/mu/blob/master/subx/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
23 Heap:
24 Start-of-heap/imm32
25 0x0b000000/imm32
26
27 == code
28
29
30
31
32
33
34 allocate:
35
36 55/push-EBP
37 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
38
39 51/push-ECX
40 52/push-EDX
41
42 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 1/r32/ECX 8/disp8 .
43
44 8b/copy 0/mod/indirect 1/rm32/ECX . . . 0/r32/EAX . .
45
46
47 89/copy 3/mod/direct 2/rm32/EDX . . . 0/r32/EAX . .
48 03/add 1/mod/*+disp8 5/rm32/EBP . . . 2/r32/EDX 0xc/disp8 .
49 3b/compare 1/mod/*+disp8 1/rm32/ECX . . . 2/r32/EDX 4/disp8 .
50 7c/jump-if-lesser $allocate:commit/disp8
51
52 b8/copy-to-EAX 0/imm32
53 eb/jump $allocate:end/disp8
54 $allocate:commit:
55
56 89/copy 0/mod/indirect 1/rm32/ECX . . . 2/r32/EDX . .
57 $allocate:end:
58
59 5a/pop-to-EDX
60 59/pop-to-ECX
61
62 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
63 5d/pop-to-EBP
64 c3/return
65
66 test-allocate-success:
67
68 55/push-EBP
69 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
70
71 68/push 0xf/imm32/limit
72 68/push 0xb/imm32/curr
73 89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . .
74
75
76 68/push 3/imm32
77 51/push-ECX
78
79 e8/call allocate/disp32
80
81 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
82
83
84 68/push "F - test-allocate-success: returns current pointer of allocation descriptor"/imm32
85 68/push 0xb/imm32
86 50/push-EAX
87
88 e8/call check-ints-equal/disp32
89
90 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
91
92
93 68/push "F - test-allocate-success: updates allocation descriptor"/imm32
94 68/push 0xe/imm32
95 ff 6/subop/push 0/mod/indirect 1/rm32/ECX . . . . . .
96
97 e8/call check-ints-equal/disp32
98
99 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
100
101 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
102 5d/pop-to-EBP
103 c3/return
104
105 test-allocate-failure:
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 6/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-failure: returns null"/imm32
124 68/push 0/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
133 68/push "F - test-allocate-failure: updates allocation descriptor"/imm32
134 68/push 0xb/imm32
135 ff 6/subop/push 0/mod/indirect 1/rm32/ECX . . . . . .
136
137 e8/call check-ints-equal/disp32
138
139 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
140
141 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
142 5d/pop-to-EBP
143 c3/return
144
145
146 allocate-region:
147
148 55/push-EBP
149 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
150
151 51/push-ECX
152
153
154 ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 0xc/disp8 .
155 ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 8/disp8 .
156
157 e8/call allocate/disp32
158
159 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
160
161 3d/compare-EAX-and 0/imm32
162 74/jump-if-equal $allocate-region:abort/disp8
163
164
165 89/copy 3/mod/direct 1/rm32/ECX . . . 0/r32/EAX . .
166 81 0/subop/add 3/mod/direct 1/rm32/ECX . . . . . 8/imm32
167 89/copy 0/mod/indirect 0/rm32/EAX . . . 1/r32/ECX . .
168
169 89/copy 3/mod/direct 1/rm32/ECX . . . 0/r32/EAX . .
170 03/add 1/mod/*+disp8 5/rm32/EBP . . . 1/r32/ECX 0xc/disp8 .
171 89/copy 1/mod/*+disp8 0/rm32/EAX . . . 1/r32/ECX 4/disp8 .
172
173 59/pop-to-ECX
174
175 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
176 5d/pop-to-EBP
177 c3/return
178
179
180
181
182
183
184
185 $allocate-region:abort:
186
187
188 68/push "allocate-region: failed to allocate"/imm32
189 68/push 2/imm32/stderr
190
191 e8/call _write/disp32
192
193 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
194
195 bb/copy-to-EBX 1/imm32
196 b8/copy-to-EAX 1/imm32/exit
197 cd/syscall 0x80/imm8
198
199
200