Subversion Repositories Kolibri OS

Rev

Rev 242 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 242 Rev 340
1
; flat assembler core
1
; flat assembler core
2
; Copyright (c) 1999-2006, Tomasz Grysztar.
2
; Copyright (c) 1999-2007, Tomasz Grysztar.
3
; All rights reserved.
3
; All rights reserved.
4
 
4
 
5
parser:
5
parser:
6
	mov	eax,[memory_end]
6
	mov	eax,[memory_end]
7
	mov	[labels_list],eax
7
	mov	[labels_list],eax
8
	mov	eax,[additional_memory]
8
	mov	eax,[additional_memory]
9
	mov	[free_additional_memory],eax
9
	mov	[free_additional_memory],eax
10
	xor	eax,eax
10
	xor	eax,eax
11
	mov	[current_locals_prefix],eax
11
	mov	[current_locals_prefix],eax
12
	mov	[anonymous_reverse],eax
12
	mov	[anonymous_reverse],eax
13
	mov	[anonymous_forward],eax
13
	mov	[anonymous_forward],eax
14
	mov	[hash_tree],eax
14
	mov	[hash_tree],eax
15
	mov	[blocks_stack],eax
15
	mov	[blocks_stack],eax
16
	mov	[parsed_lines],eax
16
	mov	[parsed_lines],eax
17
	mov	esi,[memory_start]
17
	mov	esi,[memory_start]
18
	mov	edi,[source_start]
18
	mov	edi,[source_start]
19
      parser_loop:
19
      parser_loop:
20
	mov	[current_line],esi
20
	mov	[current_line],esi
21
	lea	eax,[edi+100h]
21
	lea	eax,[edi+100h]
22
	cmp	eax,[labels_list]
22
	cmp	eax,[labels_list]
23
	jae	out_of_memory
23
	jae	out_of_memory
24
	cmp	byte [esi+16],0
24
	cmp	byte [esi+16],0
25
	je	empty_line
25
	je	empty_line
26
	mov	al,0Fh
26
	mov	al,0Fh
27
	stos	byte [edi]
27
	stos	byte [edi]
28
	mov	eax,esi
28
	mov	eax,esi
29
	stos	dword [edi]
29
	stos	dword [edi]
30
	inc	[parsed_lines]
30
	inc	[parsed_lines]
31
	add	esi,16
31
	add	esi,16
32
      parse_line:
32
      parse_line:
33
	cmp	byte [esi],1Ah
33
	cmp	byte [esi],1Ah
34
	jne	empty_instruction
34
	jne	empty_instruction
35
	push	edi
35
	push	edi
36
	add	esi,2
36
	add	esi,2
37
	movzx	ecx,byte [esi-1]
37
	movzx	ecx,byte [esi-1]
38
	cmp	byte [esi+ecx],':'
38
	cmp	byte [esi+ecx],':'
39
	je	simple_label
39
	je	simple_label
40
	cmp	byte [esi+ecx],'='
40
	cmp	byte [esi+ecx],'='
41
	je	constant_label
41
	je	constant_label
42
	call	get_instruction
42
	call	get_instruction
43
	jnc	main_instruction_identified
43
	jnc	main_instruction_identified
44
	cmp	byte [esi+ecx],1Ah
44
	cmp	byte [esi+ecx],1Ah
45
	jne	no_data_label
45
	jne	no_data_label
46
	push	esi ecx
46
	push	esi ecx
47
	lea	esi,[esi+ecx+2]
47
	lea	esi,[esi+ecx+2]
48
	movzx	ecx,byte [esi-1]
48
	movzx	ecx,byte [esi-1]
49
	call	get_data_directive
49
	call	get_data_directive
50
	jnc	data_label
50
	jnc	data_label
51
	pop	ecx esi
51
	pop	ecx esi
52
      no_data_label:
52
      no_data_label:
53
	call	get_data_directive
53
	call	get_data_directive
54
	jnc	main_instruction_identified
54
	jnc	main_instruction_identified
55
	pop	edi
55
	pop	edi
56
	sub	esi,2
56
	sub	esi,2
57
	xor	bx,bx
57
	xor	bx,bx
58
	call	parse_line_contents
58
	call	parse_line_contents
59
	jmp	parse_next_line
59
	jmp	parse_next_line
60
      simple_label:
60
      simple_label:
61
	pop	edi
61
	pop	edi
62
	call	identify_label
62
	call	identify_label
63
	mov	byte [edi],2
63
	mov	byte [edi],2
64
	inc	edi
64
	inc	edi
65
	stos	dword [edi]
65
	stos	dword [edi]
66
	inc	esi
66
	inc	esi
67
	xor	al,al
67
	xor	al,al
68
	stos	byte [edi]
68
	stos	byte [edi]
69
	jmp	parse_line
69
	jmp	parse_line
70
      constant_label:
70
      constant_label:
71
	pop	edi
71
	pop	edi
72
	call	get_label_id
72
	call	get_label_id
73
	mov	byte [edi],3
73
	mov	byte [edi],3
74
	inc	edi
74
	inc	edi
75
	stos	dword [edi]
75
	stos	dword [edi]
76
	xor	al,al
76
	xor	al,al
77
	stos	byte [edi]
77
	stos	byte [edi]
78
	inc	esi
78
	inc	esi
79
	xor	bx,bx
79
	xor	bx,bx
80
	call	parse_line_contents
80
	call	parse_line_contents
81
	jmp	parse_next_line
81
	jmp	parse_next_line
82
      data_label:
82
      data_label:
83
	pop	ecx edx
83
	pop	ecx edx
84
	pop	edi
84
	pop	edi
85
	push	eax ebx esi
85
	push	eax ebx esi
86
	mov	esi,edx
86
	mov	esi,edx
87
	movzx	ecx,byte [esi-1]
87
	movzx	ecx,byte [esi-1]
88
	call	identify_label
88
	call	identify_label
89
	mov	byte [edi],2
89
	mov	byte [edi],2
90
	inc	edi
90
	inc	edi
91
	stos	dword [edi]
91
	stos	dword [edi]
92
	pop	esi ebx eax
92
	pop	esi ebx eax
93
	stos	byte [edi]
93
	stos	byte [edi]
94
	push	edi
94
	push	edi
95
      main_instruction_identified:
95
      main_instruction_identified:
96
	pop	edi
96
	pop	edi
97
	mov	dl,al
97
	mov	dl,al
98
	mov	al,1
98
	mov	al,1
99
	stos	byte [edi]
99
	stos	byte [edi]
100
	mov	ax,bx
100
	mov	ax,bx
101
	stos	word [edi]
101
	stos	word [edi]
102
	mov	al,dl
102
	mov	al,dl
103
	stos	byte [edi]
103
	stos	byte [edi]
104
	cmp	bx,if_directive-assembler
104
	cmp	bx,if_directive-assembler
105
	je	parse_block
105
	je	parse_block
106
	cmp	bx,repeat_directive-assembler
106
	cmp	bx,repeat_directive-assembler
107
	je	parse_block
107
	je	parse_block
108
	cmp	bx,while_directive-assembler
108
	cmp	bx,while_directive-assembler
109
	je	parse_block
109
	je	parse_block
110
	cmp	bx,end_directive-assembler
110
	cmp	bx,end_directive-assembler
111
	je	parse_end_directive
111
	je	parse_end_directive
112
	cmp	bx,else_directive-assembler
112
	cmp	bx,else_directive-assembler
113
	je	parse_else
113
	je	parse_else
114
      common_parse:
114
      common_parse:
115
	call	parse_line_contents
115
	call	parse_line_contents
116
	jmp	parse_next_line
116
	jmp	parse_next_line
117
      empty_instruction:
117
      empty_instruction:
118
	lods	byte [esi]
118
	lods	byte [esi]
119
	or	al,al
119
	or	al,al
120
	jz	parse_next_line
120
	jz	parse_next_line
121
	cmp	al,':'
121
	cmp	al,':'
122
	je	invalid_name
122
	je	invalid_name
123
	cmp	al,3Bh
123
	cmp	al,3Bh
124
	je	skip_preprocessed_symbol
124
	je	skip_preprocessed_symbol
125
	dec	esi
125
	dec	esi
126
	call	parse_argument
126
	call	parse_argument
127
	jmp	parse_next_line
127
	jmp	parse_next_line
128
      skip_preprocessed_symbol:
128
      skip_preprocessed_symbol:
129
	lods	byte [esi]
129
	lods	byte [esi]
130
	movzx	eax,al
130
	movzx	eax,al
131
	add	esi,eax
131
	add	esi,eax
132
      skip_next:
132
      skip_next:
133
	lods	byte [esi]
133
	lods	byte [esi]
134
	or	al,al
134
	or	al,al
135
	jz	parse_next_line
135
	jz	parse_next_line
136
	cmp	al,1Ah
136
	cmp	al,1Ah
137
	je	skip_preprocessed_symbol
137
	je	skip_preprocessed_symbol
138
	cmp	al,3Bh
138
	cmp	al,3Bh
139
	je	skip_preprocessed_symbol
139
	je	skip_preprocessed_symbol
140
	cmp	al,22h
140
	cmp	al,22h
141
	je	skip_preprocessed_string
141
	je	skip_preprocessed_string
142
	jmp	skip_next
142
	jmp	skip_next
143
      skip_preprocessed_string:
143
      skip_preprocessed_string:
144
	lods	dword [esi]
144
	lods	dword [esi]
145
	add	esi,eax
145
	add	esi,eax
146
	jmp	skip_next
146
	jmp	skip_next
147
      empty_line:
147
      empty_line:
148
	add	esi,17
148
	add	esi,17
149
      parse_next_line:
149
      parse_next_line:
150
	cmp	esi,[source_start]
150
	cmp	esi,[source_start]
151
	jb	parser_loop
151
	jb	parser_loop
152
      source_parsed:
152
      source_parsed:
153
	cmp	[blocks_stack],0
153
	cmp	[blocks_stack],0
154
	je	blocks_stack_ok
154
	je	blocks_stack_ok
155
	pop	eax
155
	pop	eax
156
	pop	[current_line]
156
	pop	[current_line]
157
	jmp	missing_end_directive
157
	jmp	missing_end_directive
158
      blocks_stack_ok:
158
      blocks_stack_ok:
159
	xor	al,al
159
	xor	al,al
160
	stos	byte [edi]
160
	stos	byte [edi]
161
	mov	eax,[error_line]
161
	mov	eax,[error_line]
162
	mov	[current_line],eax
162
	mov	[current_line],eax
163
	cmp	[anonymous_forward],0
163
	cmp	[anonymous_forward],0
164
	jne	invalid_value
164
	jne	invalid_value
165
	add	edi,0Fh
165
	add	edi,0Fh
166
	and	edi,not 0Fh
166
	and	edi,not 0Fh
167
	mov	[code_start],edi
167
	mov	[code_start],edi
168
	ret
168
	ret
169
      parse_block:
169
      parse_block:
170
	mov	eax,esp
170
	mov	eax,esp
171
	sub	eax,100h
