Subversion Repositories Kolibri OS

Rev

Rev 624 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
31 halyavin 1
 
2
; Copyright (c) 1999-2007, Tomasz Grysztar.
340 heavyiron 3
; All rights reserved.
31 halyavin 4
5
 
6
	mov	eax,[memory_end]
157 heavyiron 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
242 heavyiron 17
	mov	esi,[memory_start]
157 heavyiron 18
	mov	edi,[source_start]
19
      parser_loop:
31 halyavin 20
	mov	[current_line],esi
157 heavyiron 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
992 heavyiron 27
	je	empty_line
28
	mov	al,0Fh
157 heavyiron 29
	stos	byte [edi]
30
	mov	eax,esi
31
	stos	dword [edi]
32
	inc	[parsed_lines]
242 heavyiron 33
	add	esi,16
157 heavyiron 34
      parse_line:
109 heavyiron 35
	cmp	byte [esi],1Ah
157 heavyiron 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:
109 heavyiron 55
	call	get_data_directive
157 heavyiron 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:
109 heavyiron 63
	pop	edi
157 heavyiron 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:
109 heavyiron 73
	pop	edi
157 heavyiron 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:
109 heavyiron 85
	pop	ecx edx
157 heavyiron 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:
109 heavyiron 98
	pop	edi
157 heavyiron 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:
109 heavyiron 117
	call	parse_line_contents
157 heavyiron 118
	jmp	parse_next_line
119
      empty_instruction:
109 heavyiron 120
	lods	byte [esi]
157 heavyiron 121
	or	al,al
122
	jz	parse_next_line
123
	cmp	al,':'
124
	je	invalid_name
125
	dec	esi
992 heavyiron 126
	cmp	al,3Bh
157 heavyiron 127
	je	skip_rest_of_line
992 heavyiron 128
	call	parse_argument
157 heavyiron 129
	jmp	parse_next_line
130
      empty_line:
109 heavyiron 131
	add	esi,16
992 heavyiron 132
      skip_rest_of_line:
133
	call	skip_foreign_line
134
      parse_next_line:
31 halyavin 135
	cmp	esi,[source_start]
157 heavyiron 136
	jb	parser_loop
137
      source_parsed:
109 heavyiron 138
	cmp	[blocks_stack],0
157 heavyiron 139
	je	blocks_stack_ok
140
	pop	eax
141
	pop	[current_line]
142
	jmp	missing_end_directive
143
      blocks_stack_ok:
109 heavyiron 144
	xor	al,al
157 heavyiron 145
	stos	byte [edi]
146
	add	edi,0Fh
147
	and	edi,not 0Fh
148
	mov	[code_start],edi
149
	ret
150
      parse_block:
109 heavyiron 151
	mov	eax,esp
157 heavyiron 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:
109 heavyiron 168
	cmp	byte [esi],1Ah
157 heavyiron 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:
109 heavyiron 180
	mov	dl,al
157 heavyiron 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:
109 heavyiron 198
	cmp	[blocks_stack],0
157 heavyiron 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:
109 heavyiron 213
	push	edi
157 heavyiron 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:
109 heavyiron 228
	push	edi
157 heavyiron 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:
109 heavyiron 243
	or	byte [esp],1
157 heavyiron 244
	sub	edi,4
245
	jmp	skip_parsing
246
      parse_true_condition_block:
109 heavyiron 247
	or	byte [esp],100b
157 heavyiron 248
	sub	edi,4
249
	jmp	parse_next_line
250
      parse_else:
109 heavyiron 251
	cmp	[blocks_stack],0
157 heavyiron 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:
109 heavyiron 279
	sub	edi,4
157 heavyiron 280
	or	byte [esp],1
281
	jmp	skip_parsing_contents
282
      parse_pure_else:
109 heavyiron 283
	bts	dword [esp],1
157 heavyiron 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:
109 heavyiron 291
	cmp	esi,[source_start]
157 heavyiron 292
	jae	source_parsed
293
	mov	[current_line],esi
294
	add	esi,16
295
      skip_parsing_line:
109 heavyiron 296
	cmp	byte [esi],1Ah
157 heavyiron 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:
109 heavyiron 310
	lea	esi,[esi+ecx+1]
157 heavyiron 311
	jmp	skip_parsing_line
312
      skip_parsing_instruction:
109 heavyiron 313
	cmp	bx,if_directive-assembler
157 heavyiron 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:
109 heavyiron 324
	lods	byte [esi]
157 heavyiron 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:
109 heavyiron 335
	lods	byte [esi]
157 heavyiron 336
	movzx	eax,al
337
	add	esi,eax
