https://github.com/akkartik/mu/blob/main/baremetal/309stream.subx
1
2
3
4 == code
5
6 stream-empty?:
7
8 55/push-ebp
9 89/<- %ebp 4/r32/esp
10
11 51/push-ecx
12 56/push-esi
13
14 b8/copy-to-eax 0/imm32/false
15
16 8b/-> *(ebp+8) 6/r32/esi
17
18 8b/-> *esi 1/r32/ecx
19 39/compare-with *(esi+4) 1/r32/ecx
20 0f 9d/set-if->= %al
21 $stream-empty?:end:
22
23 5e/pop-to-esi
24 59/pop-to-ecx
25
26 89/<- %esp 5/r32/ebp
27 5d/pop-to-ebp
28 c3/return
29
30 stream-full?:
31
32 55/push-ebp
33 89/<- %ebp 4/r32/esp
34
35 51/push-ecx
36 56/push-esi
37
38 b8/copy-to-eax 0/imm32/false
39
40 8b/-> *(ebp+8) 6/r32/esi
41
42 8b/-> *(esi+8) 1/r32/ecx
43 39/compare-with *esi 1/r32/ecx
44 0f 9d/set-if->= %al
45 $stream-full?:end:
46
47 5e/pop-to-esi
48 59/pop-to-ecx
49
50 89/<- %esp 5/r32/ebp
51 5d/pop-to-ebp
52 c3/return
53
54 write-to-stream:
55
56 55/push-ebp
57 89/<- %ebp 4/r32/esp
58
59 50/push-eax
60 51/push-ecx
61 52/push-edx
62 53/push-ebx
63 57/push-edi
64
65 8b/-> *(ebp+8) 7/r32/edi
66
67 8b/-> *edi 2/r32/edx
68
69 8b/-> *(ebp+0x10) 1/r32/ecx
70 01/add-to %ecx 2/r32/edx
71 3b/compare 1/r32/ecx *(edi+8)
72 0f 8f/jump-if-> $write-to-stream:abort/disp32
73
74 8d/copy-address *(edi+edx+0xc) 2/r32/edx
75
76 8b/-> *(ebp+0x10) 3/r32/ebx
77 8d/copy-address *(edx+ebx) 3/r32/ebx
78
79 8b/-> *(ebp+0xc) 0/r32/eax
80
81 8b/-> *(ebp+0x10) 1/r32/ecx
82 8d/copy-address *(eax+ecx) 1/r32/ecx
83
84 (_append-4 %edx %ebx %eax %ecx)
85
86 8b/-> *(ebp+0x10) 1/r32/ecx
87 01/add-to *edi 1/r32/ecx
88 $write-to-stream:end:
89
90 5f/pop-to-edi
91 5b/pop-to-ebx
92 5a/pop-to-edx
93 59/pop-to-ecx
94 58/pop-to-eax
95
96 89/<- %esp 5/r32/ebp
97 5d/pop-to-ebp
98 c3/return
99
100 $write-to-stream:abort:
101 (draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0 "write-to-stream: stream full" 3)
102 {
103 eb/jump loop/disp8
104 }
105
106
107 read-from-stream:
108
109 55/push-ebp
110 89/<- %ebp 4/r32/esp
111
112 50/push-eax
113 51/push-ecx
114 52/push-edx
115 53/push-ebx
116 56/push-esi
117
118 8b/-> *(ebp+8) 6/r32/esi
119
120 8b/-> *(esi+4) 2/r32/edx
121
122 8b/-> *(ebp+0x10) 1/r32/ecx
123 01/add-to %ecx 2/r32/edx
124 3b/compare 1/r32/ecx *esi
125 0f 8f/jump-if-> $read-from-stream:abort/disp32
126
127 8d/copy-address *(esi+edx+0xc) 2/r32/edx
128
129 8b/-> *(ebp+0x10) 3/r32/ebx
130 8d/copy-address *(edx+ebx) 3/r32/ebx
131
132 8b/-> *(ebp+0xc) 0/r32/eax
133
134 8b/-> *(ebp+0x10) 1/r32/ecx
135 8d/copy-address *(eax+ecx) 1/r32/ecx
136
137 (_append-4 %eax %ecx %edx %ebx)
138
139 8b/-> *(ebp+0x10) 1/r32/ecx
140 01/add-to *(esi+4) 1/r32/ecx
141 $read-from-stream:end:
142
143 5e/pop-to-esi
144 5b/pop-to-ebx
145 5a/pop-to-edx
146 59/pop-to-ecx
147 58/pop-to-eax
148
149 89/<- %esp 5/r32/ebp
150 5d/pop-to-ebp
151 c3/return
152
153 $read-from-stream:abort:
154 (draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0 "read-from-stream: stream empty" 3)
155 {
156 eb/jump loop/disp8
157 }
158
159
160 stream-first:
161
162 55/push-ebp
163 89/<- %ebp 4/r32/esp
164
165 51/push-ecx
166 56/push-esi
167
168 b8/copy-to-eax 0/imm32
169
170 8b/-> *(ebp+8) 6/r32/esi
171
172 8b/-> *(esi+4) 1/r32/ecx
173
174 3b/compare-with 1/r32/ecx *esi
175 7d/jump-if->= $stream-first:end/disp8
176
177 8a/byte-> *(esi+ecx+0xc) 0/r32/AL
178 $stream-first:end:
179
180 5e/pop-to-esi
181 59/pop-to-ecx
182
183 89/<- %esp 5/r32/ebp
184 5d/pop-to-ebp
185 c3/return
186
187 stream-final:
188
189 55/push-ebp
190 89/<- %ebp 4/r32/esp
191
192 51/push-ecx
193 56/push-esi
194
195 b8/copy-to-eax 0/imm32
196
197 8b/-> *(ebp+8) 6/r32/esi
198
199 8b/-> *esi 1/r32/ecx
200
201 39/compare-with *(esi+4) 1/r32/ecx
202 7d/jump-if->= $stream-final:end/disp8
203
204 49/decrement-ecx
205
206 8a/byte-> *(esi+ecx+0xc) 0/r32/AL
207 $stream-final:end:
208
209 5e/pop-to-esi
210 59/pop-to-ecx
211
212 89/<- %esp 5/r32/ebp
213 5d/pop-to-ebp
214 c3/return