171
	sub	eax,100h
172
	jc	stack_overflow
172
	jc	stack_overflow
173
	cmp	eax,[stack_limit]
173
	cmp	eax,[stack_limit]
174
	jb	stack_overflow
174
	jb	stack_overflow
175
	push	[current_line]
175
	push	[current_line]
176
	mov	ax,bx
176
	mov	ax,bx
177
	shl	eax,16
177
	shl	eax,16
178
	push	eax
178
	push	eax
179
	inc	[blocks_stack]
179
	inc	[blocks_stack]
180
	cmp	bx,if_directive-assembler
180
	cmp	bx,if_directive-assembler
181
	je	parse_if
181
	je	parse_if
182
	cmp	bx,while_directive-assembler
182
	cmp	bx,while_directive-assembler
183
	je	parse_while
183
	je	parse_while
184
	call	parse_line_contents
184
	call	parse_line_contents
185
	jmp	parse_next_line
185
	jmp	parse_next_line
186
      parse_end_directive:
186
      parse_end_directive:
187
	cmp	byte [esi],1Ah
187
	cmp	byte [esi],1Ah
188
	jne	common_parse
188
	jne	common_parse
189
	push	edi
189
	push	edi
190
	inc	esi
190
	inc	esi
191
	movzx	ecx,byte [esi]
191
	movzx	ecx,byte [esi]
192
	inc	esi
192
	inc	esi
193
	call	get_instruction
193
	call	get_instruction
194
	pop	edi
194
	pop	edi
195
	jnc	parse_end_block
195
	jnc	parse_end_block
196
	sub	esi,2
196
	sub	esi,2
197
	jmp	common_parse
197
	jmp	common_parse
198
      parse_end_block:
198
      parse_end_block:
199
	mov	dl,al
199
	mov	dl,al
200
	mov	al,1
200
	mov	al,1
201
	stos	byte [edi]
201
	stos	byte [edi]
202
	mov	ax,bx
202
	mov	ax,bx
203
	stos	word [edi]
203
	stos	word [edi]
204
	mov	al,dl
204
	mov	al,dl
205
	stos	byte [edi]
205
	stos	byte [edi]
206
	lods	byte [esi]
206
	lods	byte [esi]
207
	or	al,al
207
	or	al,al
208
	jnz	extra_characters_on_line
208
	jnz	extra_characters_on_line
209
	cmp	bx,if_directive-assembler
209
	cmp	bx,if_directive-assembler
210
	je	close_parsing_block
210
	je	close_parsing_block
211
	cmp	bx,repeat_directive-assembler
211
	cmp	bx,repeat_directive-assembler
212
	je	close_parsing_block
212
	je	close_parsing_block
213
	cmp	bx,while_directive-assembler
213
	cmp	bx,while_directive-assembler
214
	je	close_parsing_block
214
	je	close_parsing_block
215
	jmp	parse_next_line
215
	jmp	parse_next_line
216
      close_parsing_block:
216
      close_parsing_block:
217
	cmp	[blocks_stack],0
217
	cmp	[blocks_stack],0
218
	je	unexpected_instruction
218
	je	unexpected_instruction
219
	cmp	bx,[esp+2]
219
	cmp	bx,[esp+2]
220
	jne	unexpected_instruction
220
	jne	unexpected_instruction
221
	dec	[blocks_stack]
221
	dec	[blocks_stack]
222
	pop	eax edx
222
	pop	eax edx
223
	cmp	bx,if_directive-assembler
223
	cmp	bx,if_directive-assembler
224
	jne	parse_next_line
224
	jne	parse_next_line
225
	test	al,1100b
225
	test	al,1100b
226
	jz	parse_next_line
226
	jz	parse_next_line
227
	test	al,10000b
227
	test	al,10000b
228
	jnz	parse_next_line
228
	jnz	parse_next_line
229
	sub	edi,8
229
	sub	edi,8
230
	jmp	parse_next_line
230
	jmp	parse_next_line
231
      parse_if:
231
      parse_if:
232
	push	edi
232
	push	edi
233
	call	parse_line_contents
233
	call	parse_line_contents
234
	xor	al,al
234
	xor	al,al
235
	stos	byte [edi]
235
	stos	byte [edi]
236
	xchg	esi,[esp]
236
	xchg	esi,[esp]
237
	mov	edi,esi
237
	mov	edi,esi
238
	call	preevaluate_logical_expression
238
	call	preevaluate_logical_expression
239
	pop	esi
239
	pop	esi
240
	cmp	al,'0'
240
	cmp	al,'0'
241
	je	parse_false_condition_block
241
	je	parse_false_condition_block
242
	cmp	al,'1'
242
	cmp	al,'1'
243
	je	parse_true_condition_block
243
	je	parse_true_condition_block
244
	or	byte [esp],10000b
244
	or	byte [esp],10000b
245
	jmp	parse_next_line
245
	jmp	parse_next_line
246
      parse_while:
246
      parse_while:
247
	push	edi
247
	push	edi
248
	call	parse_line_contents
248
	call	parse_line_contents
249
	xor	al,al
249
	xor	al,al
250
	stos	byte [edi]
250
	stos	byte [edi]
251
	xchg	esi,[esp]
251
	xchg	esi,[esp]
252
	mov	edi,esi
252
	mov	edi,esi
253
	call	preevaluate_logical_expression
253
	call	preevaluate_logical_expression
254
	pop	esi
254
	pop	esi
255
	cmp	al,'0'
255
	cmp	al,'0'
256
	je	parse_false_condition_block
256
	je	parse_false_condition_block
257
	cmp	al,'1'
257
	cmp	al,'1'
258
	jne	parse_next_line
258
	jne	parse_next_line
259
	stos	byte [edi]
259
	stos	byte [edi]
260
	jmp	parse_next_line
260
	jmp	parse_next_line
261
      parse_false_condition_block:
261
      parse_false_condition_block:
262
	or	byte [esp],1
262
	or	byte [esp],1
263
	sub	edi,4
263
	sub	edi,4
264
	jmp	skip_parsing
264
	jmp	skip_parsing
265
      parse_true_condition_block:
265
      parse_true_condition_block:
266
	or	byte [esp],100b
266
	or	byte [esp],100b
267
	sub	edi,4
267
	sub	edi,4
268
	jmp	parse_next_line
268
	jmp	parse_next_line
269
      parse_else:
269
      parse_else:
270
	cmp	[blocks_stack],0
270
	cmp	[blocks_stack],0
271
	je	unexpected_instruction
271
	je	unexpected_instruction
272
	cmp	word [esp+2],if_directive-assembler
272
	cmp	word [esp+2],if_directive-assembler
273
	jne	unexpected_instruction
273
	jne	unexpected_instruction
274
	lods	byte [esi]
274
	lods	byte [esi]
275
	or	al,al
275
	or	al,al
276
	jz	parse_pure_else
276
	jz	parse_pure_else
277
	cmp	al,1Ah
277
	cmp	al,1Ah
278
	jne	extra_characters_on_line
278
	jne	extra_characters_on_line
279
	push	edi
279
	push	edi
280
	movzx	ecx,byte [esi]
280
	movzx	ecx,byte [esi]
281
	inc	esi
281
	inc	esi
282
	call	get_instruction
282
	call	get_instruction
283
	jc	extra_characters_on_line
283
	jc	extra_characters_on_line
284
	pop	edi
284
	pop	edi
285
	cmp	bx,if_directive-assembler
285
	cmp	bx,if_directive-assembler
286
	jne	extra_characters_on_line
286
	jne	extra_characters_on_line
287
	test	byte [esp],100b
287
	test	byte [esp],100b
288
	jnz	skip_true_condition_else
288
	jnz	skip_true_condition_else
289
	mov	dl,al
289
	mov	dl,al
290
	mov	al,1
290
	mov	al,1
291
	stos	byte [edi]
291
	stos	byte [edi]
292
	mov	ax,bx
292
	mov	ax,bx
293
	stos	word [edi]
293
	stos	word [edi]
294
	mov	al,dl
294
	mov	al,dl
295
	stos	byte [edi]
295
	stos	byte [edi]
296
	jmp	parse_if
296
	jmp	parse_if
297
      skip_true_condition_else:
297
      skip_true_condition_else:
298
	sub	edi,4
298
	sub	edi,4
299
	or	byte [esp],1
299
	or	byte [esp],1
300
	jmp	skip_parsing_contents
300
	jmp	skip_parsing_contents
301
      parse_pure_else:
301
      parse_pure_else:
302
	bts	dword [esp],1
302
	bts	dword [esp],1
303
	jc	unexpected_instruction
303
	jc	unexpected_instruction
304
	test	byte [esp],100b
304
	test	byte [esp],100b
305
	jz	parse_next_line
305
	jz	parse_next_line
306
	sub	edi,4
306
	sub	edi,4
307
	or	byte [esp],1
307
	or	byte [esp],1
308
	jmp	skip_parsing
308
	jmp	skip_parsing
309
      skip_parsing:
309
      skip_parsing:
310
	cmp	esi,[source_start]
310
	cmp	esi,[source_start]
311
	jae	source_parsed
311
	jae	source_parsed
312
	mov	[current_line],esi
312
	mov	[current_line],esi
313
	add	esi,16
313
	add	esi,16
314
      skip_parsing_line:
314
      skip_parsing_line:
315
	cmp	byte [esi],1Ah
315
	cmp	byte [esi],1Ah
316
	jne	skip_parsing_contents
316
	jne	skip_parsing_contents
317
	inc	esi
317
	inc	esi
318
	movzx	ecx,byte [esi]
318
	movzx	ecx,byte [esi]
319
	inc	esi
319
	inc	esi
320
	cmp	byte [esi+ecx],':'
320
	cmp	byte [esi+ecx],':'
321
	je	skip_parsing_label
321
	je	skip_parsing_label
322
	push	edi
322
	push	edi
323
	call	get_instruction
323
	call	get_instruction
324
	pop	edi
324
	pop	edi
325
	jnc	skip_parsing_instruction
325
	jnc	skip_parsing_instruction
326
	add	esi,ecx
326
	add	esi,ecx
327
	jmp	skip_parsing_contents
327
	jmp	skip_parsing_contents
328
      skip_parsing_label:
328
      skip_parsing_label:
329
	lea	esi,[esi+ecx+1]
329
	lea	esi,[esi+ecx+1]
330
	jmp	skip_parsing_line
330
	jmp	skip_parsing_line
331
      skip_parsing_instruction:
331
      skip_parsing_instruction:
332
	cmp	bx,if_directive-assembler
332
	cmp	bx,if_directive-assembler
333
	je	skip_parsing_block
333
	je	skip_parsing_block
334
	cmp	bx,repeat_directive-assembler
334
	cmp	bx,repeat_directive-assembler
335
	je	skip_parsing_block
335
	je	skip_parsing_block
336
	cmp	bx,while_directive-assembler
336
	cmp	bx,while_directive-assembler
337
	je	skip_parsing_block
337
	je	skip_parsing_block
