https://github.com/akkartik/mu/blob/master/subx/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-not-equal $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