https://github.com/akkartik/mu/blob/master/070new-stream.subx
1
2
3 == code
4
5
6
7
8 new-stream:
9
10 55/push-ebp
11 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
12
13 52/push-edx
14
15
16 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 0/r32/eax 0x10/disp8 .
17
18 31/xor 3/mod/direct 2/rm32/edx . . . 2/r32/edx . .
19 f7 4/subop/multiply 1/mod/*+disp8 5/rm32/ebp . . 0xc/disp8 .
20
21 81 7/subop/compare 3/mod/direct 2/rm32/edx . . . . . 0/imm32
22 75/jump-if-!= $new-stream:abort/disp8
23
24 89/copy 3/mod/direct 2/rm32/edx . . . 0/r32/eax . .
25
26 05/add-to-eax 0xc/imm32
27
28
29 50/push-eax
30 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
31
32 e8/call allocate/disp32
33
34 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
35
36 89/copy 1/mod/*+disp8 0/rm32/eax . . . 2/r32/edx 8/disp8 .
37
38
39 50/push-eax
40
41 e8/call clear-stream/disp32
42
43 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
44 $new-stream:end:
45
46 5a/pop-to-edx
47
48 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
49 5d/pop-to-ebp
50 c3/return
51
52 $new-stream:abort:
53
54
55 68/push "new-stream: size too large\n"/imm32
56 68/push 2/imm32/stderr
57
58 e8/call _write/disp32
59
60 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
61
62 bb/copy-to-ebx 1/imm32
63 b8/copy-to-eax 1/imm32/exit
64 cd/syscall 0x80/imm8
65
66
67 test-new-stream:
68
69 55/push-ebp
70 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
71
72 68/push 0/imm32/limit
73 68/push 0/imm32/curr
74 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . .
75
76
77 51/push-ecx
78 68/push 0x200/imm32
79
80 e8/call new-segment/disp32
81
82 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
83
84 8b/copy 0/mod/indirect 1/rm32/ecx . . . 2/r32/edx . .
85
86
87 68/push 2/imm32
88 68/push 3/imm32
89 51/push-ecx
90
91 e8/call new-stream/disp32
92
93 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
94
95
96 68/push "F - test-new-stream: returns current pointer of allocation descriptor"/imm32
97 52/push-edx
98 50/push-eax
99
100 e8/call check-ints-equal/disp32
101
102 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
103
104
105 68/push "F - test-new-stream: sets length correctly"/imm32
106 68/push 6/imm32
107 ff 6/subop/push 1/mod/*+disp8 0/rm32/eax . . . . . 8/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
114 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
115 5d/pop-to-ebp
116 c3/return
117
118