338
	cmp	bx,end_directive-assembler
338
	cmp	bx,end_directive-assembler
339
	je	skip_parsing_end_directive
339
	je	skip_parsing_end_directive
340
	cmp	bx,else_directive-assembler
340
	cmp	bx,else_directive-assembler
341
	je	skip_parsing_else
341
	je	skip_parsing_else
342
      skip_parsing_contents:
342
      skip_parsing_contents:
343
	lods	byte [esi]
343
	lods	byte [esi]
344
	or	al,al
344
	or	al,al
345
	jz	skip_parsing
345
	jz	skip_parsing
346
	cmp	al,1Ah
346
	cmp	al,1Ah
347
	je	skip_parsing_symbol
347
	je	skip_parsing_symbol
348
	cmp	al,3Bh
348
	cmp	al,3Bh
349
	je	skip_parsing_symbol
349
	je	skip_parsing_symbol
350
	cmp	al,22h
350
	cmp	al,22h
351
	je	skip_parsing_string
351
	je	skip_parsing_string
352
	jmp	skip_parsing_contents
352
	jmp	skip_parsing_contents
353
      skip_parsing_symbol:
353
      skip_parsing_symbol:
354
	lods	byte [esi]
354
	lods	byte [esi]
355
	movzx	eax,al
355
	movzx	eax,al
356
	add	esi,eax
356
	add	esi,eax
357
	jmp	skip_parsing_contents
357
	jmp	skip_parsing_contents
358
      skip_parsing_string:
358
      skip_parsing_string:
359
	lods	dword [esi]
359
	lods	dword [esi]
360
	add	esi,eax
360
	add	esi,eax
361
	jmp	skip_parsing_contents
361
	jmp	skip_parsing_contents
362
      skip_parsing_block:
362
      skip_parsing_block:
363
	mov	eax,esp
363
	mov	eax,esp
364
	sub	eax,100h
364
	sub	eax,100h
365
	jc	stack_overflow
365
	jc	stack_overflow
366
	cmp	eax,[stack_limit]
366
	cmp	eax,[stack_limit]
367
	jb	stack_overflow
367
	jb	stack_overflow
368
	push	[current_line]
368
	push	[current_line]
369
	mov	ax,bx
369
	mov	ax,bx
370
	shl	eax,16
370
	shl	eax,16
371
	push	eax
371
	push	eax
372
	inc	[blocks_stack]
372
	inc	[blocks_stack]
373
	jmp	skip_parsing_contents
373
	jmp	skip_parsing_contents
374
      skip_parsing_end_directive:
374
      skip_parsing_end_directive:
375
	cmp	byte [esi],1Ah
375
	cmp	byte [esi],1Ah
376
	jne	skip_parsing_contents
376
	jne	skip_parsing_contents
377
	push	edi
377
	push	edi
378
	inc	esi
378
	inc	esi
379
	movzx	ecx,byte [esi]
379
	movzx	ecx,byte [esi]
380
	inc	esi
380
	inc	esi
381
	call	get_instruction
381
	call	get_instruction
382
	pop	edi
382
	pop	edi
383
	jnc	skip_parsing_end_block
383
	jnc	skip_parsing_end_block
384
	add	esi,ecx
384
	add	esi,ecx
385
	jmp	skip_parsing_contents
385
	jmp	skip_parsing_contents
386
      skip_parsing_end_block:
386
      skip_parsing_end_block:
387
	lods	byte [esi]
387
	lods	byte [esi]
388
	or	al,al
388
	or	al,al
389
	jnz	extra_characters_on_line
389
	jnz	extra_characters_on_line
390
	cmp	bx,if_directive-assembler
390
	cmp	bx,if_directive-assembler
391
	je	close_skip_parsing_block
391
	je	close_skip_parsing_block
392
	cmp	bx,repeat_directive-assembler
392
	cmp	bx,repeat_directive-assembler
393
	je	close_skip_parsing_block
393
	je	close_skip_parsing_block
394
	cmp	bx,while_directive-assembler
394
	cmp	bx,while_directive-assembler
395
	je	close_skip_parsing_block
395
	je	close_skip_parsing_block
396
	jmp	skip_parsing
396
	jmp	skip_parsing
397
      close_skip_parsing_block:
397
      close_skip_parsing_block:
398
	cmp	[blocks_stack],0
398
	cmp	[blocks_stack],0
399
	je	unexpected_instruction
399
	je	unexpected_instruction
400
	cmp	bx,[esp+2]
400
	cmp	bx,[esp+2]
401
	jne	unexpected_instruction
401
	jne	unexpected_instruction
402
	dec	[blocks_stack]
402
	dec	[blocks_stack]
403
	pop	eax edx
403
	pop	eax edx
404
	test	al,1
404
	test	al,1
405
	jz	skip_parsing
405
	jz	skip_parsing
406
	cmp	bx,if_directive-assembler
406
	cmp	bx,if_directive-assembler
407
	jne	parse_next_line
407
	jne	parse_next_line
408
	test	al,10000b
408
	test	al,10000b
409
	jz	parse_next_line
409
	jz	parse_next_line
410
	mov	al,0Fh
410
	mov	al,0Fh
411
	stos	byte [edi]
411
	stos	byte [edi]
412
	mov	eax,[current_line]
412
	mov	eax,[current_line]
413
	stos	dword [edi]
413
	stos	dword [edi]
414
	inc	[parsed_lines]
414
	inc	[parsed_lines]
415
	mov	eax,1 + (end_directive-assembler) shl 8
415
	mov	eax,1 + (end_directive-assembler) shl 8
416
	stos	dword [edi]
416
	stos	dword [edi]
417
	mov	eax,1 + (if_directive-assembler) shl 8
417
	mov	eax,1 + (if_directive-assembler) shl 8
418
	stos	dword [edi]
418
	stos	dword [edi]
419
	jmp	parse_next_line
419
	jmp	parse_next_line
420
      skip_parsing_else:
420
      skip_parsing_else:
421
	cmp	[blocks_stack],0
421
	cmp	[blocks_stack],0
422
	je	unexpected_instruction
422
	je	unexpected_instruction
423
	cmp	word [esp+2],if_directive-assembler
423
	cmp	word [esp+2],if_directive-assembler
424
	jne	unexpected_instruction
424
	jne	unexpected_instruction
425
	lods	byte [esi]
425
	lods	byte [esi]
426
	or	al,al
426
	or	al,al
427
	jz	skip_parsing_pure_else
427
	jz	skip_parsing_pure_else
428
	cmp	al,1Ah
428
	cmp	al,1Ah
429
	jne	extra_characters_on_line
429
	jne	extra_characters_on_line
430
	push	edi
430
	push	edi
431
	movzx	ecx,byte [esi]
431
	movzx	ecx,byte [esi]
432
	inc	esi
432
	inc	esi
433
	call	get_instruction
433
	call	get_instruction
434
	jc	extra_characters_on_line
434
	jc	extra_characters_on_line
435
	pop	edi
435
	pop	edi
436
	cmp	bx,if_directive-assembler
436
	cmp	bx,if_directive-assembler
437
	jne	extra_characters_on_line
437
	jne	extra_characters_on_line
438
	mov	al,[esp]
438
	mov	al,[esp]
439
	test	al,1
439
	test	al,1
440
	jz	skip_parsing_contents
440
	jz	skip_parsing_contents
441
	test	al,100b
441
	test	al,100b
442
	jnz	skip_parsing_contents
442
	jnz	skip_parsing_contents
443
	test	al,10000b
443
	test	al,10000b
444
	jnz	parse_else_if
444
	jnz	parse_else_if
445
	xor	al,al
445
	xor	al,al
446
	mov	[esp],al
446
	mov	[esp],al
447
	mov	al,0Fh
447
	mov	al,0Fh
448
	stos	byte [edi]
448
	stos	byte [edi]
449
	mov	eax,[current_line]
449
	mov	eax,[current_line]
450
	stos	dword [edi]
450
	stos	dword [edi]
451
	inc	[parsed_lines]
451
	inc	[parsed_lines]
452
      parse_else_if:
452
      parse_else_if:
453
	mov	eax,1 + (if_directive-assembler) shl 8
453
	mov	eax,1 + (if_directive-assembler) shl 8
454
	stos	dword [edi]
454
	stos	dword [edi]
455
	jmp	parse_if
455
	jmp	parse_if
456
      skip_parsing_pure_else:
456
      skip_parsing_pure_else:
457
	bts	dword [esp],1
457
	bts	dword [esp],1
458
	jc	unexpected_instruction
458
	jc	unexpected_instruction
459
	mov	al,[esp]
459
	mov	al,[esp]
460
	test	al,1
460
	test	al,1
461
	jz	skip_parsing
461
	jz	skip_parsing
462
	test	al,100b
462
	test	al,100b
463
	jnz	skip_parsing
463
	jnz	skip_parsing
464
	and	al,not 1
464
	and	al,not 1
465
	or	al,1000b
465
	or	al,1000b
466
	mov	[esp],al
466
	mov	[esp],al
467
	jmp	parse_next_line
467
	jmp	parse_next_line
468
 
468
 
469
parse_line_contents:
469
parse_line_contents:
470
	mov	[parenthesis_stack],0
470
	mov	[parenthesis_stack],0
471
      parse_instruction_arguments:
471
      parse_instruction_arguments:
472
	cmp	bx,prefix_instruction-assembler
472
	cmp	bx,prefix_instruction-assembler
473
	je	allow_embedded_instruction
473
	je	allow_embedded_instruction
474
	cmp	bx,times_directive-assembler
474
	cmp	bx,times_directive-assembler
475
	je	parse_times_directive
475
	je	parse_times_directive
476
	cmp	bx,end_directive-assembler
476
	cmp	bx,end_directive-assembler
477
	je	allow_embedded_instruction
477
	je	allow_embedded_instruction
478
	cmp	bx,label_directive-assembler
478
	cmp	bx,label_directive-assembler
479
	je	parse_label_directive
479
	je	parse_label_directive
480
	cmp	bx,segment_directive-assembler
480
	cmp	bx,segment_directive-assembler
481
	je	parse_label_directive
481
	je	parse_label_directive
482
	cmp	bx,load_directive-assembler
482
	cmp	bx,load_directive-assembler
483
	je	parse_load_directive
483
	je	parse_load_directive
484
	cmp	bx,extrn_directive-assembler
484
	cmp	bx,extrn_directive-assembler
485
	je	parse_extrn_directive
485
	je	parse_extrn_directive
486
	cmp	bx,public_directive-assembler
486
	cmp	bx,public_directive-assembler
487
	je	parse_public_directive
487
	je	parse_public_directive
488
      parse_argument:
488
      parse_argument:
489
	lea	eax,[edi+100h]
489
	lea	eax,[edi+100h]
490
	cmp	eax,[labels_list]
490
	cmp	eax,[labels_list]
491
	jae	out_of_memory
491
	jae	out_of_memory
492
	lods	byte [esi]
492
	lods	byte [esi]
493
	cmp	al,':'
493
	cmp	al,':'
