https://github.com/akkartik/mu/blob/master/082slurp.subx
1 == code
2
3
4
5
6
7
8 slurp:
9
10
11
12
13
14
15
16
17
18
19 55/push-ebp
20 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
21
22 50/push-eax
23 51/push-ecx
24 52/push-edx
25 56/push-esi
26 57/push-edi
27
28 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 6/r32/esi 8/disp8 .
29
30 8b/copy 1/mod/*+disp8 6/rm32/esi . . . 1/r32/ecx 8/disp8 .
31
32 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 7/r32/edi 0xc/disp8 .
33
34 8b/copy 0/mod/indirect 7/rm32/edi . . . 2/r32/edx . .
35 $slurp:loop:
36
37 3b/compare 1/mod/*+disp8 7/rm32/edi . . . 2/r32/edx 8/disp8 .
38 7d/jump-if->= $slurp:abort/disp8
39
40 3b/compare 1/mod/*+disp8 6/rm32/esi . . . 1/r32/ecx 4/disp8 .
41 7c/jump-if-< $slurp:from-stream/disp8
42
43
44 8d/copy-address 1/mod/*+disp8 6/rm32/esi . . . 0/r32/eax 4/disp8 .
45 50/push-eax
46
47 e8/call clear-stream/disp32
48
49 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
50
51 31/xor 3/mod/direct 1/rm32/ecx . . . 1/r32/ecx . .
52
53
54 50/push-eax
55 ff 6/subop/push 0/mod/indirect 6/rm32/esi . . . . . .
56
57 e8/call read/disp32
58
59 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
60
61
62
63 3d/compare-eax-and 0/imm32
64 74/jump-if-= $slurp:end/disp8
65 $slurp:from-stream:
66
67 31/xor 3/mod/direct 0/rm32/eax . . . 0/r32/eax . .
68 8a/copy-byte 1/mod/*+disp8 4/rm32/sib 6/base/esi 1/index/ecx . 0/r32/AL 0x10/disp8 .
69
70 88/copy-byte 1/mod/*+disp8 4/rm32/sib 7/base/edi 2/index/edx . 0/r32/AL 0xc/disp8 .
71
72 41/increment-ecx
73
74 42/increment-edx
75 eb/jump $slurp:loop/disp8
76 $slurp:end:
77
78 89/copy 1/mod/*+disp8 6/rm32/esi . . . 1/r32/ecx 8/disp8 .
79
80 89/copy 0/mod/indirect 7/rm32/edi . . . 2/r32/edx . .
81
82 5f/pop-to-edi
83 5e/pop-to-esi
84 5a/pop-to-edx
85 59/pop-to-ecx
86 58/pop-to-eax
87
88 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
89 5d/pop-to-ebp
90 c3/return
91
92 $slurp:abort:
93
94
95 68/push "slurp: destination too small\n"/imm32
96 68/push 2/imm32/stderr
97
98 e8/call _write/disp32
99
100 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
101
102 bb/copy-to-ebx 1/imm32
103 e8/call syscall_exit/disp32
104
105
106 test-slurp:
107
108
109
110 68/push _test-stream/imm32
111
112 e8/call clear-stream/disp32
113
114 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
115
116
117 68/push $_test-buffered-file->buffer/imm32
118
119 e8/call clear-stream/disp32
120
121 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
122
123
124 68/push _test-tmp-stream/imm32
125
126 e8/call clear-stream/disp32
127
128 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
129
130
131 68/push "ab\ncd"/imm32
132 68/push _test-stream/imm32
133
134 e8/call write/disp32
135
136 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
137
138
139
140 68/push _test-tmp-stream/imm32
141 68/push _test-buffered-file/imm32
142
143 e8/call slurp/disp32
144
145 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
146
147
148 68/push "F - test-slurp"/imm32
149 68/push "ab\ncd"/imm32
150 68/push _test-tmp-stream/imm32
151
152 e8/call check-stream-equal/disp32
153
154 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
155
156 c3/return
157
158