https://github.com/akkartik/mu/blob/main/310copy-bytes.subx
1
2
3
4 == code
5
6 copy-bytes:
7
8
9
10
11
12
13
14
15
16
17
18
19 55/push-ebp
20 89/<- %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/-> *(ebp+8) 6/r32/esi
29
30 8b/-> *(ebp+0xc) 7/r32/edi
31
32 b9/copy-to-ecx 0/imm32
33
34 8b/-> *(ebp+0x10) 2/r32/edx
35 {
36
37 39/compare %ecx 2/r32/edx
38 7d/jump-if->= break/disp8
39
40 8a/byte-> *esi 0/r32/AL
41 88/byte<- *edi 0/r32/AL
42
43 46/increment-esi
44 47/increment-edi
45 41/increment-ecx
46 eb/jump loop/disp8
47 }
48 $copy-bytes:end:
49
50 5f/pop-to-edi
51 5e/pop-to-esi
52 5a/pop-to-edx
53 59/pop-to-ecx
54 58/pop-to-eax
55
56 89/<- %esp 5/r32/ebp
57 5d/pop-to-ebp
58 c3/return
59
60 stream-to-array:
61
62 55/push-ebp
63 89/<- %ebp 4/r32/esp
64
65 50/push-eax
66 51/push-ecx
67 52/push-edx
68 56/push-esi
69
70 8b/-> *(ebp+8) 6/r32/esi
71
72 8b/-> *esi 1/r32/ecx
73 2b/subtract *(esi+4) 1/r32/ecx
74
75 (allocate-array Heap %ecx *(ebp+0xc))
76
77 8b/-> *(esi+4) 2/r32/edx
78 8d/copy-address *(esi+edx+0xc) 2/r32/edx
79
80 8b/-> *(ebp+0xc) 0/r32/eax
81 (lookup *eax *(eax+4))
82 8d/copy-address *(eax+4) 0/r32/eax
83
84 (copy-bytes %edx %eax %ecx)
85 $stream-to-array:end:
86
87 5e/pop-to-esi
88 5a/pop-to-edx
89 59/pop-to-ecx
90 58/pop-to-eax
91
92 89/<- %esp 5/r32/ebp
93 5d/pop-to-ebp
94 c3/return
95
96 test-stream-to-array:
97
98 55/push-ebp
99 89/<- %ebp 4/r32/esp
100
101 (clear-stream _test-input-stream)
102 (write _test-input-stream "abc")
103
104 (read-byte _test-input-stream)
105 8b/-> *$_test-input-stream->read 0/r32/eax
106 (check-ints-equal %eax 1 "F - test-stream-to-array/pre")
107
108 68/push 0/imm32
109 68/push 0/imm32
110 89/<- %ecx 4/r32/esp
111
112 (stream-to-array _test-input-stream %ecx)
113 (lookup *ecx *(ecx+4))
114 (check-strings-equal %eax "bc" "F - test-stream-to-array")
115 8b/-> *$_test-input-stream->read 0/r32/eax
116 (check-ints-equal %eax 1 "F - test-stream-to-array/read-pointer-not-perturbed")
117
118 89/<- %esp 5/r32/ebp
119 5d/pop-to-ebp
120 c3/return
121
122
123
124 unquote-stream-to-array:
125
126 55/push-ebp
127 89/<- %ebp 4/r32/esp
128
129 50/push-eax
130 51/push-ecx
131 52/push-edx
132 56/push-esi
133
134 8b/-> *(ebp+8) 6/r32/esi
135
136 8b/-> *esi 1/r32/ecx
137 2b/subtract *(esi+4) 1/r32/ecx
138 81 7/subop/compare %ecx 2/imm32
139 7c/jump-if-< $unquote-stream-to-array:end/disp8
140 81 5/subop/subtract %ecx 2/imm32
141
142 (allocate-array Heap %ecx *(ebp+0xc))
143
144 8b/-> *(esi+4) 2/r32/edx
145 8d/copy-address *(esi+edx+0xd) 2/r32/edx
146
147 8b/-> *(ebp+0xc) 0/r32/eax
148 (lookup *eax *(eax+4))
149 8d/copy-address *(eax+4) 0/r32/eax
150
151 (copy-bytes %edx %eax %ecx)
152 $unquote-stream-to-array:end:
153
154 5e/pop-to-esi
155 5a/pop-to-edx
156 59/pop-to-ecx
157 58/pop-to-eax
158
159 89/<- %esp 5/r32/ebp
160 5d/pop-to-ebp
161 c3/return