494
	je	instruction_separator
494
	je	instruction_separator
495
	cmp	al,','
495
	cmp	al,','
496
	je	separator
496
	je	separator
497
	cmp	al,'='
497
	cmp	al,'='
498
	je	separator
498
	je	separator
499
	cmp	al,'|'
499
	cmp	al,'|'
500
	je	separator
500
	je	separator
501
	cmp	al,'&'
501
	cmp	al,'&'
502
	je	separator
502
	je	separator
503
	cmp	al,'~'
503
	cmp	al,'~'
504
	je	separator
504
	je	separator
505
	cmp	al,'>'
505
	cmp	al,'>'
506
	je	greater
506
	je	greater
507
	cmp	al,'<'
507
	cmp	al,'<'
508
	je	less
508
	je	less
509
	cmp	al,')'
509
	cmp	al,')'
510
	je	close_parenthesis
510
	je	close_parenthesis
511
	or	al,al
511
	or	al,al
512
	jz	contents_parsed
512
	jz	contents_parsed
513
	cmp	al,'['
513
	cmp	al,'['
514
	je	address_argument
514
	je	address_argument
515
	cmp	al,']'
515
	cmp	al,']'
516
	je	separator
516
	je	separator
517
	cmp	al,'{'
517
	cmp	al,'{'
518
	je	unallowed_character
518
	je	unallowed_character
519
	cmp	al,'}'
519
	cmp	al,'}'
520
	je	unallowed_character
520
	je	unallowed_character
521
	cmp	al,'#'
521
	cmp	al,'#'
522
	je	unallowed_character
522
	je	unallowed_character
523
	cmp	al,'`'
523
	cmp	al,'`'
524
	je	unallowed_character
524
	je	unallowed_character
525
	dec	esi
525
	dec	esi
526
	cmp	al,1Ah
526
	cmp	al,1Ah
527
	jne	expression_argument
527
	jne	expression_argument
528
	push	edi
528
	push	edi
529
	mov	edi,directive_operators
529
	mov	edi,directive_operators
530
	call	get_operator
530
	call	get_operator
531
	or	al,al
531
	or	al,al
532
	jnz	operator_argument
532
	jnz	operator_argument
533
	inc	esi
533
	inc	esi
534
	movzx	ecx,byte [esi]
534
	movzx	ecx,byte [esi]
535
	inc	esi
535
	inc	esi
536
	call	get_symbol
536
	call	get_symbol
537
	jnc	symbol_argument
537
	jnc	symbol_argument
538
	cmp	ecx,1
538
	cmp	ecx,1
539
	jne	check_argument
539
	jne	check_argument
540
	cmp	byte [esi],'?'
540
	cmp	byte [esi],'?'
541
	jne	check_argument
541
	jne	check_argument
542
	pop	edi
542
	pop	edi
543
	movs	byte [edi],[esi]
543
	movs	byte [edi],[esi]
544
	jmp	argument_parsed
544
	jmp	argument_parsed
545
      symbol_argument:
545
      symbol_argument:
546
	pop	edi
546
	pop	edi
547
	stos	word [edi]
547
	stos	word [edi]
548
	jmp	argument_parsed
548
	jmp	argument_parsed
549
      operator_argument:
549
      operator_argument:
550
	pop	edi
550
	pop	edi
551
	cmp	al,85h
551
	cmp	al,85h
552
	je	ptr_argument
552
	je	ptr_argument
553
	stos	byte [edi]
553
	stos	byte [edi]
554
	cmp	al,80h
554
	cmp	al,80h
555
	je	forced_expression
555
	je	forced_expression
556
	cmp	al,81h
556
	cmp	al,81h
557
	je	forced_parenthesis
557
	je	forced_parenthesis
558
	cmp	al,82h
558
	cmp	al,82h
559
	je	parse_from_operator
559
	je	parse_from_operator
560
	cmp	al,89h
560
	cmp	al,89h
561
	je	parse_label_operator
561
	je	parse_label_operator
562
	jmp	argument_parsed
562
	jmp	argument_parsed
563
      allow_embedded_instruction:
563
      allow_embedded_instruction:
564
	cmp	byte [esi],1Ah
564
	cmp	byte [esi],1Ah
565
	jne	parse_argument
565
	jne	parse_argument
566
	push	edi
566
	push	edi
567
	inc	esi
567
	inc	esi
568
	movzx	ecx,byte [esi]
568
	movzx	ecx,byte [esi]
569
	inc	esi
569
	inc	esi
570
	call	get_instruction
570
	call	get_instruction
571
	jnc	embedded_instruction
571
	jnc	embedded_instruction
572
	call	get_data_directive
572
	call	get_data_directive
573
	jnc	embedded_instruction
573
	jnc	embedded_instruction
574
	pop	edi
574
	pop	edi
575
	sub	esi,2
575
	sub	esi,2
576
	jmp	parse_argument
576
	jmp	parse_argument
577
      embedded_instruction:
577
      embedded_instruction:
578
	pop	edi
578
	pop	edi
579
	mov	dl,al
579
	mov	dl,al
580
	mov	al,1
580
	mov	al,1
581
	stos	byte [edi]
581
	stos	byte [edi]
582
	mov	ax,bx
582
	mov	ax,bx
583
	stos	word [edi]
583
	stos	word [edi]
584
	mov	al,dl
584
	mov	al,dl
585
	stos	byte [edi]
585
	stos	byte [edi]
586
	jmp	parse_instruction_arguments
586
	jmp	parse_instruction_arguments
587
      parse_times_directive:
587
      parse_times_directive:
588
	mov	al,'('
588
	mov	al,'('
589
	stos	byte [edi]
589
	stos	byte [edi]
590
	call	convert_expression
590
	call	convert_expression
591
	mov	al,')'
591
	mov	al,')'
592
	stos	byte [edi]
592
	stos	byte [edi]
593
	cmp	byte [esi],':'
593
	cmp	byte [esi],':'
594
	jne	allow_embedded_instruction
594
	jne	allow_embedded_instruction
595
	movs	byte [edi],[esi]
595
	movs	byte [edi],[esi]
596
	jmp	allow_embedded_instruction
596
	jmp	allow_embedded_instruction
597
      parse_label_directive:
597
      parse_label_directive:
598
	cmp	byte [esi],1Ah
598
	cmp	byte [esi],1Ah
599
	jne	argument_parsed
599
	jne	argument_parsed
600
	push	esi
600
	push	esi
601
	inc	esi
601
	inc	esi
602
	movzx	ecx,byte [esi]
602
	movzx	ecx,byte [esi]
603
	inc	esi
603
	inc	esi
604
	call	identify_label
604
	call	identify_label
605
	pop	ebx
605
	pop	ebx
606
	cmp	eax,0Fh
606
	cmp	eax,0Fh
607
	je	non_label_identified
607
	je	non_label_identified
608
	mov	byte [edi],2
608
	mov	byte [edi],2
609
	inc	edi
609
	inc	edi
610
	stos	dword [edi]
610
	stos	dword [edi]
611
	xor	al,al
611
	xor	al,al
612
	stos	byte [edi]
612
	stos	byte [edi]
613
	jmp	argument_parsed
613
	jmp	argument_parsed
614
      non_label_identified:
614
      non_label_identified:
615
	mov	esi,ebx
615
	mov	esi,ebx
616
	jmp	argument_parsed
616
	jmp	argument_parsed
617
      parse_load_directive:
617
      parse_load_directive:
618
	cmp	byte [esi],1Ah
618
	cmp	byte [esi],1Ah
619
	jne	argument_parsed
619
	jne	argument_parsed
620
	push	esi
620
	push	esi
621
	inc	esi
621
	inc	esi
622
	movzx	ecx,byte [esi]
622
	movzx	ecx,byte [esi]
623
	inc	esi
623
	inc	esi
624
	call	get_label_id
624
	call	get_label_id
625
	pop	ebx
625
	pop	ebx
626
	cmp	eax,0Fh
626
	cmp	eax,0Fh
627
	je	non_label_identified
627
	je	non_label_identified
628
	mov	byte [edi],2
628
	mov	byte [edi],2
629
	inc	edi
629
	inc	edi
630
	stos	dword [edi]
630
	stos	dword [edi]
631
	xor	al,al
631
	xor	al,al
632
	stos	byte [edi]
632
	stos	byte [edi]
633
	jmp	argument_parsed
633
	jmp	argument_parsed
634
      parse_public_directive:
634
      parse_public_directive:
635
	cmp	byte [esi],1Ah
635
	cmp	byte [esi],1Ah
636
	jne	parse_argument
636
	jne	parse_argument
637
	inc	esi
637
	inc	esi
638
	push	esi
638
	push	esi
639
	movzx	ecx,byte [esi]
639
	movzx	ecx,byte [esi]
640
	inc	esi
640
	inc	esi
641
	mov	al,2
641
	mov	al,2
642
	stos	byte [edi]
642
	stos	byte [edi]
643
	call	get_label_id
643
	call	get_label_id
644
	stos	dword [edi]
644
	stos	dword [edi]
645
	mov	ax,8600h
645
	mov	ax,8600h
646
	stos	word [edi]
646
	stos	word [edi]
647
	pop	ebx
647
	pop	ebx
648
	push	ebx esi edi
648
	push	ebx esi edi
649
	mov	edi,directive_operators
649
	mov	edi,directive_operators
650
	call	get_operator
650
	call	get_operator
651
	pop	edi edx ebx
651
	pop	edi edx ebx
652
	cmp	al,86h
652
	cmp	al,86h
653
	je	argument_parsed
653
	je	argument_parsed
654
	mov	esi,edx
654
	mov	esi,edx
655
	xchg	esi,ebx
655
	xchg	esi,ebx
656
	movzx	ecx,byte [esi]
656
	movzx	ecx,byte [esi]
657
	inc	esi
657
	inc	esi
658
	mov	ax,'('
658
	mov	ax,'('
659
	stos	word [edi]
659
	stos	word [edi]
660
	mov	eax,ecx
660
	mov	eax,ecx
661
	stos	dword [edi]
661
	stos	dword [edi]
662
	rep	movs byte [edi],[esi]
662
	rep	movs byte [edi],[esi]
663
	xor	al,al
663
	xor	al,al
664
	stos	byte [edi]
664
	stos	byte [edi]
665
	xchg	esi,ebx
665
	xchg	esi,ebx
666
	jmp	argument_parsed
666
	jmp	argument_parsed
667
      parse_extrn_directive:
667
      parse_extrn_directive:
668
	cmp	byte [esi],22h
668
	cmp	byte [esi],22h
669
	je	parse_quoted_extrn
669
	je	parse_quoted_extrn
670
	cmp	byte [esi],1Ah
670
	cmp	byte [esi],1Ah
671
	jne	parse_argument
671
	jne	parse_argument
672
	push	esi
672
	push	esi
673
	movzx	ecx,byte [esi+1]
673
	movzx	ecx,byte [esi+1]
674
	add	esi,2
674
	add	esi,2
675
	mov	ax,'('
