Rev 4875 | Go to most recent revision | Details | 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 | proc convert_to_str uses ebx ecx edx esi edi, _num, _str |
||
16 | mov eax, [_num] |
||
17 | mov esi, [_str] |
||
18 | mov edi, 0 |
||
19 | mov ecx, eax |
||
20 | and ecx, 1 shl 31 |
||
21 | cmp ecx, 0 |
||
22 | je @f |
||
23 | mov [esi], byte "-" |
||
24 | inc esi |
||
25 | inc edi |
||
26 | not eax |
||
27 | inc eax |
||
28 | @@: |
||
29 | mov ebx, 10 |
||
30 | xor ecx, ecx |
||
31 | @@: |
||
32 | xor edx, edx |
||
33 | div ebx |
||
34 | push edx |
||
35 | inc ecx |
||
36 | inc edi |
||
37 | cmp eax, 0 |
||
38 | jne @b |
||
39 | @@: |
||
40 | pop eax |
||
41 | add al, "0" |
||
42 | mov [esi], al |
||
43 | inc esi |
||
44 | loop @b |
||
45 | mov [esi], byte 0 |
||
46 | mov eax, edi |
||
47 | ret |
||
48 | endp |
||
49 | |||
50 | ; --------------------------- |
||
51 | |||
52 | proc parse |
||
53 | mov [exp_pos], 0 |
||
54 | mov [error_n], 0 |
||
55 | stdcall parse_lvl0 |
||
56 | ret |
||
57 | endp |
||
58 | |||
59 | ; --------------------------- |
||
60 | |||
61 | proc parse_lvl0 uses ebx ecx |
||
62 | test_err |
||
63 | stdcall parse_lvl1 |
||
64 | test_err |
||
65 | @@: |
||
66 | mov ebx, exp |
||
67 | add ebx, [exp_pos] |
||
68 | cmp [ebx], byte 0 |
||
69 | je .end |
||
70 | cmp [ebx], byte ")" |
||
71 | je .end |
||
72 | inc [exp_pos] |
||
73 | cmp [ebx], byte "+" |
||
74 | jne .not_add |
||
75 | mov ecx, eax |
||
76 | stdcall parse_lvl1 |
||
77 | test_err |
||
78 | add eax, ecx |
||
79 | jmp @b |
||
80 | .not_add: |
||
81 | cmp [ebx], byte "-" |
||
82 | jne @b |
||
83 | mov ecx, eax |
||
84 | stdcall parse_lvl1 |
||
85 | test_err |
||
86 | sub ecx, eax |
||
87 | mov eax, ecx |
||
88 | jmp @b |
||
89 | .end: |
||
90 | ret |
||
91 | endp |
||
92 | |||
93 | ; --------------------------- |
||
94 | |||
95 | proc parse_lvl1 uses ebx ecx edx |
||
96 | test_err |
||
97 | stdcall parse_lvl2 |
||
98 | test_err |
||
99 | @@: |
||
100 | mov ebx, exp |
||
101 | add ebx, [exp_pos] |
||
102 | cmp [ebx], byte 0 |
||
103 | je .end |
||
104 | inc [exp_pos] |
||
105 | cmp [ebx], byte "*" |
||
106 | jne .not_mul |
||
107 | mov ecx, eax |
||
108 | stdcall parse_lvl2 |
||
109 | test_err |
||
110 | imul ecx, eax |
||
111 | mov eax, ecx |
||
112 | jmp @b |
||
113 | .not_mul: |
||
114 | cmp [ebx], byte "/" |
||
115 | je .div_or_mod |
||
116 | cmp [ebx], byte "%" |
||
117 | je .div_or_mod |
||
118 | jmp .end |
||
119 | .div_or_mod: |
||
120 | mov ecx, eax |
||
121 | stdcall parse_lvl2 |
||
122 | test_err |
||
123 | cmp eax, 0 |
||
124 | jne .not_null |
||
125 | set_err 1 |
||
126 | .not_null: |
||
127 | xchg ecx, eax |
||
128 | cdq |
||
129 | div ecx |
||
130 | cmp [ebx], byte "%" |
||
131 | je .mod |
||
132 | jmp @b |
||
133 | .mod: |
||
134 | mov eax, edx |
||
135 | jmp @b |
||
136 | .end: |
||
137 | dec [exp_pos] |
||
138 | ret |
||
139 | endp |
||
140 | |||
141 | ; --------------------------- |
||
142 | |||
143 | proc parse_lvl2 uses ebx |
||
144 | test_err |
||
145 | stdcall skip_spaces |
||
146 | mov ebx, exp |
||
147 | add ebx, [exp_pos] |
||
148 | cmp [ebx], byte 48 |
||
149 | jl @f |
||
150 | cmp [ebx], byte 57 |
||
151 | jg @f |
||
152 | stdcall parse_lvl3 |
||
153 | jmp .end |
||
154 | @@: |
||
155 | inc [exp_pos] |
||
156 | cmp [ebx], byte "(" |
||
157 | jne @f |
||
158 | stdcall parse_lvl0 |
||
159 | test_err |
||
160 | inc [exp_pos] |
||
161 | jmp .end |
||
162 | @@: |
||
163 | cmp [ebx], byte "+" |
||
164 | jne @f |
||
165 | stdcall parse_lvl2 |
||
166 | test_err |
||
167 | jmp .end |
||
168 | @@: |
||
169 | cmp [ebx], byte "-" |
||
170 | jne .end |
||
171 | stdcall parse_lvl2 |
||
172 | test_err |
||
173 | neg eax |
||
174 | .end: |
||
175 | stdcall skip_spaces |
||
176 | ret |
||
177 | endp |
||
178 | |||
179 | ; --------------------------- |
||
180 | |||
181 | proc parse_lvl3 uses ebx ecx |
||
182 | sub eax, eax |
||
183 | sub ecx, ecx |
||
184 | mov ebx, exp |
||
185 | add ebx, [exp_pos] |
||
186 | @@: |
||
187 | cmp [ebx], byte 0 |
||
188 | je @f |
||
189 | cmp [ebx], byte 48 |
||
190 | jl @f |
||
191 | cmp [ebx], byte 57 |
||
192 | jg @f |
||
193 | imul eax, 10 |
||
194 | mov cl, [ebx] |
||
195 | add eax, ecx |
||
196 | sub eax, 48 |
||
197 | inc ebx |
||
198 | inc [exp_pos] |
||
199 | jmp @b |
||
200 | @@: |
||
201 | ret |
||
202 | endp |
||
203 | |||
204 | ; --------------------------- |
||
205 | |||
206 | proc skip_spaces uses ebx |
||
207 | mov ebx, exp |
||
208 | add ebx, [exp_pos] |
||
209 | @@: |
||
210 | cmp [ebx], byte " " |
||
211 | jne @f |
||
212 | inc ebx |
||
213 | inc [exp_pos] |
||
214 | jmp @b |
||
215 | @@: |
||
216 | ret |
||
217 | endp |