338
	jmp	skip_parsing_contents
339
      skip_parsing_string:
109 heavyiron 340
	lods	dword [esi]
157 heavyiron 341
	add	esi,eax
342
	jmp	skip_parsing_contents
343
      skip_parsing_block:
109 heavyiron 344
	mov	eax,esp
157 heavyiron 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:
109 heavyiron 356
	cmp	byte [esi],1Ah
157 heavyiron 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:
109 heavyiron 368
	lods	byte [esi]
157 heavyiron 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:
109 heavyiron 379
	cmp	[blocks_stack],0
157 heavyiron 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]
242 heavyiron 396
	mov	eax,1 + (end_directive-assembler) shl 8
157 heavyiron 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:
109 heavyiron 402
	cmp	[blocks_stack],0
157 heavyiron 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]
242 heavyiron 433
      parse_else_if:
109 heavyiron 434
	mov	eax,1 + (if_directive-assembler) shl 8
157 heavyiron 435
	stos	dword [edi]
436
	jmp	parse_if
437
      skip_parsing_pure_else:
109 heavyiron 438
	bts	dword [esp],1
157 heavyiron 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
31 halyavin 450
 
109 heavyiron 451
	mov	[parenthesis_stack],0
157 heavyiron 452
      parse_instruction_arguments:
109 heavyiron 453
	cmp	bx,prefix_instruction-assembler
157 heavyiron 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:
109 heavyiron 470
	lea	eax,[edi+100h]
157 heavyiron 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:
109 heavyiron 527
	pop	edi
157 heavyiron 528
	stos	word [edi]
529
	jmp	argument_parsed
530
      operator_argument:
109 heavyiron 531
	pop	edi
157 heavyiron 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:
109 heavyiron 545
	cmp	byte [esi],1Ah
157 heavyiron 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:
109 heavyiron 559
	pop	edi
157 heavyiron 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:
109 heavyiron 569
	mov	al,'('
157 heavyiron 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:
31 halyavin 579
	cmp	byte [esi],1Ah
157 heavyiron 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:
109 heavyiron 596
	mov	esi,ebx
157 heavyiron 597
	jmp	argument_parsed
598
      parse_load_directive:
31 halyavin 599
	cmp	byte [esi],1Ah
157 heavyiron 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:
31 halyavin 616
	cmp	byte [esi],1Ah
157 heavyiron 617
	jne	parse_argument
618
	inc	esi
619
	push	esi
620
	movzx	ecx,byte [esi]
621
	inc	esi
622
	push	esi ecx
624 heavyiron 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
157 heavyiron 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:
31 halyavin 661
	cmp	byte [esi],22h
157 heavyiron 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:
31 halyavin 677
	cmp	byte [esi],1Ah
157 heavyiron 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:
31 halyavin 690
	cmp	byte [esi],22h
157 heavyiron 691
	jne	forced_expression
692
	jmp	argument_parsed
693
      parse_quoted_extrn:
31 halyavin 694
	inc	esi
157 heavyiron 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:
31 halyavin 714
	call	parse_address
157 heavyiron 715
	jmp	address_parsed
716
      check_argument:
31 halyavin 717
	push	esi ecx
157 heavyiron 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:
31 halyavin 729
	pop	edi
157 heavyiron 730
	sub	esi,2
731
      expression_argument:
31 halyavin 732
	cmp	byte [esi],22h
157 heavyiron 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:
31 halyavin 748
	inc	esi
157 heavyiron 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:
31 halyavin 758
	shr	ecx,1
157 heavyiron 759
	jnc	string_movsw_ok
760
	movs	word [edi],[esi]
761
      string_movsw_ok:
31 halyavin 762
	rep	movs dword [edi],[esi]
157 heavyiron 763
	xor	al,al
764
	stos	byte [edi]
765
	jmp	expression_parsed
766
      not_string:
31 halyavin 767
	cmp	byte [esi],'('
157 heavyiron 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:
31 halyavin 781
	mov	al,'('
157 heavyiron 782
	stos	byte [edi]
783
	call	convert_expression
784
	mov	al,')'
785
	stos	byte [edi]
786
	jmp	expression_parsed
787
      forced_expression:
31 halyavin 788
	mov	al,'('
157 heavyiron 789
	stos	byte [edi]
790
	call	convert_expression
791
	mov	al,')'
792
	stos	byte [edi]
793
	jmp	argument_parsed
794
      address_argument:
31 halyavin 795
	call	parse_address
157 heavyiron 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:
31 halyavin 804
	mov	al,']'
157 heavyiron 805
	stos	byte [edi]
