Subversion Repositories Kolibri OS

Rev

Rev 1242 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1242 Rev 2287
Line 1... Line 1...
1
; flat assembler core
1
; flat assembler core
2
; Copyright (c) 1999-2009, Tomasz Grysztar.
2
; Copyright (c) 1999-2011, Tomasz Grysztar.
3
; All rights reserved.
3
; All rights reserved.
Line 4... Line 4...
4
 
4
 
5
parser:
5
parser:
6
	mov	eax,[memory_end]
6
	mov	eax,[memory_end]
Line 31... Line 31...
31
	stos	dword [edi]
31
	stos	dword [edi]
32
	inc	[parsed_lines]
32
	inc	[parsed_lines]
33
	add	esi,16
33
	add	esi,16
34
      parse_line:
34
      parse_line:
35
	cmp	byte [esi],1Ah
35
	mov	[formatter_symbols_allowed],0
-
 
36
	cmp	byte [esi],1Ah
36
	jne	empty_instruction
37
	jne	empty_instruction
37
	push	edi
38
	push	edi
38
	add	esi,2
39
	add	esi,2
39
	movzx	ecx,byte [esi-1]
40
	movzx	ecx,byte [esi-1]
40
	cmp	byte [esi+ecx],':'
41
	cmp	byte [esi+ecx],':'
Line 459... Line 460...
459
	je	allow_embedded_instruction
460
	je	allow_embedded_instruction
460
	cmp	bx,label_directive-instruction_handler
461
	cmp	bx,label_directive-instruction_handler
461
	je	parse_label_directive
462
	je	parse_label_directive
462
	cmp	bx,segment_directive-instruction_handler
463
	cmp	bx,segment_directive-instruction_handler
463
	je	parse_label_directive
464
	je	parse_segment_directive
464
	cmp	bx,load_directive-instruction_handler
465
	cmp	bx,load_directive-instruction_handler
465
	je	parse_load_directive
466
	je	parse_load_directive
466
	cmp	bx,extrn_directive-instruction_handler
467
	cmp	bx,extrn_directive-instruction_handler
467
	je	parse_extrn_directive
468
	je	parse_extrn_directive
468
	cmp	bx,public_directive-instruction_handler
469
	cmp	bx,public_directive-instruction_handler
469
	je	parse_public_directive
470
	je	parse_public_directive
470
      parse_argument:
471
	cmp	bx,section_directive-instruction_handler
-
 
472
	je	parse_formatter_argument
-
 
473
	cmp	bx,format_directive-instruction_handler
-
 
474
	je	parse_formatter_argument
-
 
475
	cmp	bx,data_directive-instruction_handler
-
 
476
	je	parse_formatter_argument
-
 
477
	jmp	parse_argument
-
 
478
      parse_formatter_argument:
-
 
479
	or	[formatter_symbols_allowed],-1
-
 
480
      parse_argument:
471
	lea	eax,[edi+100h]
481
	lea	eax,[edi+100h]
472
	cmp	eax,[labels_list]
482
	cmp	eax,[labels_list]
473
	jae	out_of_memory
483
	jae	out_of_memory
474
	lods	byte [esi]
484
	lods	byte [esi]
475
	cmp	al,':'
485
	cmp	al,':'
Line 534... Line 544...
534
	je	ptr_argument
544
	je	ptr_argument
535
	stos	byte [edi]
545
	stos	byte [edi]
536
	cmp	al,80h
546
	cmp	al,80h
537
	je	forced_expression
547
	je	forced_expression
538
	cmp	al,81h
548
	cmp	al,8Ch
-
 
549
	je	forced_expression
-
 
550
	cmp	al,81h
539
	je	forced_parenthesis
551
	je	forced_parenthesis
540
	cmp	al,82h
552
	cmp	al,82h
541
	je	parse_from_operator
553
	je	parse_from_operator
542
	cmp	al,89h
554
	cmp	al,89h
543
	je	parse_label_operator
555
	je	parse_label_operator
Line 575... Line 587...
575
	cmp	byte [esi],':'
587
	cmp	byte [esi],':'
576
	jne	allow_embedded_instruction
588
	jne	allow_embedded_instruction
577
	movs	byte [edi],[esi]
589
	movs	byte [edi],[esi]
578
	jmp	allow_embedded_instruction
590
	jmp	allow_embedded_instruction
579
      parse_label_directive:
591
      parse_segment_directive:
-
 
592
	or	[formatter_symbols_allowed],-1
-
 
593
      parse_label_directive:
580
	cmp	byte [esi],1Ah
594
	cmp	byte [esi],1Ah
581
	jne	argument_parsed
595
	jne	argument_parsed
582
	push	esi
596
	push	esi
583
	inc	esi
597
	inc	esi
584
	movzx	ecx,byte [esi]
598
	movzx	ecx,byte [esi]
Line 621... Line 635...
621
	movzx	ecx,byte [esi]
635
	movzx	ecx,byte [esi]
622
	inc	esi
636
	inc	esi
623
	push	esi ecx
637
	push	esi ecx
624
	push	edi
638
	push	edi
625
	call	get_symbol
639
	or	[formatter_symbols_allowed],-1
-
 
640
	call	get_symbol
626
	pop	edi
641
	mov	[formatter_symbols_allowed],0
-
 
642
	pop	edi
627
	jc	parse_public_label
643
	jc	parse_public_label
628
	cmp	al,1Dh
644
	cmp	al,1Dh
629
	jne	parse_public_label
645
	jne	parse_public_label
630
	add	esp,12
