Rev 4865 | Rev 4882 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4865 | eAndrew | 1 | macro test_err |
2 | { local ..not_error |
||
3 | cmp [error_n], 0 |
||
4 | je ..not_error |
||
5 | ret |
||
6 | ..not_error: |
||
7 | } |
||
8 | |||
9 | macro set_err err |
||
10 | { |
||
11 | mov [error_n], err |
||
12 | ret |
||
13 | } |
||
14 | |||
15 | ; --------------------------- |
||
16 | |||
17 | proc parse |
||
18 | mov [exp_pos], 0 |
||
4875 | eAndrew | 19 | stdcall skip_spaces |
20 | |||
21 | mov ebx, exp |
||
22 | add ebx, [exp_pos] |
||
23 | cmp [ebx], byte 0 |
||
24 | je .null_exp |
||
25 | |||
26 | mov [exp_lvl], 0 |
||
4865 | eAndrew | 27 | mov [error_n], 0 |
28 | stdcall parse_lvl0 |
||
29 | ret |
||
4875 | eAndrew | 30 | |
31 | .null_exp: |
||
32 | mov eax, 0 |
||
33 | ret |
||
4865 | eAndrew | 34 | endp |
35 | |||
36 | ; --------------------------- |
||
37 | |||
38 | proc parse_lvl0 uses ebx ecx |
||
39 | test_err |
||
40 | stdcall parse_lvl1 |
||
41 | test_err |
||
42 | @@: |
||
43 | mov ebx, exp |
||
44 | add ebx, [exp_pos] |
||
45 | cmp [ebx], byte 0 |
||
46 | je .end |
||
47 | cmp [ebx], byte ")" |
||
4875 | eAndrew | 48 | je .brk_end |
4865 | eAndrew | 49 | inc [exp_pos] |
50 | cmp [ebx], byte "+" |
||
51 | jne .not_add |
||
52 | mov ecx, eax |
||
53 | stdcall parse_lvl1 |
||
54 | test_err |
||
55 | add eax, ecx |
||
56 | jmp @b |
||
57 | .not_add: |
||
58 | cmp [ebx], byte "-" |
||
4875 | eAndrew | 59 | jne .unexp_char |
4865 | eAndrew | 60 | mov ecx, eax |
61 | stdcall parse_lvl1 |
||
62 | test_err |
||
63 | sub ecx, eax |
||
64 | mov eax, ecx |
||
65 | jmp @b |
||
4875 | eAndrew | 66 | .brk_end: |
67 | cmp [exp_lvl], 0 |
||
68 | jne @f |
||
69 | set_err 3 |
||
70 | @@: |
||
71 | dec [exp_lvl] |
||
4865 | eAndrew | 72 | .end: |
73 | ret |
||
4875 | eAndrew | 74 | .unexp_char: |
75 | set_err 4 |
||
4865 | eAndrew | 76 | endp |
77 | |||
78 | ; --------------------------- |
||
79 | |||
80 | proc parse_lvl1 uses ebx ecx edx |
||
81 | test_err |
||
82 | stdcall parse_lvl2 |
||
83 | test_err |
||
84 | @@: |
||
85 | mov ebx, exp |
||
86 | add ebx, [exp_pos] |
||
87 | cmp [ebx], byte 0 |
||
88 | je .end |
||
89 | cmp [ebx], byte "*" |
||
90 | jne .not_mul |
||
4875 | eAndrew | 91 | inc [exp_pos] |
4865 | eAndrew | 92 | mov ecx, eax |
93 | stdcall parse_lvl2 |
||
94 | test_err |
||
95 | imul ecx, eax |
||
96 | mov eax, ecx |
||
97 | jmp @b |
||
98 | .not_mul: |
||
99 | cmp [ebx], byte "/" |
||
100 | je .div_or_mod |
||
101 | cmp [ebx], byte "%" |
||
102 | je .div_or_mod |
||
103 | jmp .end |
||
104 | .div_or_mod: |
||
4875 | eAndrew | 105 | inc [exp_pos] |
4865 | eAndrew | 106 | mov ecx, eax |
107 | stdcall parse_lvl2 |
||
108 | test_err |
||
109 | cmp eax, 0 |
||
110 | jne .not_null |
||
111 | set_err 1 |
||
112 | .not_null: |
||
113 | xchg ecx, eax |
||
114 | cdq |
||
115 | div ecx |
||
116 | cmp [ebx], byte "%" |
||
117 | je .mod |
||
118 | jmp @b |
||
119 | .mod: |
||
120 | mov eax, edx |
||
121 | jmp @b |
||
122 | .end: |
||
123 | ret |
||
124 | endp |
||
125 | |||
126 | ; --------------------------- |
||
127 | |||
4875 | eAndrew | 128 | proc parse_lvl2 uses ebx ecx edx |
4865 | eAndrew | 129 | test_err |
4875 | eAndrew | 130 | stdcall parse_lvl3 |
131 | test_err |
||
132 | @@: |
||
133 | mov ebx, exp |
||
134 | add ebx, [exp_pos] |
||
135 | cmp [ebx], byte 0 |
||
136 | je .end |
||
137 | cmp [ebx], byte "^" |
||
138 | jne .end |
||
139 | inc [exp_pos] |
||
140 | mov ecx, eax |
||
141 | stdcall parse_lvl2 |
||
142 | test_err |
||
143 | stdcall c_power |
||
144 | jmp @b |
||
145 | .end: |
||
146 | ret |
||
147 | endp |
||
148 | |||
149 | ; --------------------------- |
||
150 | |||
151 | proc parse_lvl3 uses ebx |
||
152 | test_err |
||
4865 | eAndrew | 153 | stdcall skip_spaces |
154 | mov ebx, exp |
||
155 | add ebx, [exp_pos] |
||
156 | cmp [ebx], byte 48 |
||
157 | jl @f |
||
158 | cmp [ebx], byte 57 |
||
159 | jg @f |
||
4875 | eAndrew | 160 | stdcall parse_lvl4 |
4865 | eAndrew | 161 | jmp .end |
162 | @@: |
||
163 | inc [exp_pos] |
||
164 | cmp [ebx], byte "(" |
||
165 | jne @f |
||
4875 | eAndrew | 166 | inc [exp_lvl] |
4865 | eAndrew | 167 | stdcall parse_lvl0 |
168 | test_err |
||
4875 | eAndrew | 169 | mov ebx, exp |
170 | add ebx, [exp_pos] |
||
171 | cmp [ebx], byte ")" |
||
172 | je .brk_ok |
||
173 | set_err 2 |
||
174 | .brk_ok: |
||
4865 | eAndrew | 175 | inc [exp_pos] |
176 | jmp .end |
||
177 | @@: |
||
178 | cmp [ebx], byte "+" |
||
179 | jne @f |
||
4875 | eAndrew | 180 | stdcall parse_lvl3 |
4865 | eAndrew | 181 | test_err |
182 | jmp .end |
||
183 | @@: |
||
184 | cmp [ebx], byte "-" |
||
4875 | eAndrew | 185 | jne .unexp_char |
186 | stdcall parse_lvl3 |
||
4865 | eAndrew | 187 | test_err |
188 | neg eax |
||
189 | .end: |
||
190 | stdcall skip_spaces |
||
191 | ret |
||
4875 | eAndrew | 192 | .unexp_char: |
193 | set_err 4 |
||
4865 | eAndrew | 194 | endp |
195 | |||
196 | ; --------------------------- |
||
197 | |||
4875 | eAndrew | 198 | proc parse_lvl4 uses ebx ecx |
199 | stdcall parse_lvl5 |
||
200 | @@: |
||
201 | mov ebx, exp |
||
202 | add ebx, [exp_pos] |
||
203 | cmp [ebx], byte 0 |
||
204 | je .end |
||
205 | cmp [ebx], byte "^" |
||
206 | jne .end |
||
207 | inc [exp_pos] |
||
208 | mov ecx, eax |
||
209 | mov ebx, exp |
||
210 | add ebx, [exp_pos] |
||
211 | cmp [ebx], byte 48 |
||
212 | jl .unexp_char |
||
213 | cmp [ebx], byte 57 |
||
214 | jg .unexp_char |
||
215 | stdcall parse_lvl4 |
||
216 | stdcall c_power |
||
217 | jmp @b |
||
218 | .end: |
||
219 | ret |
||
220 | .unexp_char: |
||
221 | set_err 4 |
||
222 | endp |
||
223 | |||
224 | ; --------------------------- |
||
225 | |||
226 | proc parse_lvl5 uses ebx ecx |
||
4865 | eAndrew | 227 | sub eax, eax |
228 | sub ecx, ecx |
||
229 | mov ebx, exp |
||
230 | add ebx, [exp_pos] |
||
231 | @@: |
||
232 | cmp [ebx], byte 0 |
||
233 | je @f |
||
234 | cmp [ebx], byte 48 |
||
235 | jl @f |
||
236 | cmp [ebx], byte 57 |
||
237 | jg @f |
||
238 | imul eax, 10 |
||
239 | mov cl, [ebx] |
||
240 | add eax, ecx |
||
241 | sub eax, 48 |
||
242 | inc ebx |
||
243 | inc [exp_pos] |
||
244 | jmp @b |
||
245 | @@: |
||
246 | ret |
||
247 | endp |
||
248 | |||
249 | ; --------------------------- |
||
250 | |||
251 | proc skip_spaces uses ebx |
||
252 | mov ebx, exp |
||
253 | add ebx, [exp_pos] |
||
254 | @@: |
||
255 | cmp [ebx], byte " " |
||
256 | jne @f |
||
257 | inc ebx |
||
258 | inc [exp_pos] |
||
259 | jmp @b |
||
260 | @@: |
||
261 | ret |
||
4875 | eAndrew | 262 | endp |
263 | |||
264 | ; --------------------------- |
||
265 | |||
266 | proc c_power uses ebx |
||
267 | mov ebx, eax |
||
268 | mov eax, 1 |
||
269 | @@: |
||
270 | cmp ebx, 0 |
||
271 | je @f |
||
272 | imul eax, ecx |
||
273 | dec ebx |
||
274 | jmp @b |
||
275 | @@: |
||
276 | ret |
||
277 | endp |
||
278 | |||
279 | ; --------------------------- |
||
280 | |||
281 | proc convert_to_str uses ebx ecx edx esi edi, _num, _str |
||
282 | mov eax, [_num] |
||
283 | mov esi, [_str] |
||
284 | mov edi, 0 |
||
285 | mov ecx, eax |
||
286 | and ecx, 1 shl 31 |
||
287 | cmp ecx, 0 |
||
288 | je @f |
||
289 | mov [esi], byte "-" |
||
290 | inc esi |
||
291 | inc edi |
||
292 | not eax |
||
293 | inc eax |
||
294 | @@: |
||
295 | mov ebx, 10 |
||
296 | xor ecx, ecx |
||
297 | @@: |
||
298 | xor edx, edx |
||
299 | div ebx |
||
300 | push edx |
||
301 | inc ecx |
||
302 | inc edi |
||
303 | cmp eax, 0 |
||
304 | jne @b |
||
305 | @@: |
||
306 | pop eax |
||
307 | add al, "0" |
||
308 | mov [esi], al |
||
309 | inc esi |
||
310 | loop @b |
||
311 | mov [esi], byte 0 |
||
312 | mov eax, edi |
||
313 | ret |
||
4865 | eAndrew | 314 | endp |