675
	mov	ax,'('
676
	stos	word [edi]
676
	stos	word [edi]
677
	mov	eax,ecx
677
	mov	eax,ecx
678
	stos	dword [edi]
678
	stos	dword [edi]
679
	rep	movs byte [edi],[esi]
679
	rep	movs byte [edi],[esi]
680
	mov	ax,8600h
680
	mov	ax,8600h
681
	stos	word [edi]
681
	stos	word [edi]
682
	pop	esi
682
	pop	esi
683
      parse_label_operator:
683
      parse_label_operator:
684
	cmp	byte [esi],1Ah
684
	cmp	byte [esi],1Ah
685
	jne	argument_parsed
685
	jne	argument_parsed
686
	inc	esi
686
	inc	esi
687
	movzx	ecx,byte [esi]
687
	movzx	ecx,byte [esi]
688
	inc	esi
688
	inc	esi
689
	mov	al,2
689
	mov	al,2
690
	stos	byte [edi]
690
	stos	byte [edi]
691
	call	get_label_id
691
	call	get_label_id
692
	stos	dword [edi]
692
	stos	dword [edi]
693
	xor	al,al
693
	xor	al,al
694
	stos	byte [edi]
694
	stos	byte [edi]
695
	jmp	argument_parsed
695
	jmp	argument_parsed
696
      parse_from_operator:
696
      parse_from_operator:
697
	cmp	byte [esi],22h
697
	cmp	byte [esi],22h
698
	jne	forced_expression
698
	jne	forced_expression
699
	jmp	argument_parsed
699
	jmp	argument_parsed
700
      parse_quoted_extrn:
700
      parse_quoted_extrn:
701
	inc	esi
701
	inc	esi
702
	mov	ax,'('
702
	mov	ax,'('
703
	stos	word [edi]
703
	stos	word [edi]
704
	lods	dword [esi]
704
	lods	dword [esi]
705
	mov	ecx,eax
705
	mov	ecx,eax
706
	stos	dword [edi]
706
	stos	dword [edi]
707
	rep	movs byte [edi],[esi]
707
	rep	movs byte [edi],[esi]
708
	xor	al,al
708
	xor	al,al
709
	stos	byte [edi]
709
	stos	byte [edi]
710
	push	esi edi
710
	push	esi edi
711
	mov	edi,directive_operators
711
	mov	edi,directive_operators
712
	call	get_operator
712
	call	get_operator
713
	mov	edx,esi
713
	mov	edx,esi
714
	pop	edi esi
714
	pop	edi esi
715
	cmp	al,86h
715
	cmp	al,86h
716
	jne	argument_parsed
716
	jne	argument_parsed
717
	stos	byte [edi]
717
	stos	byte [edi]
718
	mov	esi,edx
718
	mov	esi,edx
719
	jmp	parse_label_operator
719
	jmp	parse_label_operator
720
      ptr_argument:
720
      ptr_argument:
721
	call	parse_address
721
	call	parse_address
722
	jmp	address_parsed
722
	jmp	address_parsed
723
      check_argument:
723
      check_argument:
724
	push	esi ecx
724
	push	esi ecx
725
	sub	esi,2
725
	sub	esi,2
726
	mov	edi,single_operand_operators
726
	mov	edi,single_operand_operators
727
	call	get_operator
727
	call	get_operator
728
	pop	ecx esi
728
	pop	ecx esi
729
	or	al,al
729
	or	al,al
730
	jnz	not_instruction
730
	jnz	not_instruction
731
	call	get_instruction
731
	call	get_instruction
732
	jnc	embedded_instruction
732
	jnc	embedded_instruction
733
	call	get_data_directive
733
	call	get_data_directive
734
	jnc	embedded_instruction
734
	jnc	embedded_instruction
735
      not_instruction:
735
      not_instruction:
736
	pop	edi
736
	pop	edi
737
	sub	esi,2
737
	sub	esi,2
738
      expression_argument:
738
      expression_argument:
739
	cmp	byte [esi],22h
739
	cmp	byte [esi],22h
740
	jne	not_string
740
	jne	not_string
741
	mov	eax,[esi+1]
741
	mov	eax,[esi+1]
742
	lea	ebx,[esi+5+eax]
742
	lea	ebx,[esi+5+eax]
743
	push	ebx ecx esi edi
743
	push	ebx ecx esi edi
744
	mov	al,'('
744
	mov	al,'('
745
	stos	byte [edi]
745
	stos	byte [edi]
746
	call	convert_expression
746
	call	convert_expression
747
	mov	al,')'
747
	mov	al,')'
748
	stos	byte [edi]
748
	stos	byte [edi]
749
	pop	eax edx ecx ebx
749
	pop	eax edx ecx ebx
750
	cmp	esi,ebx
750
	cmp	esi,ebx
751
	jne	expression_parsed
751
	jne	expression_parsed
752
	mov	edi,eax
752
	mov	edi,eax
753
	mov	esi,edx
753
	mov	esi,edx
754
      string_argument:
754
      string_argument:
755
	inc	esi
755
	inc	esi
756
	mov	ax,'('
756
	mov	ax,'('
757
	stos	word [edi]
757
	stos	word [edi]
758
	lods	dword [esi]
758
	lods	dword [esi]
759
	mov	ecx,eax
759
	mov	ecx,eax
760
	stos	dword [edi]
760
	stos	dword [edi]
761
	shr	ecx,1
761
	shr	ecx,1
762
	jnc	string_movsb_ok
762
	jnc	string_movsb_ok
763
	movs	byte [edi],[esi]
763
	movs	byte [edi],[esi]
764
      string_movsb_ok:
764
      string_movsb_ok:
765
	shr	ecx,1
765
	shr	ecx,1
766
	jnc	string_movsw_ok
766
	jnc	string_movsw_ok
767
	movs	word [edi],[esi]
767
	movs	word [edi],[esi]
768
      string_movsw_ok:
768
      string_movsw_ok:
769
	rep	movs dword [edi],[esi]
769
	rep	movs dword [edi],[esi]
770
	xor	al,al
770
	xor	al,al
771
	stos	byte [edi]
771
	stos	byte [edi]
772
	jmp	expression_parsed
772
	jmp	expression_parsed
773
      not_string:
773
      not_string:
774
	cmp	byte [esi],'('
774
	cmp	byte [esi],'('
775
	jne	expression
775
	jne	expression
776
	mov	eax,esp
776
	mov	eax,esp
777
	sub	eax,100h
777
	sub	eax,100h
778
	jc	stack_overflow
778
	jc	stack_overflow
779
	cmp	eax,[stack_limit]
779
	cmp	eax,[stack_limit]
780
	jb	stack_overflow
780
	jb	stack_overflow
781
	push	esi edi
781
	push	esi edi
782
	inc	esi
782
	inc	esi
783
	mov	al,'{'
783
	mov	al,'{'
784
	stos	byte [edi]
784
	stos	byte [edi]
785
	inc	[parenthesis_stack]
785
	inc	[parenthesis_stack]
786
	jmp	parse_argument
786
	jmp	parse_argument
787
      expression:
787
      expression:
788
	mov	al,'('
788
	mov	al,'('
789
	stos	byte [edi]
789
	stos	byte [edi]
790
	call	convert_expression
790
	call	convert_expression
791
	mov	al,')'
791
	mov	al,')'
792
	stos	byte [edi]
792
	stos	byte [edi]
793
	jmp	expression_parsed
793
	jmp	expression_parsed
794
      forced_expression:
794
      forced_expression:
795
	mov	al,'('
795
	mov	al,'('
796
	stos	byte [edi]
796
	stos	byte [edi]
797
	call	convert_expression
797
	call	convert_expression
798
	mov	al,')'
798
	mov	al,')'
799
	stos	byte [edi]
799
	stos	byte [edi]
800
	jmp	argument_parsed
800
	jmp	argument_parsed
801
      address_argument:
801
      address_argument:
802
	call	parse_address
802
	call	parse_address
803
	lods	byte [esi]
803
	lods	byte [esi]
804
	cmp	al,']'
804
	cmp	al,']'
805
	je	address_parsed
805
	je	address_parsed
806
	dec	esi
806
	dec	esi
807
	mov	al,')'
807
	mov	al,')'
808
	stos	byte [edi]
808
	stos	byte [edi]
809
	jmp	argument_parsed
809
	jmp	argument_parsed
810
      address_parsed:
810
      address_parsed:
811
	mov	al,']'
811
	mov	al,']'
812
	stos	byte [edi]
812
	stos	byte [edi]
813
	jmp	argument_parsed
813
	jmp	argument_parsed
814
      parse_address:
814
      parse_address:
815
	mov	al,'['
815
	mov	al,'['
816
	stos	byte [edi]
816
	stos	byte [edi]
817
	cmp	word [esi],021Ah
817
	cmp	word [esi],021Ah
818
	jne	convert_address
818
	jne	convert_address
819
	push	esi
819
	push	esi
820
	add	esi,4
820
	add	esi,4
821
	lea	ebx,[esi+1]
821
	lea	ebx,[esi+1]
822
	cmp	byte [esi],':'
822
	cmp	byte [esi],':'
823
	pop	esi
823
	pop	esi
824
	jne	convert_address
824
	jne	convert_address
825
	add	esi,2
825
	add	esi,2
826
	mov	ecx,2
826
	mov	ecx,2
827
	push	ebx edi
827
	push	ebx edi
828
	call	get_symbol
828
	call	get_symbol
829
	pop	edi esi
829
	pop	edi esi
830
	jc	unknown_segment_prefix
830
	jc	unknown_segment_prefix
831
	cmp	al,10h
831
	cmp	al,10h
832
	jne	unknown_segment_prefix
832
	jne	unknown_segment_prefix
833
	mov	al,ah
833
	mov	al,ah
834
	and	ah,11110000b
834
	and	ah,11110000b
835
	cmp	ah,60h
835
	cmp	ah,60h
836
	jne	unknown_segment_prefix
836
	jne	unknown_segment_prefix
837
	stos	byte [edi]
837
	stos	byte [edi]
838
	jmp	convert_address
838
	jmp	convert_address
839
      unknown_segment_prefix:
839
      unknown_segment_prefix:
840
	sub	esi,5
840
	sub	esi,5
841
      convert_address:
841
      convert_address:
842
	push	edi
842
	push	edi
843
	mov	edi,address_sizes
843
	mov	edi,address_sizes
844
	call	get_operator
844
	call	get_operator
845
	pop	edi
845
	pop	edi
846
	or	al,al
846
	or	al,al
847
	jz	convert_expression
847
	jz	convert_expression
848
	add	al,70h
848
	add	al,70h
849
	stos	byte [edi]
849
	stos	byte [edi]
850
	jmp	convert_expression
850
	jmp	convert_expression
851
      forced_parenthesis:
851
      forced_parenthesis:
852
	cmp	byte [esi],'('
852
	cmp	byte [esi],'('
853
	jne	argument_parsed
853
	jne	argument_parsed
854
	inc	esi
854
	inc	esi