646
	add	esp,12
631
	stos	word [edi]
647
	stos	word [edi]
Line 785... Line 801...
785
	mov	al,')'
801
	mov	al,')'
786
	stos	byte [edi]
802
	stos	byte [edi]
787
	jmp	expression_parsed
803
	jmp	expression_parsed
788
      forced_expression:
804
      forced_expression:
789
	mov	al,'('
805
	xor	al,al
-
 
806
	xchg	al,[formatter_symbols_allowed]
-
 
807
	push	eax
-
 
808
	mov	al,'('
790
	stos	byte [edi]
809
	stos	byte [edi]
791
	call	convert_expression
810
	call	convert_expression
792
	mov	al,')'
811
	mov	al,')'
793
	stos	byte [edi]
812
	stos	byte [edi]
794
	jmp	argument_parsed
813
	pop	eax
-
 
814
	mov	[formatter_symbols_allowed],al
-
 
815
	jmp	argument_parsed
795
      address_argument:
816
      address_argument:
796
	call	parse_address
817
	call	parse_address
797
	lods	byte [esi]
818
	lods	byte [esi]
798
	cmp	al,']'
819
	cmp	al,']'
799
	je	address_parsed
820
	je	address_parsed
Line 1007... Line 1028...
1007
	mov	ecx,ebp
1028
	mov	ecx,ebp
1008
	repe	cmps byte [esi],[edi]
1029
	repe	cmps byte [esi],[edi]
1009
	ja	symbols_up
1030
	ja	symbols_up
1010
	jb	symbols_down
1031
	jb	symbols_down
1011
	pop	esi
1032
	mov	ax,[edi]
-
 
1033
 
-
 
1034
	cmp	al,18h
-
 
1035
	jb	symbol_ok
-
 
1036
	cmp	[formatter_symbols_allowed],0
-
 
1037
	je	no_symbol
-
 
1038
 
-
 
1039
      symbol_ok:
-
 
1040
	pop	esi
1012
	add	esi,ebp
1041
	add	esi,ebp
1013
	mov	ax,[edi]
1042
	clc
1014
	clc
-
 
1015
	ret
1043
	ret
1016
      no_symbol:
1044
      no_symbol:
1017
	pop	esi
1045
	pop	esi
1018
	mov	ecx,ebp
1046
	mov	ecx,ebp
1019
	stc
1047
	stc
Line 1045... Line 1073...
1045
	push	esi
1073
	push	esi
1046
	mov	ebp,ecx
1074
	mov	ebp,ecx
1047
	call	lower_case
1075
	call	lower_case
1048
	mov	ecx,ebp
1076
	mov	ecx,ebp
1049
	cmp	cl,11
1077
	cmp	cl,16
1050
	ja	no_instruction
1078
	ja	no_instruction
1051
	sub	cl,2
1079
	sub	cl,2
1052
	jc	no_instruction
1080
	jc	no_instruction
1053
	movzx	ebx,word [instructions+ecx*4]
1081
	movzx	ebx,word [instructions+ecx*4]
1054
	add	ebx,instructions
1082
	add	ebx,instructions
1055
	movzx	edx,word [instructions+ecx*4+2]
1083
	movzx	edx,word [instructions+ecx*4+2]
Line 1155... Line 1183...
1155
	xor	ebx,ebx
1183
	xor	ebx,ebx
1156
	ret
1184
	ret
1157
      anonymous_back:
1185
      anonymous_back:
1158
	mov	eax,[anonymous_reverse]
1186
	mov	eax,[anonymous_reverse]
1159
	or	eax,eax
1187
	add	esi,2
1160
	jz	new_anonymous
-
 
1161
	add	esi,2
-
 
1162
	jmp	anonymous_ok
1188
	or	eax,eax
-
 
1189
	jz	bogus_anonymous
-
 
1190
	jmp	anonymous_ok
-
 
1191
      bogus_anonymous:
-
 
1192
	call	allocate_label
-
 
1193
	mov	[anonymous_reverse],eax
-
 
1194
	jmp	anonymous_ok
1163
      new_anonymous:
1195
      new_anonymous:
1164
	add	esi,2
1196
	add	esi,2
1165
	mov	eax,[anonymous_forward]
1197
	mov	eax,[anonymous_forward]
1166
	or	eax,eax
1198
	or	eax,eax
1167
	jnz	new_anonymous_ok
1199
	jnz	new_anonymous_ok
Line 1173... Line 1205...
1173
      standard_label:
1205
      standard_label:
1174
	cmp	byte [esi],'%'
1206
	cmp	byte [esi],'%'
1175
	je	get_predefined_id
1207
	je	get_predefined_id
1176
	cmp	byte [esi],'$'
1208
	cmp	byte [esi],'$'
1177
	jne	find_label
1209
	je	current_address_label
-
 
1210
	cmp	byte [esi],'?'
-
 
1211
	jne	find_label
1178
	cmp	ecx,2
1212
	cmp	ecx,1
-
 
1213
	jne	find_label
-
 
1214
	inc	esi
-
 
1215
	mov	eax,0Fh
-
 
1216
	ret
-
 
1217
      current_address_label:
-
 
1218
	cmp	ecx,2
1179
	ja	find_label
1219
	ja	find_label
1180
	inc	esi
1220
	inc	esi
1181
	jb	get_current_offset_id
1221
	jb	get_current_offset_id
1182
	inc	esi
1222
	inc	esi
1183
	cmp	byte [esi-1],'$'
1223
	cmp	byte [esi-1],'$'