806
	jmp	argument_parsed
807
      parse_address:
31 halyavin 808
	mov	al,'['
157 heavyiron 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:
109 heavyiron 833
	sub	esi,5
157 heavyiron 834
      convert_address:
31 halyavin 835
	push	edi
157 heavyiron 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:
31 halyavin 845
	cmp	byte [esi],'('
157 heavyiron 846
	jne	argument_parsed
847
	inc	esi
848
	mov	al,'{'
849
	jmp	separator
850
      unallowed_character:
31 halyavin 851
	mov	al,0FFh
157 heavyiron 852
	jmp	separator
853
      close_parenthesis:
31 halyavin 854
	mov	al,'}'
157 heavyiron 855
      separator:
31 halyavin 856
	stos	byte [edi]
157 heavyiron 857
	jmp	argument_parsed
858
      instruction_separator:
31 halyavin 859
	stos	byte [edi]
157 heavyiron 860
	jmp	allow_embedded_instruction
861
      greater:
31 halyavin 862
	cmp	byte [esi],'='
157 heavyiron 863
	jne	separator
864
	inc	esi
865
	mov	al,0F2h
866
	jmp	separator
867
      less:
31 halyavin 868
	cmp	byte [edi-1],0F6h
157 heavyiron 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:
31 halyavin 878
	inc	esi
157 heavyiron 879
	mov	al,0F1h
880
	jmp	separator
881
      argument_parsed:
31 halyavin 882
	cmp	[parenthesis_stack],0
157 heavyiron 883
	je	parse_argument
884
	dec	[parenthesis_stack]
885
	add	esp,8
886
	jmp	argument_parsed
887
      expression_parsed:
31 halyavin 888
	cmp	[parenthesis_stack],0
157 heavyiron 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:
109 heavyiron 896
	cmp	[parenthesis_stack],0
157 heavyiron 897
	je	contents_ok
242 heavyiron 898
	dec	[parenthesis_stack]
899
	add	esp,8
900
	jmp	contents_parsed
901
      contents_ok:
902
	ret
157 heavyiron 903
31 halyavin 904
 
109 heavyiron 905
	cmp	byte [esi],'.'
157 heavyiron 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:
109 heavyiron 915
	ret
157 heavyiron 916
      anonymous_label_name:
109 heavyiron 917
	cmp	byte [esi-1],'@'
157 heavyiron 918
	je	anonymous_label_name_ok
919
	mov	eax,0Fh
920
      anonymous_label_name_ok:
109 heavyiron 921
	ret
157 heavyiron 922
      local_label_name:
109 heavyiron 923
	call	get_label_id
157 heavyiron 924
	ret
925
109 heavyiron 926
 
31 halyavin 927
	cmp	byte [esi],1Ah
157 heavyiron 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:
31 halyavin 939
	mov	esi,converted
157 heavyiron 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:
31 halyavin 950
	mov	edi,ebx
157 heavyiron 951
	inc	edi
952
	jmp	check_operator
953
      no_operator:
31 halyavin 954
	mov	esi,edx
157 heavyiron 955
	mov	ecx,ebp
956
	pop	ebp
957
      no_simple_operator:
31 halyavin 958
	xor	al,al
157 heavyiron 959
	ret
960
      operator_found:
31 halyavin 961
	lea	esi,[edx+2+ebp]
157 heavyiron 962
	mov	ecx,ebp
963
	pop	ebp
964
	mov	al,[edi]
965
	ret
966
      get_simple_operator:
31 halyavin 967
	mov	al,[esi]
157 heavyiron 968
	cmp	al,22h
969
	je	no_simple_operator
970
      simple_operator:
31 halyavin 971
	cmp	byte [edi],1
157 heavyiron 972
	jb	no_simple_operator
973
	ja	simple_next_operator
974
	cmp	al,[edi+1]
975
	je	simple_operator_found
976
      simple_next_operator:
31 halyavin 977
	movzx	ecx,byte [edi]
157 heavyiron 978
	lea	edi,[edi+1+ecx+1]
979
	jmp	simple_operator
980
      simple_operator_found:
31 halyavin 981
	inc	esi
157 heavyiron 982
	mov	al,[edi+2]
983
	ret
984
31 halyavin 985
 
986
	push	esi
157 heavyiron 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:
31 halyavin 998
	or	edx,edx
157 heavyiron 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:
31 halyavin 1016
	pop	esi
157 heavyiron 1017
	mov	ecx,ebp
1018
	stc
1019
	ret
1020
      symbols_down:
109 heavyiron 1021
	shr	edx,1
157 heavyiron 1022
	jmp	scan_symbols
