Subversion Repositories Kolibri OS

Rev

Rev 7836 | Details | Compare with Previous | Last modification | View Log | RSS feed

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