Subversion Repositories Kolibri OS

Rev

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