https://github.com/akkartik/mu/blob/master/091write-int.subx
1
2
3 == code
4
5
6
7
8 write-int:
9
10 55/push-ebp
11 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
12
13 50/push-eax
14 51/push-ecx
15 57/push-edi
16
17 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 7/r32/edi 8/disp8 .
18
19 8b/copy 0/mod/indirect 7/rm32/edi . . . 1/r32/ecx . .
20
21 3b/compare 1/mod/*+disp8 7/rm32/edi . . . 1/r32/ecx 8/disp8 .
22 7d/jump-if-greater-or-equal $write-int:abort/disp8
23 $write-int:to-stream:
24
25 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 0/r32/eax 0xc/disp8 .
26 89/copy 1/mod/*+disp8 4/rm32/sib 7/base/edi 1/index/ecx . 0/r32/eax 0xc/disp8 .
27
28 81 0/subop/add 0/mod/indirect 7/rm32/edi . . . . . 4/imm32
29 $write-int:end:
30
31 5f/pop-to-edi
32 59/pop-to-ecx
33 58/pop-to-eax
34
35 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
36 5d/pop-to-ebp
37 c3/return
38
39 $write-int:abort:
40
41
42 68/push "write-int: out of space\n"/imm32
43 68/push 2/imm32/stderr
44
45 e8/call _write/disp32
46
47 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
48
49 bb/copy-to-ebx 1/imm32
50 b8/copy-to-eax 1/imm32/exit
51 cd/syscall 0x80/imm8
52
53
54 test-write-int-single:
55
56
57
58
59 68/push _test-stream/imm32
60
61 e8/call clear-stream/disp32
62
63 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
64
65
66 68/push 0x64636261/imm32
67 68/push _test-stream/imm32
68
69 e8/call write-int/disp32
70
71 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
72
73
74 68/push "F - test-write-int-single"/imm32
75 68/push "abcd"/imm32
76 68/push _test-stream/imm32
77
78 e8/call check-stream-equal/disp32
79
80 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
81
82 c3/return
83
84 test-write-byte-buffered-multiple:
85
86
87
88
89 68/push _test-stream/imm32
90
91 e8/call clear-stream/disp32
92
93 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
94
95
96 68/push 0x64636261/imm32
97 68/push _test-stream/imm32
98
99 e8/call write-int/disp32
100
101 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
102
103
104 68/push 0x68676665/imm32
105 68/push _test-stream/imm32
106
107 e8/call write-int/disp32
108
109 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
110
111
112 68/push "F - test-write-byte-buffered-multiple"/imm32
113 68/push "abcdefgh"/imm32
114 68/push _test-stream/imm32
115
116 e8/call check-stream-equal/disp32
117
118 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
119
120 c3/return
121
122