855
	mov	al,'{'
855
	mov	al,'{'
856
	jmp	separator
856
	jmp	separator
857
      unallowed_character:
857
      unallowed_character:
858
	mov	al,0FFh
858
	mov	al,0FFh
859
	jmp	separator
859
	jmp	separator
860
      close_parenthesis:
860
      close_parenthesis:
861
	mov	al,'}'
861
	mov	al,'}'
862
      separator:
862
      separator:
863
	stos	byte [edi]
863
	stos	byte [edi]
864
	jmp	argument_parsed
864
	jmp	argument_parsed
865
      instruction_separator:
865
      instruction_separator:
866
	stos	byte [edi]
866
	stos	byte [edi]
867
	jmp	allow_embedded_instruction
867
	jmp	allow_embedded_instruction
868
      greater:
868
      greater:
869
	cmp	byte [esi],'='
869
	cmp	byte [esi],'='
870
	jne	separator
870
	jne	separator
871
	inc	esi
871
	inc	esi
872
	mov	al,0F2h
872
	mov	al,0F2h
873
	jmp	separator
873
	jmp	separator
874
      less:
874
      less:
875
	cmp	byte [edi-1],0F6h
875
	cmp	byte [edi-1],0F6h
876
	je	separator
876
	je	separator
877
	cmp	byte [esi],'>'
877
	cmp	byte [esi],'>'
878
	je	not_equal
878
	je	not_equal
879
	cmp	byte [esi],'='
879
	cmp	byte [esi],'='
880
	jne	separator
880
	jne	separator
881
	inc	esi
881
	inc	esi
882
	mov	al,0F3h
882
	mov	al,0F3h
883
	jmp	separator
883
	jmp	separator
884
      not_equal:
884
      not_equal:
885
	inc	esi
885
	inc	esi
886
	mov	al,0F1h
886
	mov	al,0F1h
887
	jmp	separator
887
	jmp	separator
888
      argument_parsed:
888
      argument_parsed:
889
	cmp	[parenthesis_stack],0
889
	cmp	[parenthesis_stack],0
890
	je	parse_argument
890
	je	parse_argument
891
	dec	[parenthesis_stack]
891
	dec	[parenthesis_stack]
892
	add	esp,8
892
	add	esp,8
893
	jmp	argument_parsed
893
	jmp	argument_parsed
894
      expression_parsed:
894
      expression_parsed:
895
	cmp	[parenthesis_stack],0
895
	cmp	[parenthesis_stack],0
896
	je	parse_argument
896
	je	parse_argument
897
	cmp	byte [esi],')'
897
	cmp	byte [esi],')'
898
	jne	argument_parsed
898
	jne	argument_parsed
899
	dec	[parenthesis_stack]
899
	dec	[parenthesis_stack]
900
	pop	edi esi
900
	pop	edi esi
901
	jmp	expression
901
	jmp	expression
902
      contents_parsed:
902
      contents_parsed:
903
	cmp	[parenthesis_stack],0
903
	cmp	[parenthesis_stack],0
904
;        jne     invalid_expression
904
;        jne     invalid_expression
905
	je	contents_ok
905
	je	contents_ok
906
	dec	[parenthesis_stack]
906
	dec	[parenthesis_stack]
907
	add	esp,8
907
	add	esp,8
908
	jmp	contents_parsed
908
	jmp	contents_parsed
909
      contents_ok:
909
      contents_ok:
910
	ret
910
	ret
911
 
911
 
912
identify_label:
912
identify_label:
913
	cmp	byte [esi],'.'
913
	cmp	byte [esi],'.'
914
	je	local_label_name
914
	je	local_label_name
915
	call	get_label_id
915
	call	get_label_id
916
	cmp	eax,10h
916
	cmp	eax,10h
917
	jb	label_identified
917
	jb	label_identified
918
	or	ebx,ebx
918
	or	ebx,ebx
919
	jz	anonymous_label_name
919
	jz	anonymous_label_name
920
	dec	ebx
920
	dec	ebx
921
	mov	[current_locals_prefix],ebx
921
	mov	[current_locals_prefix],ebx
922
      label_identified:
922
      label_identified:
923
	ret
923
	ret
924
      anonymous_label_name:
924
      anonymous_label_name:
925
	cmp	byte [esi-1],'@'
925
	cmp	byte [esi-1],'@'
926
	je	anonymous_label_name_ok
926
	je	anonymous_label_name_ok
927
	mov	eax,0Fh
927
	mov	eax,0Fh
928
      anonymous_label_name_ok:
928
      anonymous_label_name_ok:
929
	ret
929
	ret
930
      local_label_name:
930
      local_label_name:
931
	call	get_label_id
931
	call	get_label_id
932
	ret
932
	ret
933
 
933
 
934
get_operator:
934
get_operator:
935
	cmp	byte [esi],1Ah
935
	cmp	byte [esi],1Ah
936
	jne	get_simple_operator
936
	jne	get_simple_operator
937
	mov	edx,esi
937
	mov	edx,esi
938
	push	ebp
938
	push	ebp
939
	inc	esi
939
	inc	esi
940
	lods	byte [esi]
940
	lods	byte [esi]
941
	movzx	ebp,al
941
	movzx	ebp,al
942
	push	edi
942
	push	edi
943
	mov	ecx,ebp
943
	mov	ecx,ebp
944
	call	lower_case
944
	call	lower_case
945
	pop	edi
945
	pop	edi
946
      check_operator:
946
      check_operator:
947
	mov	esi,converted
947
	mov	esi,converted
948
	movzx	ecx,byte [edi]
948
	movzx	ecx,byte [edi]
949
	jecxz	no_operator
949
	jecxz	no_operator
950
	inc	edi
950
	inc	edi
951
	mov	ebx,edi
951
	mov	ebx,edi
952
	add	ebx,ecx
952
	add	ebx,ecx
953
	cmp	ecx,ebp
953
	cmp	ecx,ebp
954
	jne	next_operator
954
	jne	next_operator
955
	repe	cmps byte [esi],[edi]
955
	repe	cmps byte [esi],[edi]
956
	je	operator_found
956
	je	operator_found
957
      next_operator:
957
      next_operator:
958
	mov	edi,ebx
958
	mov	edi,ebx
959
	inc	edi
959
	inc	edi
960
	jmp	check_operator
960
	jmp	check_operator
961
      no_operator:
961
      no_operator:
962
	mov	esi,edx
962
	mov	esi,edx
963
	mov	ecx,ebp
963
	mov	ecx,ebp
964
	pop	ebp
964
	pop	ebp
965
      no_simple_operator:
965
      no_simple_operator:
966
	xor	al,al
966
	xor	al,al
967
	ret
967
	ret
968
      operator_found:
968
      operator_found:
969
	lea	esi,[edx+2+ebp]
969
	lea	esi,[edx+2+ebp]
970
	mov	ecx,ebp
970
	mov	ecx,ebp
971
	pop	ebp
971
	pop	ebp
972
	mov	al,[edi]
972
	mov	al,[edi]
973
	ret
973
	ret
974
      get_simple_operator:
974
      get_simple_operator:
975
	mov	al,[esi]
975
	mov	al,[esi]
976
	cmp	al,22h
976
	cmp	al,22h
977
	je	no_simple_operator
977
	je	no_simple_operator
978
      simple_operator:
978
      simple_operator:
979
	cmp	byte [edi],1
979
	cmp	byte [edi],1
980
	jb	no_simple_operator
980
	jb	no_simple_operator
981
	ja	simple_next_operator
981
	ja	simple_next_operator
982
	cmp	al,[edi+1]
982
	cmp	al,[edi+1]
983
	je	simple_operator_found
983
	je	simple_operator_found
984
      simple_next_operator:
984
      simple_next_operator:
985
	movzx	ecx,byte [edi]
985
	movzx	ecx,byte [edi]
986
	lea	edi,[edi+1+ecx+1]
986
	lea	edi,[edi+1+ecx+1]
987
	jmp	simple_operator
987
	jmp	simple_operator
988
      simple_operator_found:
988
      simple_operator_found:
989
	inc	esi
989
	inc	esi
990
	mov	al,[edi+2]
990
	mov	al,[edi+2]
991
	ret
991
	ret
992
 
992
 
993
get_symbol:
993
get_symbol:
994
	push	esi
994
	push	esi
995
	mov	ebp,ecx
995
	mov	ebp,ecx
996
	call	lower_case
996
	call	lower_case
997
	mov	ecx,ebp
997
	mov	ecx,ebp
998
	cmp	cl,11
998
	cmp	cl,11
999
	ja	no_symbol
999
	ja	no_symbol
1000
	sub	cl,2
1000
	sub	cl,2
1001
	jc	no_symbol
1001
	jc	no_symbol
1002
	movzx	ebx,word [symbols+ecx*4]
1002
	movzx	ebx,word [symbols+ecx*4]
1003
	add	ebx,symbols
1003
	add	ebx,symbols
1004
	movzx	edx,word [symbols+ecx*4+2]
1004
	movzx	edx,word [symbols+ecx*4+2]
1005
      scan_symbols:
1005
      scan_symbols:
1006
	or	edx,edx
1006
	or	edx,edx
1007
	jz	no_symbol
1007
	jz	no_symbol
1008
	mov	eax,edx
1008
	mov	eax,edx
1009
	shr	eax,1
1009
	shr	eax,1
1010
	lea	edi,[ebp+2]
1010
	lea	edi,[ebp+2]
1011
	imul	eax,edi
1011
	imul	eax,edi
1012
	lea	edi,[ebx+eax]
1012
	lea	edi,[ebx+eax]
1013
	mov	esi,converted
1013
	mov	esi,converted
1014
	mov	ecx,ebp
1014
	mov	ecx,ebp
1015
	repe	cmps byte [esi],[edi]
1015
	repe	cmps byte [esi],[edi]
1016
	ja	symbols_up
1016
	ja	symbols_up
1017
	jb	symbols_down
1017
	jb	symbols_down
1018
	pop	esi
1018
	pop	esi
1019
	add	esi,ebp
1019
	add	esi,ebp
1020
	mov	ax,[edi]
1020
	mov	ax,[edi]
1021
	clc
1021
	clc
1022
	ret
1022
	ret
1023
      no_symbol:
1023
      no_symbol:
1024
	pop	esi
1024
	pop	esi
1025
	mov	ecx,ebp
1025
	mov	ecx,ebp
1026
	stc
1026
	stc
1027
	ret
1027
	ret
1028
      symbols_down:
1028
      symbols_down:
1029
	shr	edx,1
1029
	shr	edx,1
1030
	jmp	scan_symbols
1030
	jmp	scan_symbols
1031
      symbols_up:
1031
      symbols_up:
1032
	lea	ebx,[edi+ecx+2]
1032
	lea	ebx,[edi+ecx+2]
1033
	shr	edx,1
1033
	shr	edx,1
1034
	adc	edx,-1
1034
	adc	edx,-1
1035
	jmp	scan_symbols
1035
	jmp	scan_symbols
1036
 
1036
 
