Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

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