1023
      symbols_up:
109 heavyiron 1024
	lea	ebx,[edi+ecx+2]
157 heavyiron 1025
	shr	edx,1
1026
	adc	edx,-1
1027
	jmp	scan_symbols
1028
31 halyavin 1029
 
109 heavyiron 1030
	push	esi
157 heavyiron 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
109 heavyiron 1043
 
31 halyavin 1044
	push	esi
157 heavyiron 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:
31 halyavin 1056
	or	edx,edx
157 heavyiron 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:
31 halyavin 1075
	pop	esi
157 heavyiron 1076
	mov	ecx,ebp
1077
	stc
1078
	ret
1079
      instructions_down:
109 heavyiron 1080
	shr	edx,1
157 heavyiron 1081
	jmp	scan_instructions
1082
      instructions_up:
109 heavyiron 1083
	lea	ebx,[edi+ecx+3]
157 heavyiron 1084
	shr	edx,1
1085
	adc	edx,-1
1086
	jmp	scan_instructions
1087
31 halyavin 1088
 
1089
	cmp	ecx,100h
157 heavyiron 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:
109 heavyiron 1130
	ret
157 heavyiron 1131
      anonymous_label:
31 halyavin 1132
	cmp	ecx,2
157 heavyiron 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:
31 halyavin 1154
	xor	ebx,ebx
157 heavyiron 1155
	ret
1156
      anonymous_back:
31 halyavin 1157
	mov	eax,[anonymous_reverse]
157 heavyiron 1158
	or	eax,eax
1159
	jz	new_anonymous
607 heavyiron 1160
	add	esi,2
1161
	jmp	anonymous_ok
157 heavyiron 1162
      new_anonymous:
31 halyavin 1163
	add	esi,2
157 heavyiron 1164
	mov	eax,[anonymous_forward]
1165
	or	eax,eax
1166
	jnz	new_anonymous_ok
1167
	call	allocate_label
1168
      new_anonymous_ok:
31 halyavin 1169
	mov	[anonymous_reverse],eax
157 heavyiron 1170
	mov	[anonymous_forward],0
1171
	jmp	anonymous_ok
1172
      standard_label:
31 halyavin 1173
	cmp	byte [esi],'%'
157 heavyiron 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:
31 halyavin 1187
	xor	eax,eax
157 heavyiron 1188
	ret
1189
      get_counter_id:
31 halyavin 1190
	mov	eax,1
157 heavyiron 1191
	ret
1192
      get_timestamp_id:
31 halyavin 1193
	mov	eax,2
157 heavyiron 1194
	ret
1195
      get_org_origin_id:
31 halyavin 1196
	mov	eax,3
157 heavyiron 1197
	ret
1198
      get_predefined_id:
31 halyavin 1199
	cmp	ecx,2
157 heavyiron 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:
31 halyavin 1211
	xor	ebx,ebx
157 heavyiron 1212
	mov	eax,2166136261
1213
	mov	ebp,16777619
1214
      hash_label:
31 halyavin 1215
	xor	al,[esi+ebx]
157 heavyiron 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:
31 halyavin 1231
	mov	edx,[ebx]
157 heavyiron 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:
31 halyavin 1248
	mov	esi,ebx
157 heavyiron 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:
31 halyavin 1259
	add	esp,4
157 heavyiron 1260
	pop	edi
1261
	mov	eax,[eax+4]
1262
	ret
1263
      extend_tree:
31 halyavin 1264
	mov	edx,[free_additional_memory]
157 heavyiron 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:
31 halyavin 1281
	mov	ecx,edx
157 heavyiron 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:
31 halyavin 1291
	cmp	al,'$'
340 heavyiron 1292
	jne	check_for_reserved_word
1293
	cmp	ecx,1
157 heavyiron 1294
	jne	invalid_name
340 heavyiron 1295
      reserved_word:
1296
	mov	eax,0Fh
1297
	pop	edi
1298
	ret
1299
      check_for_reserved_word:
31 halyavin 1300
	call	get_instruction
157 heavyiron 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:
31 halyavin 1323
	mov	edx,[free_additional_memory]
157 heavyiron 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:
109 heavyiron 1340
	mov	eax,[labels_list]
157 heavyiron 1341
	mov	ecx,LABEL_STRUCTURE_SIZE shr 2
1342
      initialize_label:
109 heavyiron 1343
	sub	eax,4
157 heavyiron 1344
	mov	dword [eax],0
1345
	loop	initialize_label
1346
	mov	[labels_list],eax
1347
	ret
1348
31 halyavin 1349
 
109 heavyiron 1350
>