1037
get_data_directive:
1037
get_data_directive:
1038
	push	esi
1038
	push	esi
1039
	mov	ebp,ecx
1039
	mov	ebp,ecx
1040
	call	lower_case
1040
	call	lower_case
1041
	mov	ecx,ebp
1041
	mov	ecx,ebp
1042
	cmp	cl,4
1042
	cmp	cl,4
1043
	ja	no_instruction
1043
	ja	no_instruction
1044
	sub	cl,2
1044
	sub	cl,2
1045
	jc	no_instruction
1045
	jc	no_instruction
1046
	movzx	ebx,word [data_directives+ecx*4]
1046
	movzx	ebx,word [data_directives+ecx*4]
1047
	add	ebx,data_directives
1047
	add	ebx,data_directives
1048
	movzx	edx,word [data_directives+ecx*4+2]
1048
	movzx	edx,word [data_directives+ecx*4+2]
1049
	jmp	scan_instructions
1049
	jmp	scan_instructions
1050
 
1050
 
1051
get_instruction:
1051
get_instruction:
1052
	push	esi
1052
	push	esi
1053
	mov	ebp,ecx
1053
	mov	ebp,ecx
1054
	call	lower_case
1054
	call	lower_case
1055
	mov	ecx,ebp
1055
	mov	ecx,ebp
1056
	cmp	cl,11
1056
	cmp	cl,11
1057
	ja	no_instruction
1057
	ja	no_instruction
1058
	sub	cl,2
1058
	sub	cl,2
1059
	jc	no_instruction
1059
	jc	no_instruction
1060
	movzx	ebx,word [instructions+ecx*4]
1060
	movzx	ebx,word [instructions+ecx*4]
1061
	add	ebx,instructions
1061
	add	ebx,instructions
1062
	movzx	edx,word [instructions+ecx*4+2]
1062
	movzx	edx,word [instructions+ecx*4+2]
1063
      scan_instructions:
1063
      scan_instructions:
1064
	or	edx,edx
1064
	or	edx,edx
1065
	jz	no_instruction
1065
	jz	no_instruction
1066
	mov	eax,edx
1066
	mov	eax,edx
1067
	shr	eax,1
1067
	shr	eax,1
1068
	lea	edi,[ebp+3]
1068
	lea	edi,[ebp+3]
1069
	imul	eax,edi
1069
	imul	eax,edi
1070
	lea	edi,[ebx+eax]
1070
	lea	edi,[ebx+eax]
1071
	mov	esi,converted
1071
	mov	esi,converted
1072
	mov	ecx,ebp
1072
	mov	ecx,ebp
1073
	repe	cmps byte [esi],[edi]
1073
	repe	cmps byte [esi],[edi]
1074
	ja	instructions_up
1074
	ja	instructions_up
1075
	jb	instructions_down
1075
	jb	instructions_down
1076
	pop	esi
1076
	pop	esi
1077
	add	esi,ebp
1077
	add	esi,ebp
1078
	mov	al,[edi]
1078
	mov	al,[edi]
1079
	mov	bx,[edi+1]
1079
	mov	bx,[edi+1]
1080
	clc
1080
	clc
1081
	ret
1081
	ret
1082
      no_instruction:
1082
      no_instruction:
1083
	pop	esi
1083
	pop	esi
1084
	mov	ecx,ebp
1084
	mov	ecx,ebp
1085
	stc
1085
	stc
1086
	ret
1086
	ret
1087
      instructions_down:
1087
      instructions_down:
1088
	shr	edx,1
1088
	shr	edx,1
1089
	jmp	scan_instructions
1089
	jmp	scan_instructions
1090
      instructions_up:
1090
      instructions_up:
1091
	lea	ebx,[edi+ecx+3]
1091
	lea	ebx,[edi+ecx+3]
1092
	shr	edx,1
1092
	shr	edx,1
1093
	adc	edx,-1
1093
	adc	edx,-1
1094
	jmp	scan_instructions
1094
	jmp	scan_instructions
1095
 
1095
 
1096
get_label_id:
1096
get_label_id:
1097
	cmp	ecx,100h
1097
	cmp	ecx,100h
1098
	jae	name_too_long
1098
	jae	name_too_long
1099
	cmp	byte [esi],'@'
1099
	cmp	byte [esi],'@'
1100
	je	anonymous_label
1100
	je	anonymous_label
1101
	cmp	byte [esi],'.'
1101
	cmp	byte [esi],'.'
1102
	jne	standard_label
1102
	jne	standard_label
1103
	cmp	byte [esi+1],'.'
1103
	cmp	byte [esi+1],'.'
1104
	je	standard_label
1104
	je	standard_label
1105
	cmp	[current_locals_prefix],0
1105
	cmp	[current_locals_prefix],0
1106
	je	standard_label
1106
	je	standard_label
1107
	push	edi
1107
	push	edi
1108
	mov	edi,[additional_memory_end]
1108
	mov	edi,[additional_memory_end]
1109
	sub	edi,2
1109
	sub	edi,2
1110
	sub	edi,ecx
1110
	sub	edi,ecx
1111
	push	ecx esi
1111
	push	ecx esi
1112
	mov	esi,[current_locals_prefix]
1112
	mov	esi,[current_locals_prefix]
1113
	lods	byte [esi]
1113
	lods	byte [esi]
1114
	movzx	ecx,al
1114
	movzx	ecx,al
1115
	sub	edi,ecx
1115
	sub	edi,ecx
1116
	cmp	edi,[free_additional_memory]
1116
	cmp	edi,[free_additional_memory]
1117
	jb	out_of_memory
1117
	jb	out_of_memory
1118
	mov	word [edi],0
1118
	mov	word [edi],0
1119
	add	edi,2
1119
	add	edi,2
1120
	mov	ebx,edi
1120
	mov	ebx,edi
1121
	rep	movs byte [edi],[esi]
1121
	rep	movs byte [edi],[esi]
1122
	pop	esi ecx
1122
	pop	esi ecx
1123
	add	al,cl
1123
	add	al,cl
1124
	jc	name_too_long
1124
	jc	name_too_long
1125
	rep	movs byte [edi],[esi]
1125
	rep	movs byte [edi],[esi]
1126
	pop	edi
1126
	pop	edi
1127
	push	ebx esi
1127
	push	ebx esi
1128
	movzx	ecx,al
1128
	movzx	ecx,al
1129
	mov	byte [ebx-1],al
1129
	mov	byte [ebx-1],al
1130
	mov	esi,ebx
1130
	mov	esi,ebx
1131
	call	get_label_id
1131
	call	get_label_id
1132
	pop	esi ebx
1132
	pop	esi ebx
1133
	cmp	ebx,[eax+24]
1133
	cmp	ebx,[eax+24]
1134
	jne	composed_label_id_ok
1134
	jne	composed_label_id_ok
1135
	lea	edx,[ebx-2]
1135
	lea	edx,[ebx-2]
1136
	mov	[additional_memory_end],edx
1136
	mov	[additional_memory_end],edx
1137
      composed_label_id_ok:
1137
      composed_label_id_ok:
1138
	ret
1138
	ret
1139
      anonymous_label:
1139
      anonymous_label:
1140
	cmp	ecx,2
1140
	cmp	ecx,2
1141
	jne	standard_label
1141
	jne	standard_label
1142
	mov	al,[esi+1]
1142
	mov	al,[esi+1]
1143
	mov	ebx,characters
1143
	mov	ebx,characters
1144
	xlat	byte [ebx]
1144
	xlat	byte [ebx]
1145
	cmp	al,'@'
1145
	cmp	al,'@'
1146
	je	new_anonymous
1146
	je	new_anonymous
1147
	cmp	al,'b'
1147
	cmp	al,'b'
1148
	je	anonymous_back
1148
	je	anonymous_back
1149
	cmp	al,'r'
1149
	cmp	al,'r'
1150
	je	anonymous_back
1150
	je	anonymous_back
1151
	cmp	al,'f'
1151
	cmp	al,'f'
1152
	jne	standard_label
1152
	jne	standard_label
1153
	add	esi,2
1153
	add	esi,2
1154
	mov	eax,[anonymous_forward]
1154
	mov	eax,[anonymous_forward]
1155
	or	eax,eax
1155
	or	eax,eax
1156
	jnz	anonymous_ok
1156
	jnz	anonymous_ok
1157
	mov	eax,[current_line]
1157
	mov	eax,[current_line]
1158
	mov	[error_line],eax
1158
	mov	[error_line],eax
1159
	call	allocate_label
1159
	call	allocate_label
1160
	mov	[anonymous_forward],eax
1160
	mov	[anonymous_forward],eax
1161
      anonymous_ok:
1161
      anonymous_ok:
1162
	xor	ebx,ebx
1162
	xor	ebx,ebx
1163
	ret
1163
	ret
1164
      anonymous_back:
1164
      anonymous_back:
1165
	add	esi,2
1165
	add	esi,2
1166
	mov	eax,[anonymous_reverse]
1166
	mov	eax,[anonymous_reverse]
1167
	or	eax,eax
1167
	or	eax,eax
1168
	jz	invalid_value
1168
	jz	invalid_value
1169
	jmp	anonymous_ok
1169
	jmp	anonymous_ok
1170
      new_anonymous:
1170
      new_anonymous:
1171
	add	esi,2
1171
	add	esi,2
1172
	mov	eax,[anonymous_forward]
1172
	mov	eax,[anonymous_forward]
1173
	or	eax,eax
1173
	or	eax,eax
1174
	jnz	new_anonymous_ok
1174
	jnz	new_anonymous_ok
1175
	call	allocate_label
1175
	call	allocate_label
1176
      new_anonymous_ok:
1176
      new_anonymous_ok:
1177
	mov	[anonymous_reverse],eax
1177
	mov	[anonymous_reverse],eax
1178
	mov	[anonymous_forward],0
1178
	mov	[anonymous_forward],0
1179
	jmp	anonymous_ok
1179
	jmp	anonymous_ok
1180
      standard_label:
1180
      standard_label:
1181
	cmp	byte [esi],'%'
1181
	cmp	byte [esi],'%'
1182
	je	get_predefined_id
1182
	je	get_predefined_id
1183
	cmp	byte [esi],'$'
1183
	cmp	byte [esi],'$'
1184
	jne	find_label
1184
	jne	find_label
1185
	cmp	ecx,2
1185
	cmp	ecx,2
1186
	ja	find_label
1186
	ja	find_label
1187
	inc	esi
1187
	inc	esi
1188
	jb	get_current_offset_id
1188
	jb	get_current_offset_id
1189
	inc	esi
1189
	inc	esi
1190
	cmp	byte [esi-1],'$'
1190
	cmp	byte [esi-1],'$'
1191
	je	get_org_origin_id
1191
	je	get_org_origin_id
1192
	sub	esi,ecx
1192
	sub	esi,ecx
1193
	jmp	find_label
1193
	jmp	find_label
1194
      get_current_offset_id:
1194
      get_current_offset_id:
1195
	xor	eax,eax
1195
	xor	eax,eax
