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