https://github.com/akkartik/mu/blob/master/subx/057write.subx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 == code
19
20
21
22
23
24 e8/call run-tests/disp32
25
26 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/EBX Num-test-failures/disp32
27 b8/copy-to-EAX 1/imm32/exit
28 cd/syscall 0x80/imm8
29
30
31 write:
32
33 55/push-EBP
34 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
35
36 81 7/subop/compare 1/mod/*+disp8 5/rm32/EBP . . . . 8/disp8 0x08000000/imm32
37 7d/jump-if-greater-or-equal $write:fake/disp8
38
39 ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 0xc/disp8 .
40 ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 8/disp8 .
41
42 e8/call _write/disp32
43
44 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
45 eb/jump $write:end/disp8
46 $write:fake:
47
48
49 50/push-EAX
50 51/push-ECX
51 52/push-EDX
52 53/push-EBX
53
54 8b/copy 1/mod/*+disp8 5/rm32/EBP . . 1/r32/ECX 8/disp8 .
55
56 8b/copy 0/mod/indirect 1/rm32/ECX . . . 2/r32/EDX . .
57
58 8b/copy 1/mod/*+disp8 1/rm32/ECX . . . 3/r32/EBX 8/disp8 .
59
60
61 ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 0xc/disp8 .
62
63 8d/copy-address 1/mod/*+disp8 4/rm32/sib 1/base/ECX 3/index/EBX . 3/r32/EBX 0xc/disp8 .
64 53/push-EBX
65
66 8d/copy-address 1/mod/*+disp8 4/rm32/sib 1/base/ECX 2/index/EDX . 3/r32/EBX 0xc/disp8 .
67 53/push-EBX
68
69 e8/call _append-3/disp32
70
71 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
72
73 01/add 0/mod/indirect 1/rm32/ECX . . . 0/r32/EAX . .
74
75 5b/pop-to-EBX
76 5a/pop-to-EDX
77 59/pop-to-ECX
78 58/pop-to-EAX
79 $write:end:
80
81 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
82 5d/pop-to-EBP
83 c3/return
84
85 test-write-single:
86
87
88 68/push _test-stream/imm32
89
90 e8/call clear-stream/disp32
91
92 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
93
94
95 68/push "Ab"/imm32
96 68/push _test-stream/imm32
97
98 e8/call write/disp32
99
100 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
101
102
103 68/push "F - test-write-single"/imm32
104 68/push 0x006241/imm32/Ab
105
106 b8/copy-to-EAX _test-stream/imm32
107 ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX . . . . 0xc/disp8 .
108
109 e8/call check-ints-equal/disp32
110
111 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
112
113 c3/return
114
115 test-write-appends:
116
117
118 68/push _test-stream/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 "C"/imm32
126 68/push _test-stream/imm32
127
128 e8/call write/disp32
129
130 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
131
132
133 68/push "D"/imm32
134 68/push _test-stream/imm32
135
136 e8/call write/disp32
137
138 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
139
140
141 68/push "F - test-write-appends"/imm32
142 68/push 0x00004443/imm32/C-D
143
144 b8/copy-to-EAX _test-stream/imm32
145 ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX . . . . 0xc/disp8 .
146
147 e8/call check-ints-equal/disp32
148
149 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
150
151 c3/return
152
153 == data
154
155 _test-stream:
156
157 00 00 00 00
158
159 00 00 00 00
160
161 08 00 00 00
162
163 00 00 00 00 00 00 00 00
164
165