https://github.com/akkartik/mu/blob/master/subx/066allocate.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 00 00 00 0b
26
27 == code
28
29
30
31
32
33 e8/call run-tests/disp32
34
35 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/EBX Num-test-failures/disp32
36 b8/copy-to-EAX 1/imm32/exit
37 cd/syscall 0x80/imm8
38
39
40
41 allocate:
42
43 55/push-EBP
44 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
45
46 51/push-ECX
47 52/push-EDX
48
49 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 1/r32/ECX 8/disp8 .
50
51 8b/copy 0/mod/indirect 1/rm32/ECX . . . 0/r32/EAX . .
52
53
54 89/copy 3/mod/direct 2/rm32/EDX . . . 0/r32/EAX . .
55 03/add 1/mod/*+disp8 5/rm32/EBP . . . 2/r32/EDX 0xc/disp8 .
56 3b/compare 1/mod/*+disp8 1/rm32/ECX . . . 2/r32/EDX 4/disp8 .
57 7c/jump-if-lesser $allocate:commit/disp8
58
59 b8/copy-to-EAX 0/imm32
60 eb/jump $allocate:end/disp8
61 $allocate:commit:
62
63 89/copy 0/mod/indirect 1/rm32/ECX . . . 2/r32/EDX . .
64 $allocate:end:
65
66 5a/pop-to-EDX
67 59/pop-to-ECX
68
69 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
70 5d/pop-to-EBP
71 c3/return
72
73 test-allocate-success:
74
75 55/push-EBP
76 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
77
78 68/push 0xf/imm32/limit
79 68/push 0xb/imm32/curr
80 89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . .
81
82
83 68/push 3/imm32
84 51/push-ECX
85
86 e8/call allocate/disp32
87
88 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
89
90
91 68/push "F - test-allocate-success: returns current pointer of allocation descriptor"/imm32
92 68/push 0xb/imm32
93 50/push-EAX
94
95 e8/call check-ints-equal/disp32
96
97 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
98
99
100 68/push "F - test-allocate-success: updates allocation descriptor"/imm32
101 68/push 0xe/imm32
102 ff 6/subop/push 0/mod/indirect 1/rm32/ECX . . . . . .
103
104 e8/call check-ints-equal/disp32
105
106 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
107
108 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
109 5d/pop-to-EBP
110 c3/return
111
112 test-allocate-failure:
113
114 55/push-EBP
115 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
116
117 68/push 0xf/imm32/limit
118 68/push 0xb/imm32/curr
119 89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . .
120
121
122 68/push 6/imm32
123 51/push-ECX
124
125 e8/call allocate/disp32
126
127 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
128
129
130 68/push "F - test-allocate-failure: returns null"/imm32
131 68/push 0/imm32
132 50/push-EAX
133
134 e8/call check-ints-equal/disp32
135
136 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
137
138
139
140 68/push "F - test-allocate-failure: updates allocation descriptor"/imm32
141 68/push 0xb/imm32
142 ff 6/subop/push 0/mod/indirect 1/rm32/ECX . . . . . .
143
144 e8/call check-ints-equal/disp32
145
146 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
147
148 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
149 5d/pop-to-EBP
150 c3/return
151
152