1196
	ret
1196
	ret
1197
      get_counter_id:
1197
      get_counter_id:
1198
	mov	eax,1
1198
	mov	eax,1
1199
	ret
1199
	ret
1200
      get_timestamp_id:
1200
      get_timestamp_id:
1201
	mov	eax,2
1201
	mov	eax,2
1202
	ret
1202
	ret
1203
      get_org_origin_id:
1203
      get_org_origin_id:
1204
	mov	eax,3
1204
	mov	eax,3
1205
	ret
1205
	ret
1206
      get_predefined_id:
1206
      get_predefined_id:
1207
	cmp	ecx,2
1207
	cmp	ecx,2
1208
	ja	find_label
1208
	ja	find_label
1209
	inc	esi
1209
	inc	esi
1210
	cmp	cl,1
1210
	cmp	cl,1
1211
	je	get_counter_id
1211
	je	get_counter_id
1212
	lods	byte [esi]
1212
	lods	byte [esi]
1213
	mov	ebx,characters
1213
	mov	ebx,characters
1214
	xlat	[ebx]
1214
	xlat	[ebx]
1215
	cmp	al,'t'
1215
	cmp	al,'t'
1216
	je	get_timestamp_id
1216
	je	get_timestamp_id
1217
	sub	esi,2
1217
	sub	esi,2
1218
      find_label:
1218
      find_label:
1219
	xor	ebx,ebx
1219
	xor	ebx,ebx
1220
	mov	eax,2166136261
1220
	mov	eax,2166136261
1221
	mov	ebp,16777619
1221
	mov	ebp,16777619
1222
      hash_label:
1222
      hash_label:
1223
	xor	al,[esi+ebx]
1223
	xor	al,[esi+ebx]
1224
	mul	ebp
1224
	mul	ebp
1225
	inc	bl
1225
	inc	bl
1226
	cmp	bl,cl
1226
	cmp	bl,cl
1227
	jb	hash_label
1227
	jb	hash_label
1228
	mov	ebp,eax
1228
	mov	ebp,eax
1229
	shl	eax,8
1229
	shl	eax,8
1230
	and	ebp,0FFh shl 24
1230
	and	ebp,0FFh shl 24
1231
	xor	ebp,eax
1231
	xor	ebp,eax
1232
	or	ebp,ebx
1232
	or	ebp,ebx
1233
	mov	[label_hash],ebp
1233
	mov	[label_hash],ebp
1234
	push	edi esi
1234
	push	edi esi
1235
	push	ecx
1235
	push	ecx
1236
	mov	ecx,32
1236
	mov	ecx,32
1237
	mov	ebx,hash_tree
1237
	mov	ebx,hash_tree
1238
      follow_tree:
1238
      follow_tree:
1239
	mov	edx,[ebx]
1239
	mov	edx,[ebx]
1240
	or	edx,edx
1240
	or	edx,edx
1241
	jz	extend_tree
1241
	jz	extend_tree
1242
	xor	eax,eax
1242
	xor	eax,eax
1243
	shl	ebp,1
1243
	shl	ebp,1
1244
	adc	eax,0
1244
	adc	eax,0
1245
	lea	ebx,[edx+eax*4]
1245
	lea	ebx,[edx+eax*4]
1246
	dec	ecx
1246
	dec	ecx
1247
	jnz	follow_tree
1247
	jnz	follow_tree
1248
	mov	[label_leaf],ebx
1248
	mov	[label_leaf],ebx
1249
	pop	edx
1249
	pop	edx
1250
	mov	eax,[ebx]
1250
	mov	eax,[ebx]
1251
	or	eax,eax
1251
	or	eax,eax
1252
	jz	add_label
1252
	jz	add_label
1253
	mov	ebx,esi
1253
	mov	ebx,esi
1254
	mov	ebp,[label_hash]
1254
	mov	ebp,[label_hash]
1255
      compare_labels:
1255
      compare_labels:
1256
	mov	esi,ebx
1256
	mov	esi,ebx
1257
	mov	ecx,edx
1257
	mov	ecx,edx
1258
	mov	edi,[eax+4]
1258
	mov	edi,[eax+4]
1259
	mov	edi,[edi+24]
1259
	mov	edi,[edi+24]
1260
	repe	cmps byte [esi],[edi]
1260
	repe	cmps byte [esi],[edi]
1261
	je	label_found
1261
	je	label_found
1262
	mov	eax,[eax]
1262
	mov	eax,[eax]
1263
	or	eax,eax
1263
	or	eax,eax
1264
	jnz	compare_labels
1264
	jnz	compare_labels
1265
	jmp	add_label
1265
	jmp	add_label
1266
      label_found:
1266
      label_found:
1267
	add	esp,4
1267
	add	esp,4
1268
	pop	edi
1268
	pop	edi
1269
	mov	eax,[eax+4]
1269
	mov	eax,[eax+4]
1270
	ret
1270
	ret
1271
      extend_tree:
1271
      extend_tree:
1272
	mov	edx,[free_additional_memory]
1272
	mov	edx,[free_additional_memory]
1273
	lea	eax,[edx+8]
1273
	lea	eax,[edx+8]
1274
	cmp	eax,[additional_memory_end]
1274
	cmp	eax,[additional_memory_end]
1275
	ja	out_of_memory
1275
	ja	out_of_memory
1276
	mov	[free_additional_memory],eax
1276
	mov	[free_additional_memory],eax
1277
	xor	eax,eax
1277
	xor	eax,eax
1278
	mov	[edx],eax
1278
	mov	[edx],eax
1279
	mov	[edx+4],eax
1279
	mov	[edx+4],eax
1280
	shl	ebp,1
1280
	shl	ebp,1
1281
	adc	eax,0
1281
	adc	eax,0
1282
	mov	[ebx],edx
1282
	mov	[ebx],edx
1283
	lea	ebx,[edx+eax*4]
1283
	lea	ebx,[edx+eax*4]
1284
	dec	ecx
1284
	dec	ecx
1285
	jnz	extend_tree
1285
	jnz	extend_tree
1286
	mov	[label_leaf],ebx
1286
	mov	[label_leaf],ebx
1287
	pop	edx
1287
	pop	edx
1288
      add_label:
1288
      add_label:
1289
	mov	ecx,edx
1289
	mov	ecx,edx
1290
	pop	esi
1290
	pop	esi
1291
	cmp	byte [esi-2],0
1291
	cmp	byte [esi-2],0
1292
	je	label_name_ok
1292
	je	label_name_ok
1293
	mov	al,[esi]
1293
	mov	al,[esi]
1294
	cmp	al,30h
1294
	cmp	al,30h
1295
	jb	name_first_char_ok
1295
	jb	name_first_char_ok
1296
	cmp	al,39h
1296
	cmp	al,39h
1297
	jbe	invalid_name
1297
	jbe	invalid_name
1298
      name_first_char_ok:
1298
      name_first_char_ok:
1299
	cmp	ecx,1
1299
	cmp	al,'$'
1300
	jne	check_for_reserved_word
-
 
1301
	cmp	al,'$'
-
 
1302
	je	reserved_word
1300
	jne	check_for_reserved_word
-
 
1301
	cmp	ecx,1
-
 
1302
	jne	invalid_name
-
 
1303
      reserved_word:
1303
      check_for_reserved_word:
1304
	mov	eax,0Fh
-
 
1305
	pop	edi
-
 
1306
	ret
-
 
1307
      check_for_reserved_word:
1304
	call	get_instruction
1308
	call	get_instruction
1305
	jnc	reserved_word
1309
	jnc	reserved_word
1306
	call	get_data_directive
1310
	call	get_data_directive
1307
	jnc	reserved_word
1311
	jnc	reserved_word
1308
	call	get_symbol
1312
	call	get_symbol
1309
	jnc	reserved_word
1313
	jnc	reserved_word
1310
	sub	esi,2
1314
	sub	esi,2
1311
	mov	edi,operators
1315
	mov	edi,operators
1312
	call	get_operator
1316
	call	get_operator
1313
	or	al,al
1317
	or	al,al
1314
	jnz	reserved_word
1318
	jnz	reserved_word
1315
	mov	edi,single_operand_operators
1319
	mov	edi,single_operand_operators
1316
	call	get_operator
1320
	call	get_operator
1317
	or	al,al
1321
	or	al,al
1318
	jnz	reserved_word
1322
	jnz	reserved_word
1319
	mov	edi,directive_operators
1323
	mov	edi,directive_operators
1320
	call	get_operator
1324
	call	get_operator
1321
	or	al,al
1325
	or	al,al
1322
	jnz	reserved_word
1326
	jnz	reserved_word
1323
	inc	esi
1327
	inc	esi
1324
	movzx	ecx,byte [esi]
1328
	movzx	ecx,byte [esi]
1325
	inc	esi
1329
	inc	esi
1326
      label_name_ok:
1330
      label_name_ok:
1327
	mov	edx,[free_additional_memory]
1331
	mov	edx,[free_additional_memory]
1328
	lea	eax,[edx+8]
1332
	lea	eax,[edx+8]
1329
	cmp	eax,[additional_memory_end]
1333
	cmp	eax,[additional_memory_end]
1330
	ja	out_of_memory
1334
	ja	out_of_memory
1331
	mov	[free_additional_memory],eax
1335
	mov	[free_additional_memory],eax
1332
	mov	ebx,esi
1336
	mov	ebx,esi
1333
	add	esi,ecx
1337
	add	esi,ecx
1334
	mov	eax,[label_leaf]
1338
	mov	eax,[label_leaf]
1335
	mov	edi,[eax]
1339
	mov	edi,[eax]
1336
	mov	[edx],edi
1340
	mov	[edx],edi
1337
	mov	[eax],edx
1341
	mov	[eax],edx
1338
	call	allocate_label
1342
	call	allocate_label
1339
	mov	[edx+4],eax
1343
	mov	[edx+4],eax
1340
	mov	[eax+24],ebx
1344
	mov	[eax+24],ebx
1341
	pop	edi
1345
	pop	edi
1342
	ret
1346
	ret
1343
      reserved_word:
-
 
1344
	mov	eax,0Fh
-
 
1345
	pop	edi
-
 
1346
	ret
-
 
1347
      allocate_label:
1347
      allocate_label:
1348
	mov	eax,[labels_list]
1348
	mov	eax,[labels_list]
1349
	mov	ecx,LABEL_STRUCTURE_SIZE shr 2
1349
	mov	ecx,LABEL_STRUCTURE_SIZE shr 2
1350
      initialize_label:
1350
      initialize_label:
1351
	sub	eax,4
1351
	sub	eax,4
1352
	mov	dword [eax],0
1352
	mov	dword [eax],0
1353
	loop	initialize_label
1353
	loop	initialize_label
1354
	mov	[labels_list],eax
1354
	mov	[labels_list],eax
1355
	ret
1355
	ret
1356
 
1356
 
1357
LABEL_STRUCTURE_SIZE = 32
1357
LABEL_STRUCTURE_SIZE = 32
1358
>
1358
>