1 # write-stream: like write, but write streams rather than strings
4 # instruction effective address register displacement immediate
5 # . op subop mod rm32 base index scale r32
6 # . 1-3 bytes 3 bits 2 bits 3 bits 3 bits 3 bits 2 bits 2 bits 0/1/2/4 bytes 0/1/2/4 bytes
8 write-stream: # f: (addr stream byte), s: (addr stream byte)
11 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp
17 8b/copy 1/mod/*+disp8 5/rm32/ebp . . 7/r32/edi 8/disp8 . # copy *(ebp+8) to edi
19 8b/copy 1/mod/*+disp8 5/rm32/ebp . . 6/r32/esi 0xc/disp8 . # copy *(ebp+12) to esi
20 # eax = _append-4(&f->data[f->write], &f->data[f->size], &s->data[s->read], &s->data[s->write])
21 # . . push &s->data[s->write]
22 8b/copy 0/mod/indirect 6/rm32/esi . . . 0/r32/eax . . # copy *esi to eax
23 8d/copy-address 1/mod/*+disp8 4/rm32/sib 6/base/esi 0/index/eax . 0/r32/eax 0xc/disp8 . # copy esi+eax+12 to eax
25 # . . push &s->data[s->read]
26 8b/copy 1/mod/*+disp8 6/rm32/esi . . . 0/r32/eax 4/disp8 . # copy *(esi+4) to eax
27 8d/copy-address 1/mod/*+disp8 4/rm32/sib 6/base/esi 0/index/eax . 0/r32/eax 0xc/disp8 . # copy esi+eax+12 to eax
29 # . . push &f->data[f->size]
30 8b/copy 1/mod/*+disp8 7/rm32/edi . . . 0/r32/eax 8/disp8 . # copy *(edi+8) to eax
31 8d/copy-address 1/mod/*+disp8 4/rm32/sib 7/base/edi 0/index/eax . 0/r32/eax 0xc/disp8 . # copy edi+eax+12 to eax
33 # . . push &f->data[f->write]
34 8b/copy 0/mod/indirect 7/rm32/edi . . . 0/r32/eax . . # copy *edi to eax
35 8d/copy-address 1/mod/*+disp8 4/rm32/sib 7/base/edi 0/index/eax . 0/r32/eax 0xc/disp8 . # copy edi+eax+12 to eax
38 e8/call _append-4/disp32
40 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32 # add to esp
42 01/add 0/mod/indirect 7/rm32/edi . . . 0/r32/eax . . # add eax to *edi
44 01/add 1/mod/*+disp8 6/rm32/esi . . . 0/r32/eax 4/disp8 . # add eax to *(esi+4)
51 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp
55 test-write-stream-single:
57 # . clear-stream(_test-stream)
59 68/push _test-stream/imm32
61 e8/call clear-stream/disp32
63 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp
64 # . clear-stream(_test-stream2)
66 68/push _test-stream2/imm32
68 e8/call clear-stream/disp32
70 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp
71 # . write(_test-stream2, "Ab")
74 68/push _test-stream2/imm32
78 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp
79 # write-stream(_test-stream, _test-stream2)
81 68/push _test-stream2/imm32
82 68/push _test-stream/imm32
84 e8/call write-stream/disp32
86 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp
87 # check-stream-equal(_test-stream, "Ab", msg)
89 68/push "F - test-write-stream-single"/imm32
91 68/push _test-stream/imm32
93 e8/call check-stream-equal/disp32
95 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp
99 test-write-stream-appends:
101 # . clear-stream(_test-stream)
103 68/push _test-stream/imm32
105 e8/call clear-stream/disp32
107 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp
108 # . clear-stream(_test-stream2)
110 68/push _test-stream2/imm32
112 e8/call clear-stream/disp32
114 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp
115 # . write(_test-stream2, "C")
118 68/push _test-stream2/imm32
122 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp
124 # . write-stream(_test-stream, _test-stream2)
126 68/push _test-stream2/imm32
127 68/push _test-stream/imm32
129 e8/call write-stream/disp32
131 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp
133 # . write(_test-stream2, "D")
136 68/push _test-stream2/imm32
140 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp
141 # . write-stream(_test-stream, _test-stream2)
143 68/push _test-stream2/imm32
144 68/push _test-stream/imm32
146 e8/call write-stream/disp32
148 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp
149 # check-stream-equal(_test-stream, "CD", msg)
151 68/push "F - test-write-stream-appends"/imm32
153 68/push _test-stream/imm32
155 e8/call check-stream-equal/disp32
157 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp
161 # like write-stream, but don't update s->read
162 # is there a better name for this?
163 write-stream-immutable: # f: (addr stream byte), s: (addr stream byte)
166 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp
172 8b/copy 1/mod/*+disp8 5/rm32/ebp . . 7/r32/edi 8/disp8 . # copy *(ebp+8) to edi
174 8b/copy 1/mod/*+disp8 5/rm32/ebp . . 6/r32/esi 0xc/disp8 . # copy *(ebp+12) to esi
175 # eax = _append-4(&f->data[f->write], &f->data[f->size], &s->data[s->read], &s->data[s->write])
176 # . . push &s->data[s->write]
177 8b/copy 0/mod/indirect 6/rm32/esi . . . 0/r32/eax . . # copy *esi to eax
178 8d/copy-address 1/mod/*+disp8 4/rm32/sib 6/base/esi 0/index/eax . 0/r32/eax 0xc/disp8 . # copy esi+eax+12 to eax
180 # . . push &s->data[s->read]
181 8b/copy 1/mod/*+disp8 6/rm32/esi . . . 0/r32/eax 4/disp8 . # copy *(esi+4) to eax
182 8d/copy-address 1/mod/*+disp8 4/rm32/sib 6/base/esi 0/index/eax . 0/r32/eax 0xc/disp8 . # copy esi+eax+12 to eax
184 # . . push &f->data[f->size]
185 8b/copy 1/mod/*+disp8 7/rm32/edi . . . 0/r32/eax 8/disp8 . # copy *(edi+8) to eax
186 8d/copy-address 1/mod/*+disp8 4/rm32/sib 7/base/edi 0/index/eax . 0/r32/eax 0xc/disp8 . # copy edi+eax+12 to eax
188 # . . push &f->data[f->write]
189 8b/copy 0/mod/indirect 7/rm32/edi . . . 0/r32/eax . . # copy *edi to eax
190 8d/copy-address 1/mod/*+disp8 4/rm32/sib 7/base/edi 0/index/eax . 0/r32/eax 0xc/disp8 . # copy edi+eax+12 to eax
193 e8/call _append-4/disp32
195 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32 # add to esp
197 01/add 0/mod/indirect 7/rm32/edi . . . 0/r32/eax . . # add eax to *edi
198 $write-stream-immutable:end:
199 # . restore registers
204 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp
210 _test-stream2: # (stream byte)
211 # current write index
218 41/A 42/B 43/C 44/D 00 00 00 00 # 8 bytes
220 # . . vim:nowrap:textwidth=0