https://github.com/akkartik/mu/blob/master/077slurp.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 b8/copy-to-EAX _test-buffered-file/imm32
119 05/add-to-EAX 4/imm32
120 50/push-EAX
121
122 e8/call clear-stream/disp32
123
124 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
125
126
127 68/push _test-tmp-stream/imm32
128
129 e8/call clear-stream/disp32
130
131 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
132
133
134 68/push "ab\ncd"/imm32
135 68/push _test-stream/imm32
136
137 e8/call write/disp32
138
139 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
140
141
142
143 68/push _test-tmp-stream/imm32
144 68/push _test-buffered-file/imm32
145
146 e8/call slurp/disp32
147
148 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
149
150
151 68/push "F - test-slurp"/imm32
152 68/push "ab\ncd"/imm32
153 68/push _test-tmp-stream/imm32
154
155 e8/call check-stream-equal/disp32
156
157 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
158
159 c3/return
160
161