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