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-greater-or-equal $slurp:abort/disp8
39
40 3b/compare 1/mod/*+disp8 6/rm32/esi . . . 1/r32/ecx 4/disp8 .
41 7c/jump-if-lesser $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-equal $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 b8/copy-to-eax 1/imm32/exit
104 cd/syscall 0x80/imm8
105
106
107 test-slurp:
108
109
110
111 68/push _test-stream/imm32
112
113 e8/call clear-stream/disp32
114
115 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
116
117
118 68/push $_test-buffered-file->buffer/imm32
119
120 e8/call clear-stream/disp32
121
122 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
123
124
125 68/push _test-tmp-stream/imm32
126
127 e8/call clear-stream/disp32
128
129 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
130
131
132 68/push "ab\ncd"/imm32
133 68/push _test-stream/imm32
134
135 e8/call write/disp32
136
137 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
138
139
140
141 68/push _test-tmp-stream/imm32
142 68/push _test-buffered-file/imm32
143
144 e8/call slurp/disp32
145
146 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
147
148
149 68/push "F - test-slurp"/imm32
150 68/push "ab\ncd"/imm32
151 68/push _test-tmp-stream/imm32
152
153 e8/call check-stream-equal/disp32
154
155 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
156
157 c3/return
158
159