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