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