fasm/SOURCE/PARSER.INC

1471 lines
27 KiB
PHP
Raw Permalink Normal View History

2000-06-19 12:00:00 +00:00
2003-01-10 12:00:00 +00:00
; flat assembler core
2022-02-21 10:44:51 +01:00
; Copyright (c) 1999-2022, Tomasz Grysztar.
2000-06-19 12:00:00 +00:00
; All rights reserved.
parser:
mov eax,[memory_end]
mov [labels_list],eax
2003-01-10 12:00:00 +00:00
mov eax,[additional_memory]
mov [free_additional_memory],eax
2002-08-04 12:00:00 +00:00
xor eax,eax
mov [current_locals_prefix],eax
mov [anonymous_reverse],eax
mov [anonymous_forward],eax
2004-01-31 12:00:00 +00:00
mov [hash_tree],eax
2006-05-07 12:00:00 +00:00
mov [blocks_stack],eax
2009-06-13 12:00:00 +00:00
mov [parsed_lines],eax
2003-09-16 12:00:00 +00:00
mov esi,[memory_start]
mov edi,[source_start]
2005-03-12 12:00:00 +00:00
parser_loop:
2000-06-19 12:00:00 +00:00
mov [current_line],esi
2005-03-12 12:00:00 +00:00
lea eax,[edi+100h]
2006-05-07 12:00:00 +00:00
cmp eax,[labels_list]
2000-06-19 12:00:00 +00:00
jae out_of_memory
2005-03-12 12:00:00 +00:00
cmp byte [esi+16],0
je empty_line
2009-06-13 12:00:00 +00:00
cmp byte [esi+16],3Bh
je empty_line
2002-01-18 12:00:00 +00:00
mov al,0Fh
stos byte [edi]
mov eax,esi
stos dword [edi]
2009-06-13 12:00:00 +00:00
inc [parsed_lines]
2003-07-24 12:00:00 +00:00
add esi,16
2006-05-07 12:00:00 +00:00
parse_line:
2012-04-17 12:00:00 +00:00
mov [formatter_symbols_allowed],0
2015-10-19 12:00:00 +00:00
mov [decorator_symbols_allowed],0
2000-06-19 12:00:00 +00:00
cmp byte [esi],1Ah
jne empty_instruction
2002-01-18 12:00:00 +00:00
push edi
2004-01-31 12:00:00 +00:00
add esi,2
movzx ecx,byte [esi-1]
2000-06-19 12:00:00 +00:00
cmp byte [esi+ecx],':'
je simple_label
2004-01-31 12:00:00 +00:00
cmp byte [esi+ecx],'='
2000-06-19 12:00:00 +00:00
je constant_label
2006-05-07 12:00:00 +00:00
call get_instruction
jnc main_instruction_identified
2004-01-31 12:00:00 +00:00
cmp byte [esi+ecx],1Ah
2006-05-07 12:00:00 +00:00
jne no_data_label
2004-01-31 12:00:00 +00:00
push esi ecx
lea esi,[esi+ecx+2]
movzx ecx,byte [esi-1]
2009-06-13 12:00:00 +00:00
call get_data_directive
2002-01-18 12:00:00 +00:00
jnc data_label
2000-06-19 12:00:00 +00:00
pop ecx esi
2006-05-07 12:00:00 +00:00
no_data_label:
2009-06-13 12:00:00 +00:00
call get_data_directive
jnc main_instruction_identified
2000-06-19 12:00:00 +00:00
pop edi
2001-10-17 12:00:00 +00:00
sub esi,2
2006-05-07 12:00:00 +00:00
xor bx,bx
call parse_line_contents
jmp parse_next_line
simple_label:
pop edi
call identify_label
2012-09-21 12:00:00 +00:00
cmp byte [esi+1],':'
je block_label
2006-05-07 12:00:00 +00:00
mov byte [edi],2
inc edi
stos dword [edi]
inc esi
xor al,al
stos byte [edi]
jmp parse_line
2012-09-21 12:00:00 +00:00
block_label:
mov byte [edi],4
inc edi
stos dword [edi]
add esi,2
jmp parse_line
2000-06-19 12:00:00 +00:00
constant_label:
pop edi
2004-01-31 12:00:00 +00:00
call get_label_id
2000-06-19 12:00:00 +00:00
mov byte [edi],3
inc edi
stos dword [edi]
xor al,al
stos byte [edi]
inc esi
2006-05-07 12:00:00 +00:00
xor bx,bx
call parse_line_contents
jmp parse_next_line
2000-06-19 12:00:00 +00:00
data_label:
2009-06-13 12:00:00 +00:00
pop ecx edx
2000-06-19 12:00:00 +00:00
pop edi
2009-06-13 12:00:00 +00:00
push eax ebx esi
mov esi,edx
2004-01-31 12:00:00 +00:00
movzx ecx,byte [esi-1]
2000-06-19 12:00:00 +00:00
call identify_label
mov byte [edi],2
inc edi
stos dword [edi]
2009-06-13 12:00:00 +00:00
pop esi ebx eax
2000-06-19 12:00:00 +00:00
stos byte [edi]
2002-01-18 12:00:00 +00:00
push edi
2006-05-07 12:00:00 +00:00
main_instruction_identified:
2000-06-19 12:00:00 +00:00
pop edi
2006-05-07 12:00:00 +00:00
mov dl,al
mov al,1
stos byte [edi]
mov ax,bx
stos word [edi]
mov al,dl
stos byte [edi]
2012-04-17 12:00:00 +00:00
cmp bx,if_directive-instruction_handler
2006-05-07 12:00:00 +00:00
je parse_block
2012-04-17 12:00:00 +00:00
cmp bx,repeat_directive-instruction_handler
2006-05-07 12:00:00 +00:00
je parse_block
2012-04-17 12:00:00 +00:00
cmp bx,while_directive-instruction_handler
2006-05-07 12:00:00 +00:00
je parse_block
2012-04-17 12:00:00 +00:00
cmp bx,end_directive-instruction_handler
2006-05-07 12:00:00 +00:00
je parse_end_directive
2012-04-17 12:00:00 +00:00
cmp bx,else_directive-instruction_handler
2006-05-07 12:00:00 +00:00
je parse_else
2012-04-17 12:00:00 +00:00
cmp bx,assert_directive-instruction_handler
je parse_assert
2006-05-07 12:00:00 +00:00
common_parse:
call parse_line_contents
jmp parse_next_line
empty_instruction:
lods byte [esi]
or al,al
jz parse_next_line
cmp al,':'
je invalid_name
dec esi
2012-04-17 12:00:00 +00:00
mov [parenthesis_stack],0
2006-05-07 12:00:00 +00:00
call parse_argument
jmp parse_next_line
empty_line:
2009-06-13 12:00:00 +00:00
add esi,16
skip_rest_of_line:
call skip_foreign_line
2006-05-07 12:00:00 +00:00
parse_next_line:
cmp esi,[source_start]
jb parser_loop
source_parsed:
cmp [blocks_stack],0
je blocks_stack_ok
pop eax
pop [current_line]
jmp missing_end_directive
blocks_stack_ok:
2000-06-19 12:00:00 +00:00
xor al,al
stos byte [edi]
2006-05-07 12:00:00 +00:00
add edi,0Fh
and edi,not 0Fh
mov [code_start],edi
2000-06-19 12:00:00 +00:00
ret
2006-05-07 12:00:00 +00:00
parse_block:
mov eax,esp
2016-12-08 12:00:00 +00:00
sub eax,[stack_limit]
cmp eax,100h
2006-05-07 12:00:00 +00:00
jb stack_overflow
push [current_line]
mov ax,bx
shl eax,16
push eax
inc [blocks_stack]
2012-04-17 12:00:00 +00:00
cmp bx,if_directive-instruction_handler
2006-05-07 12:00:00 +00:00
je parse_if
2012-04-17 12:00:00 +00:00
cmp bx,while_directive-instruction_handler
2006-05-07 12:00:00 +00:00
je parse_while
call parse_line_contents
jmp parse_next_line
parse_end_directive:
2002-01-18 12:00:00 +00:00
cmp byte [esi],1Ah
2006-05-07 12:00:00 +00:00
jne common_parse
push edi
2002-01-18 12:00:00 +00:00
inc esi
movzx ecx,byte [esi]
2005-08-08 12:00:00 +00:00
inc esi
2006-05-07 12:00:00 +00:00
call get_instruction
pop edi
jnc parse_end_block
sub esi,2
jmp common_parse
parse_end_block:
mov dl,al
mov al,1
2004-01-31 12:00:00 +00:00
stos byte [edi]
2006-05-07 12:00:00 +00:00
mov ax,bx
stos word [edi]
mov al,dl
2004-01-31 12:00:00 +00:00
stos byte [edi]
2006-05-07 12:00:00 +00:00
lods byte [esi]
or al,al
jnz extra_characters_on_line
2012-04-17 12:00:00 +00:00
cmp bx,if_directive-instruction_handler
2006-05-07 12:00:00 +00:00
je close_parsing_block
2012-04-17 12:00:00 +00:00
cmp bx,repeat_directive-instruction_handler
2006-05-07 12:00:00 +00:00
je close_parsing_block
2012-04-17 12:00:00 +00:00
cmp bx,while_directive-instruction_handler
2006-05-07 12:00:00 +00:00
je close_parsing_block
jmp parse_next_line
close_parsing_block:
cmp [blocks_stack],0
je unexpected_instruction
cmp bx,[esp+2]
jne unexpected_instruction
dec [blocks_stack]
pop eax edx
2012-04-17 12:00:00 +00:00
cmp bx,if_directive-instruction_handler
2006-05-07 12:00:00 +00:00
jne parse_next_line
test al,1100b
jz parse_next_line
test al,10000b
jnz parse_next_line
sub edi,8
jmp parse_next_line
parse_if:
push edi
call parse_line_contents
xor al,al
2000-06-19 12:00:00 +00:00
stos byte [edi]
2006-05-07 12:00:00 +00:00
xchg esi,[esp]
mov edi,esi
call preevaluate_logical_expression
pop esi
cmp al,'0'
je parse_false_condition_block
cmp al,'1'
je parse_true_condition_block
or byte [esp],10000b
jmp parse_next_line
parse_while:
push edi
call parse_line_contents
2002-01-18 12:00:00 +00:00
xor al,al
stos byte [edi]
2006-05-07 12:00:00 +00:00
xchg esi,[esp]
mov edi,esi
call preevaluate_logical_expression
pop esi
cmp al,'0'
je parse_false_condition_block
cmp al,'1'
jne parse_next_line
stos byte [edi]
jmp parse_next_line
parse_false_condition_block:
or byte [esp],1
sub edi,4
jmp skip_parsing
parse_true_condition_block:
or byte [esp],100b
sub edi,4
jmp parse_next_line
parse_else:
cmp [blocks_stack],0
je unexpected_instruction
2012-04-17 12:00:00 +00:00
cmp word [esp+2],if_directive-instruction_handler
2006-05-07 12:00:00 +00:00
jne unexpected_instruction
lods byte [esi]
or al,al
jz parse_pure_else
cmp al,1Ah
jne extra_characters_on_line
2004-01-31 12:00:00 +00:00
push edi
movzx ecx,byte [esi]
inc esi
2006-05-07 12:00:00 +00:00
call get_instruction
jc extra_characters_on_line
2002-01-18 12:00:00 +00:00
pop edi
2012-04-17 12:00:00 +00:00
cmp bx,if_directive-instruction_handler
2006-05-07 12:00:00 +00:00
jne extra_characters_on_line
test byte [esp],100b
jnz skip_true_condition_else
2002-01-18 12:00:00 +00:00
mov dl,al
mov al,1
stos byte [edi]
mov ax,bx
stos word [edi]
mov al,dl
stos byte [edi]
2006-05-07 12:00:00 +00:00
jmp parse_if
2012-04-17 12:00:00 +00:00
parse_assert:
push edi
call parse_line_contents
xor al,al
stos byte [edi]
xchg esi,[esp]
mov edi,esi
call preevaluate_logical_expression
pop esi
or al,al
jz parse_next_line
stos byte [edi]
jmp parse_next_line
2006-05-07 12:00:00 +00:00
skip_true_condition_else:
sub edi,4
or byte [esp],1
jmp skip_parsing_contents
parse_pure_else:
bts dword [esp],1
jc unexpected_instruction
test byte [esp],100b
jz parse_next_line
sub edi,4
or byte [esp],1
jmp skip_parsing
skip_parsing:
cmp esi,[source_start]
jae source_parsed
mov [current_line],esi
add esi,16
skip_parsing_line:
cmp byte [esi],1Ah
jne skip_parsing_contents
inc esi
movzx ecx,byte [esi]
inc esi
cmp byte [esi+ecx],':'
je skip_parsing_label
push edi
call get_instruction
pop edi
jnc skip_parsing_instruction
add esi,ecx
jmp skip_parsing_contents
skip_parsing_label:
lea esi,[esi+ecx+1]
jmp skip_parsing_line
skip_parsing_instruction:
2012-04-17 12:00:00 +00:00
cmp bx,if_directive-instruction_handler
2006-05-07 12:00:00 +00:00
je skip_parsing_block
2012-04-17 12:00:00 +00:00
cmp bx,repeat_directive-instruction_handler
2006-05-07 12:00:00 +00:00
je skip_parsing_block
2012-04-17 12:00:00 +00:00
cmp bx,while_directive-instruction_handler
2006-05-07 12:00:00 +00:00
je skip_parsing_block
2012-04-17 12:00:00 +00:00
cmp bx,end_directive-instruction_handler
2006-05-07 12:00:00 +00:00
je skip_parsing_end_directive
2012-04-17 12:00:00 +00:00
cmp bx,else_directive-instruction_handler
2006-05-07 12:00:00 +00:00
je skip_parsing_else
skip_parsing_contents:
lods byte [esi]
or al,al
jz skip_parsing
cmp al,1Ah
je skip_parsing_symbol
cmp al,3Bh
je skip_parsing_symbol
cmp al,22h
je skip_parsing_string
jmp skip_parsing_contents
skip_parsing_symbol:
lods byte [esi]
movzx eax,al
add esi,eax
jmp skip_parsing_contents
skip_parsing_string:
lods dword [esi]
add esi,eax
jmp skip_parsing_contents
skip_parsing_block:
mov eax,esp
2016-12-08 12:00:00 +00:00
sub eax,[stack_limit]
cmp eax,100h
2006-05-07 12:00:00 +00:00
jb stack_overflow
push [current_line]
mov ax,bx
shl eax,16
push eax
inc [blocks_stack]
jmp skip_parsing_contents
skip_parsing_end_directive:
cmp byte [esi],1Ah
jne skip_parsing_contents
push edi
inc esi
movzx ecx,byte [esi]
inc esi
call get_instruction
pop edi
jnc skip_parsing_end_block
add esi,ecx
jmp skip_parsing_contents
skip_parsing_end_block:
lods byte [esi]
or al,al
jnz extra_characters_on_line
2012-04-17 12:00:00 +00:00
cmp bx,if_directive-instruction_handler
2006-05-07 12:00:00 +00:00
je close_skip_parsing_block
2012-04-17 12:00:00 +00:00
cmp bx,repeat_directive-instruction_handler
2006-05-07 12:00:00 +00:00
je close_skip_parsing_block
2012-04-17 12:00:00 +00:00
cmp bx,while_directive-instruction_handler
2006-05-07 12:00:00 +00:00
je close_skip_parsing_block
jmp skip_parsing
close_skip_parsing_block:
cmp [blocks_stack],0
je unexpected_instruction
cmp bx,[esp+2]
jne unexpected_instruction
dec [blocks_stack]
pop eax edx
test al,1
jz skip_parsing
2012-04-17 12:00:00 +00:00
cmp bx,if_directive-instruction_handler
2006-05-07 12:00:00 +00:00
jne parse_next_line
test al,10000b
jz parse_next_line
mov al,0Fh
stos byte [edi]
mov eax,[current_line]
stos dword [edi]
2009-06-13 12:00:00 +00:00
inc [parsed_lines]
2012-04-17 12:00:00 +00:00
mov eax,1 + (end_directive-instruction_handler) shl 8
2006-05-07 12:00:00 +00:00
stos dword [edi]
2012-04-17 12:00:00 +00:00
mov eax,1 + (if_directive-instruction_handler) shl 8
2006-05-07 12:00:00 +00:00
stos dword [edi]
jmp parse_next_line
skip_parsing_else:
cmp [blocks_stack],0
je unexpected_instruction
2012-04-17 12:00:00 +00:00
cmp word [esp+2],if_directive-instruction_handler
2006-05-07 12:00:00 +00:00
jne unexpected_instruction
lods byte [esi]
or al,al
jz skip_parsing_pure_else
cmp al,1Ah
jne extra_characters_on_line
push edi
movzx ecx,byte [esi]
inc esi
call get_instruction
jc extra_characters_on_line
pop edi
2012-04-17 12:00:00 +00:00
cmp bx,if_directive-instruction_handler
2006-05-07 12:00:00 +00:00
jne extra_characters_on_line
mov al,[esp]
test al,1
jz skip_parsing_contents
test al,100b
jnz skip_parsing_contents
test al,10000b
jnz parse_else_if
xor al,al
mov [esp],al
mov al,0Fh
stos byte [edi]
mov eax,[current_line]
stos dword [edi]
2009-06-13 12:00:00 +00:00
inc [parsed_lines]
2006-05-07 12:00:00 +00:00
parse_else_if:
2012-04-17 12:00:00 +00:00
mov eax,1 + (if_directive-instruction_handler) shl 8
2006-05-07 12:00:00 +00:00
stos dword [edi]
jmp parse_if
skip_parsing_pure_else:
bts dword [esp],1
jc unexpected_instruction
mov al,[esp]
test al,1
jz skip_parsing
test al,100b
jnz skip_parsing
and al,not 1
or al,1000b
mov [esp],al
jmp parse_next_line
parse_line_contents:
mov [parenthesis_stack],0
parse_instruction_arguments:
2012-04-17 12:00:00 +00:00
cmp bx,prefix_instruction-instruction_handler
2006-05-07 12:00:00 +00:00
je allow_embedded_instruction
2012-04-17 12:00:00 +00:00
cmp bx,times_directive-instruction_handler
2006-05-07 12:00:00 +00:00
je parse_times_directive
2012-04-17 12:00:00 +00:00
cmp bx,end_directive-instruction_handler
2006-05-07 12:00:00 +00:00
je allow_embedded_instruction
2012-04-17 12:00:00 +00:00
cmp bx,label_directive-instruction_handler
2002-01-18 12:00:00 +00:00
je parse_label_directive
2012-04-17 12:00:00 +00:00
cmp bx,segment_directive-instruction_handler
je parse_segment_directive
cmp bx,load_directive-instruction_handler
2004-01-31 12:00:00 +00:00
je parse_load_directive
2012-04-17 12:00:00 +00:00
cmp bx,extrn_directive-instruction_handler
2003-01-10 12:00:00 +00:00
je parse_extrn_directive
2012-04-17 12:00:00 +00:00
cmp bx,public_directive-instruction_handler
2002-11-14 12:00:00 +00:00
je parse_public_directive
2012-04-17 12:00:00 +00:00
cmp bx,section_directive-instruction_handler
je parse_formatter_argument
cmp bx,format_directive-instruction_handler
je parse_formatter_argument
cmp bx,data_directive-instruction_handler
je parse_formatter_argument
jmp parse_argument
parse_formatter_argument:
or [formatter_symbols_allowed],-1
2006-05-07 12:00:00 +00:00
parse_argument:
lea eax,[edi+100h]
cmp eax,[labels_list]
jae out_of_memory
2000-06-19 12:00:00 +00:00
lods byte [esi]
cmp al,':'
2001-10-17 12:00:00 +00:00
je instruction_separator
cmp al,','
2000-06-19 12:00:00 +00:00
je separator
cmp al,'='
2012-04-17 12:00:00 +00:00
je expression_comparator
2000-06-19 12:00:00 +00:00
cmp al,'|'
je separator
cmp al,'&'
je separator
cmp al,'~'
je separator
cmp al,'>'
je greater
cmp al,'<'
je less
cmp al,')'
2005-06-14 12:00:00 +00:00
je close_parenthesis
2000-06-19 12:00:00 +00:00
or al,al
2006-05-07 12:00:00 +00:00
jz contents_parsed
2000-06-19 12:00:00 +00:00
cmp al,'['
je address_argument
2000-07-06 12:00:00 +00:00
cmp al,']'
je separator
2002-11-14 12:00:00 +00:00
cmp al,'{'
2015-10-19 12:00:00 +00:00
je open_decorator
2002-11-14 12:00:00 +00:00
cmp al,'}'
2015-10-19 12:00:00 +00:00
je close_decorator
2002-11-14 12:00:00 +00:00
cmp al,'#'
je unallowed_character
2003-12-08 12:00:00 +00:00
cmp al,'`'
je unallowed_character
2013-03-30 12:00:00 +00:00
cmp al,3Bh
je foreign_argument
2015-10-19 12:00:00 +00:00
cmp [decorator_symbols_allowed],0
je not_a_separator
cmp al,'-'
je separator
not_a_separator:
2000-06-19 12:00:00 +00:00
dec esi
cmp al,1Ah
2001-08-23 12:00:00 +00:00
jne expression_argument
2000-06-19 12:00:00 +00:00
push edi
2002-01-18 12:00:00 +00:00
mov edi,directive_operators
call get_operator
or al,al
jnz operator_argument
inc esi
movzx ecx,byte [esi]
2000-06-19 12:00:00 +00:00
inc esi
2002-01-18 12:00:00 +00:00
call get_symbol
jnc symbol_argument
2000-06-19 12:00:00 +00:00
cmp ecx,1
jne check_argument
cmp byte [esi],'?'
jne check_argument
pop edi
movs byte [edi],[esi]
jmp argument_parsed
2013-03-30 12:00:00 +00:00
foreign_argument:
dec esi
call skip_foreign_line
jmp contents_parsed
2002-01-18 12:00:00 +00:00
symbol_argument:
pop edi
stos word [edi]
2019-11-28 12:32:08 +01:00
cmp byte [esi],'+'
jne argument_parsed
and ax,0F0FFh
cmp ax,6010h
jne argument_parsed
movs byte [edi],[esi]
2002-01-18 12:00:00 +00:00
jmp argument_parsed
operator_argument:
pop edi
2002-05-22 12:00:00 +00:00
cmp al,85h
je ptr_argument
2002-01-18 12:00:00 +00:00
stos byte [edi]
2012-04-17 12:00:00 +00:00
cmp al,8Ch
je forced_expression
2005-06-14 12:00:00 +00:00
cmp al,81h
je forced_parenthesis
2019-12-05 12:35:34 +01:00
cmp al,80h
je parse_at_operator
2005-03-12 12:00:00 +00:00
cmp al,82h
2005-06-14 12:00:00 +00:00
je parse_from_operator
2002-11-14 12:00:00 +00:00
cmp al,89h
je parse_label_operator
2012-04-17 12:00:00 +00:00
cmp al,0F8h
je forced_expression
2002-11-14 12:00:00 +00:00
jmp argument_parsed
2012-04-17 12:00:00 +00:00
instruction_separator:
stos byte [edi]
2006-05-07 12:00:00 +00:00
allow_embedded_instruction:
cmp byte [esi],1Ah
jne parse_argument
push edi
inc esi
movzx ecx,byte [esi]
inc esi
call get_instruction
jnc embedded_instruction
2009-06-13 12:00:00 +00:00
call get_data_directive
jnc embedded_instruction
2006-05-07 12:00:00 +00:00
pop edi
sub esi,2
jmp parse_argument
embedded_instruction:
pop edi
mov dl,al
mov al,1
stos byte [edi]
mov ax,bx
stos word [edi]
mov al,dl
stos byte [edi]
jmp parse_instruction_arguments
parse_times_directive:
mov al,'('
stos byte [edi]
call convert_expression
mov al,')'
stos byte [edi]
cmp byte [esi],':'
jne allow_embedded_instruction
movs byte [edi],[esi]
jmp allow_embedded_instruction
2012-04-17 12:00:00 +00:00
parse_segment_directive:
or [formatter_symbols_allowed],-1
2006-05-07 12:00:00 +00:00
parse_label_directive:
cmp byte [esi],1Ah
jne argument_parsed
push esi
inc esi
movzx ecx,byte [esi]
inc esi
call identify_label
pop ebx
cmp eax,0Fh
je non_label_identified
mov byte [edi],2
inc edi
stos dword [edi]
xor al,al
stos byte [edi]
jmp argument_parsed
non_label_identified:
mov esi,ebx
jmp argument_parsed
parse_load_directive:
cmp byte [esi],1Ah
jne argument_parsed
push esi
inc esi
movzx ecx,byte [esi]
inc esi
call get_label_id
pop ebx
cmp eax,0Fh
je non_label_identified
mov byte [edi],2
inc edi
stos dword [edi]
xor al,al
stos byte [edi]
jmp argument_parsed
2002-11-14 12:00:00 +00:00
parse_public_directive:
cmp byte [esi],1Ah
2006-05-07 12:00:00 +00:00
jne parse_argument
2003-01-10 12:00:00 +00:00
inc esi
2002-11-14 12:00:00 +00:00
push esi
2003-01-10 12:00:00 +00:00
movzx ecx,byte [esi]
2005-08-08 12:00:00 +00:00
inc esi
2009-06-13 12:00:00 +00:00
push esi ecx
push edi
2012-04-17 12:00:00 +00:00
or [formatter_symbols_allowed],-1
2009-06-13 12:00:00 +00:00
call get_symbol
2012-04-17 12:00:00 +00:00
mov [formatter_symbols_allowed],0
2009-06-13 12:00:00 +00:00
pop edi
jc parse_public_label
cmp al,1Dh
jne parse_public_label
add esp,12
stos word [edi]
jmp parse_public_directive
parse_public_label:
pop ecx esi
2003-01-10 12:00:00 +00:00
mov al,2
stos byte [edi]
call get_label_id
stos dword [edi]
mov ax,8600h
stos word [edi]
pop ebx
push ebx esi edi
mov edi,directive_operators
call get_operator
pop edi edx ebx
cmp al,86h
je argument_parsed
mov esi,edx
xchg esi,ebx
movzx ecx,byte [esi]
inc esi
2002-11-14 12:00:00 +00:00
mov ax,'('
stos word [edi]
mov eax,ecx
stos dword [edi]
rep movs byte [edi],[esi]
xor al,al
stos byte [edi]
2003-01-10 12:00:00 +00:00
xchg esi,ebx
jmp argument_parsed
parse_extrn_directive:
cmp byte [esi],22h
je parse_quoted_extrn
cmp byte [esi],1Ah
2006-05-07 12:00:00 +00:00
jne parse_argument
2003-01-10 12:00:00 +00:00
push esi
movzx ecx,byte [esi+1]
add esi,2
mov ax,'('
stos word [edi]
mov eax,ecx
stos dword [edi]
rep movs byte [edi],[esi]
mov ax,8600h
stos word [edi]
2002-11-14 12:00:00 +00:00
pop esi
parse_label_operator:
cmp byte [esi],1Ah
jne argument_parsed
inc esi
movzx ecx,byte [esi]
2005-08-08 12:00:00 +00:00
inc esi
2002-11-14 12:00:00 +00:00
mov al,2
stos byte [edi]
call get_label_id
stos dword [edi]
xor al,al
stos byte [edi]
2002-01-18 12:00:00 +00:00
jmp argument_parsed
2005-06-14 12:00:00 +00:00
parse_from_operator:
cmp byte [esi],22h
2019-12-05 12:35:34 +01:00
je argument_parsed
parse_at_operator:
cmp byte [esi],':'
je argument_parsed
jmp forced_multipart_expression
2003-01-10 12:00:00 +00:00
parse_quoted_extrn:
inc esi
mov ax,'('
stos word [edi]
lods dword [esi]
mov ecx,eax
stos dword [edi]
rep movs byte [edi],[esi]
xor al,al
stos byte [edi]
push esi edi
mov edi,directive_operators
call get_operator
mov edx,esi
pop edi esi
cmp al,86h
jne argument_parsed
stos byte [edi]
mov esi,edx
jmp parse_label_operator
2002-05-22 12:00:00 +00:00
ptr_argument:
call parse_address
2005-02-12 12:00:00 +00:00
jmp address_parsed
2000-06-19 12:00:00 +00:00
check_argument:
push esi ecx
sub esi,2
mov edi,single_operand_operators
call get_operator
pop ecx esi
or al,al
2001-08-23 12:00:00 +00:00
jnz not_instruction
2000-06-19 12:00:00 +00:00
call get_instruction
2006-05-07 12:00:00 +00:00
jnc embedded_instruction
2009-06-13 12:00:00 +00:00
call get_data_directive
jnc embedded_instruction
2001-08-23 12:00:00 +00:00
not_instruction:
2000-06-19 12:00:00 +00:00
pop edi
sub esi,2
2001-08-23 12:00:00 +00:00
expression_argument:
2002-01-18 12:00:00 +00:00
cmp byte [esi],22h
2001-08-23 12:00:00 +00:00
jne not_string
2002-01-18 12:00:00 +00:00
mov eax,[esi+1]
lea ebx,[esi+5+eax]
2001-08-23 12:00:00 +00:00
push ebx ecx esi edi
2012-09-21 12:00:00 +00:00
call parse_expression
2001-08-23 12:00:00 +00:00
pop eax edx ecx ebx
cmp esi,ebx
2012-09-21 12:00:00 +00:00
jne expression_argument_parsed
2001-08-23 12:00:00 +00:00
mov edi,eax
mov esi,edx
2002-01-18 12:00:00 +00:00
string_argument:
2001-08-23 12:00:00 +00:00
inc esi
mov ax,'('
stos word [edi]
2002-01-18 12:00:00 +00:00
lods dword [esi]
mov ecx,eax
2000-10-07 12:00:00 +00:00
stos dword [edi]
2002-01-18 12:00:00 +00:00
shr ecx,1
jnc string_movsb_ok
movs byte [edi],[esi]
string_movsb_ok:
shr ecx,1
jnc string_movsw_ok
movs word [edi],[esi]
string_movsw_ok:
rep movs dword [edi],[esi]
2000-06-19 12:00:00 +00:00
xor al,al
stos byte [edi]
2012-09-21 12:00:00 +00:00
jmp expression_argument_parsed
parse_expression:
mov al,'('
stos byte [edi]
call convert_expression
mov al,')'
stos byte [edi]
ret
2001-08-23 12:00:00 +00:00
not_string:
2000-06-19 12:00:00 +00:00
cmp byte [esi],'('
2004-07-22 12:00:00 +00:00
jne expression
2005-08-08 12:00:00 +00:00
mov eax,esp
2016-12-08 12:00:00 +00:00
sub eax,[stack_limit]
cmp eax,100h
2005-08-08 12:00:00 +00:00
jb stack_overflow
2000-06-19 12:00:00 +00:00
push esi edi
inc esi
2015-10-19 12:00:00 +00:00
mov al,91h
2000-06-19 12:00:00 +00:00
stos byte [edi]
inc [parenthesis_stack]
2006-05-07 12:00:00 +00:00
jmp parse_argument
2012-04-17 12:00:00 +00:00
expression_comparator:
stos byte [edi]
jmp forced_expression
greater:
cmp byte [esi],'='
jne separator
inc esi
mov al,0F2h
jmp separator
less:
cmp byte [edi-1],0F6h
je separator
cmp byte [esi],'>'
je not_equal
cmp byte [esi],'='
jne separator
inc esi
mov al,0F3h
jmp separator
not_equal:
inc esi
mov al,0F1h
jmp expression_comparator
2004-07-22 12:00:00 +00:00
expression:
2012-09-21 12:00:00 +00:00
call parse_expression
jmp expression_argument_parsed
2002-01-18 12:00:00 +00:00
forced_expression:
2012-04-17 12:00:00 +00:00
xor al,al
xchg al,[formatter_symbols_allowed]
push eax
2012-09-21 12:00:00 +00:00
call parse_expression
forced_expression_parsed:
2012-04-17 12:00:00 +00:00
pop eax
mov [formatter_symbols_allowed],al
2002-11-14 12:00:00 +00:00
jmp argument_parsed
2012-09-21 12:00:00 +00:00
forced_multipart_expression:
xor al,al
xchg al,[formatter_symbols_allowed]
push eax
call parse_expression
cmp byte [esi],':'
jne forced_expression_parsed
movs byte [edi],[esi]
call parse_expression
jmp forced_expression_parsed
2000-06-19 12:00:00 +00:00
address_argument:
2002-05-22 12:00:00 +00:00
call parse_address
lods byte [esi]
cmp al,']'
2006-05-07 12:00:00 +00:00
je address_parsed
2015-11-09 12:00:00 +00:00
cmp al,','
je divided_address
2006-05-07 12:00:00 +00:00
dec esi
mov al,')'
stos byte [edi]
jmp argument_parsed
2015-11-09 12:00:00 +00:00
divided_address:
mov ax,'),'
stos word [edi]
jmp expression
2005-02-12 12:00:00 +00:00
address_parsed:
mov al,']'
2002-05-22 12:00:00 +00:00
stos byte [edi]
jmp argument_parsed
parse_address:
2000-06-19 12:00:00 +00:00
mov al,'['
stos byte [edi]
cmp word [esi],021Ah
jne convert_address
2002-01-18 12:00:00 +00:00
push esi
add esi,4
lea ebx,[esi+1]
cmp byte [esi],':'
pop esi
jne convert_address
2000-06-19 12:00:00 +00:00
add esi,2
mov ecx,2
2002-01-18 12:00:00 +00:00
push ebx edi
2000-06-19 12:00:00 +00:00
call get_symbol
2002-01-18 12:00:00 +00:00
pop edi esi
2006-05-07 12:00:00 +00:00
jc unknown_segment_prefix
2000-06-19 12:00:00 +00:00
cmp al,10h
2006-05-07 12:00:00 +00:00
jne unknown_segment_prefix
2000-06-19 12:00:00 +00:00
mov al,ah
and ah,11110000b
2015-10-19 12:00:00 +00:00
cmp ah,30h
2006-05-07 12:00:00 +00:00
jne unknown_segment_prefix
2015-10-19 12:00:00 +00:00
add al,30h
2000-06-19 12:00:00 +00:00
stos byte [edi]
2006-05-07 12:00:00 +00:00
jmp convert_address
unknown_segment_prefix:
sub esi,5
2000-06-19 12:00:00 +00:00
convert_address:
push edi
2002-01-18 12:00:00 +00:00
mov edi,address_sizes
2009-06-13 12:00:00 +00:00
call get_operator
2000-06-19 12:00:00 +00:00
pop edi
2009-06-13 12:00:00 +00:00
or al,al
jz convert_expression
2000-06-19 12:00:00 +00:00
add al,70h
stos byte [edi]
2002-05-22 12:00:00 +00:00
jmp convert_expression
2005-06-14 12:00:00 +00:00
forced_parenthesis:
cmp byte [esi],'('
jne argument_parsed
inc esi
2015-10-19 12:00:00 +00:00
mov al,91h
2005-06-14 12:00:00 +00:00
jmp separator
2002-11-14 12:00:00 +00:00
unallowed_character:
mov al,0FFh
jmp separator
2015-10-19 12:00:00 +00:00
open_decorator:
inc [decorator_symbols_allowed]
jmp separator
close_decorator:
dec [decorator_symbols_allowed]
jmp separator
2005-06-14 12:00:00 +00:00
close_parenthesis:
2015-10-19 12:00:00 +00:00
mov al,92h
2000-06-19 12:00:00 +00:00
separator:
stos byte [edi]
argument_parsed:
cmp [parenthesis_stack],0
2006-05-07 12:00:00 +00:00
je parse_argument
2000-06-19 12:00:00 +00:00
dec [parenthesis_stack]
2000-08-10 12:00:00 +00:00
add esp,8
2000-06-19 12:00:00 +00:00
jmp argument_parsed
2012-09-21 12:00:00 +00:00
expression_argument_parsed:
2000-06-19 12:00:00 +00:00
cmp [parenthesis_stack],0
2006-05-07 12:00:00 +00:00
je parse_argument
2000-06-19 12:00:00 +00:00
cmp byte [esi],')'
jne argument_parsed
dec [parenthesis_stack]
pop edi esi
2004-07-22 12:00:00 +00:00
jmp expression
2006-05-07 12:00:00 +00:00
contents_parsed:
2000-06-19 12:00:00 +00:00
cmp [parenthesis_stack],0
2009-06-13 12:00:00 +00:00
je contents_ok
dec [parenthesis_stack]
add esp,8
jmp contents_parsed
contents_ok:
2000-06-19 12:00:00 +00:00
ret
2002-11-14 12:00:00 +00:00
2006-05-07 12:00:00 +00:00
identify_label:
cmp byte [esi],'.'
je local_label_name
call get_label_id
cmp eax,10h
jb label_identified
or ebx,ebx
jz anonymous_label_name
dec ebx
mov [current_locals_prefix],ebx
label_identified:
ret
anonymous_label_name:
cmp byte [esi-1],'@'
je anonymous_label_name_ok
mov eax,0Fh
anonymous_label_name_ok:
ret
local_label_name:
call get_label_id
ret
2002-11-14 12:00:00 +00:00
get_operator:
cmp byte [esi],1Ah
2003-06-28 12:00:00 +00:00
jne get_simple_operator
2002-11-14 12:00:00 +00:00
mov edx,esi
push ebp
inc esi
lods byte [esi]
movzx ebp,al
push edi
mov ecx,ebp
call lower_case
pop edi
check_operator:
2003-01-10 12:00:00 +00:00
mov esi,converted
2002-11-14 12:00:00 +00:00
movzx ecx,byte [edi]
jecxz no_operator
inc edi
mov ebx,edi
add ebx,ecx
cmp ecx,ebp
jne next_operator
repe cmps byte [esi],[edi]
je operator_found
2012-04-17 12:00:00 +00:00
jb no_operator
2002-11-14 12:00:00 +00:00
next_operator:
mov edi,ebx
inc edi
jmp check_operator
no_operator:
mov esi,edx
2003-06-28 12:00:00 +00:00
mov ecx,ebp
2002-11-14 12:00:00 +00:00
pop ebp
no_simple_operator:
xor al,al
ret
operator_found:
lea esi,[edx+2+ebp]
2003-06-28 12:00:00 +00:00
mov ecx,ebp
2002-11-14 12:00:00 +00:00
pop ebp
mov al,[edi]
ret
2003-06-28 12:00:00 +00:00
get_simple_operator:
2002-11-14 12:00:00 +00:00
mov al,[esi]
2003-01-10 12:00:00 +00:00
cmp al,22h
je no_simple_operator
2003-06-28 12:00:00 +00:00
simple_operator:
2002-11-14 12:00:00 +00:00
cmp byte [edi],1
jb no_simple_operator
ja simple_next_operator
cmp al,[edi+1]
je simple_operator_found
simple_next_operator:
movzx ecx,byte [edi]
lea edi,[edi+1+ecx+1]
2003-06-28 12:00:00 +00:00
jmp simple_operator
2002-11-14 12:00:00 +00:00
simple_operator_found:
inc esi
mov al,[edi+2]
ret
get_symbol:
2009-06-13 12:00:00 +00:00
push esi
2002-11-14 12:00:00 +00:00
mov ebp,ecx
call lower_case
2009-06-13 12:00:00 +00:00
mov ecx,ebp
cmp cl,11
ja no_symbol
2015-10-19 12:00:00 +00:00
sub cl,1
2009-06-13 12:00:00 +00:00
jc no_symbol
movzx ebx,word [symbols+ecx*4]
add ebx,symbols
movzx edx,word [symbols+ecx*4+2]
2002-11-14 12:00:00 +00:00
scan_symbols:
2009-06-13 12:00:00 +00:00
or edx,edx
2002-11-14 12:00:00 +00:00
jz no_symbol
2009-06-13 12:00:00 +00:00
mov eax,edx
shr eax,1
lea edi,[ebp+2]
imul eax,edi
lea edi,[ebx+eax]
mov esi,converted
2002-11-14 12:00:00 +00:00
mov ecx,ebp
repe cmps byte [esi],[edi]
2009-06-13 12:00:00 +00:00
ja symbols_up
jb symbols_down
2012-04-17 12:00:00 +00:00
mov ax,[edi]
cmp al,18h
jb symbol_ok
2015-10-19 12:00:00 +00:00
cmp al,1Fh
je decorator_symbol
2012-04-17 12:00:00 +00:00
cmp [formatter_symbols_allowed],0
je no_symbol
symbol_ok:
2009-06-13 12:00:00 +00:00
pop esi
add esi,ebp
clc
ret
2015-10-19 12:00:00 +00:00
decorator_symbol:
cmp [decorator_symbols_allowed],0
jne symbol_ok
2002-11-14 12:00:00 +00:00
no_symbol:
2009-06-13 12:00:00 +00:00
pop esi
2002-11-14 12:00:00 +00:00
mov ecx,ebp
stc
ret
2009-06-13 12:00:00 +00:00
symbols_down:
shr edx,1
jmp scan_symbols
symbols_up:
lea ebx,[edi+ecx+2]
shr edx,1
adc edx,-1
jmp scan_symbols
get_data_directive:
push esi
mov ebp,ecx
call lower_case
mov ecx,ebp
cmp cl,4
ja no_instruction
sub cl,2
jc no_instruction
movzx ebx,word [data_directives+ecx*4]
add ebx,data_directives
movzx edx,word [data_directives+ecx*4+2]
jmp scan_instructions
2002-11-14 12:00:00 +00:00
get_instruction:
2009-06-13 12:00:00 +00:00
push esi
2002-11-14 12:00:00 +00:00
mov ebp,ecx
call lower_case
mov ecx,ebp
2019-08-01 20:31:24 +02:00
cmp cl,17
2002-11-14 12:00:00 +00:00
ja no_instruction
sub cl,2
jc no_instruction
2009-06-13 12:00:00 +00:00
movzx ebx,word [instructions+ecx*4]
add ebx,instructions
movzx edx,word [instructions+ecx*4+2]
2002-11-14 12:00:00 +00:00
scan_instructions:
2009-06-13 12:00:00 +00:00
or edx,edx
2002-11-14 12:00:00 +00:00
jz no_instruction
2009-06-13 12:00:00 +00:00
mov eax,edx
shr eax,1
lea edi,[ebp+3]
imul eax,edi
lea edi,[ebx+eax]
mov esi,converted
2002-11-14 12:00:00 +00:00
mov ecx,ebp
repe cmps byte [esi],[edi]
2009-06-13 12:00:00 +00:00
ja instructions_up
jb instructions_down
pop esi
add esi,ebp
mov al,[edi]
mov bx,[edi+1]
clc
ret
2002-11-14 12:00:00 +00:00
no_instruction:
2009-06-13 12:00:00 +00:00
pop esi
2002-11-14 12:00:00 +00:00
mov ecx,ebp
stc
ret
2009-06-13 12:00:00 +00:00
instructions_down:
shr edx,1
jmp scan_instructions
instructions_up:
lea ebx,[edi+ecx+3]
shr edx,1
adc edx,-1
jmp scan_instructions
2002-11-14 12:00:00 +00:00
get_label_id:
cmp ecx,100h
jae name_too_long
cmp byte [esi],'@'
je anonymous_label
cmp byte [esi],'.'
jne standard_label
2004-04-03 12:00:00 +00:00
cmp byte [esi+1],'.'
2002-11-14 12:00:00 +00:00
je standard_label
cmp [current_locals_prefix],0
je standard_label
push edi
2006-05-07 12:00:00 +00:00
mov edi,[additional_memory_end]
2004-01-31 12:00:00 +00:00
sub edi,2
sub edi,ecx
2002-11-14 12:00:00 +00:00
push ecx esi
mov esi,[current_locals_prefix]
lods byte [esi]
movzx ecx,al
2004-01-31 12:00:00 +00:00
sub edi,ecx
2006-05-07 12:00:00 +00:00
cmp edi,[free_additional_memory]
2004-01-31 12:00:00 +00:00
jb out_of_memory
mov word [edi],0
add edi,2
mov ebx,edi
2002-11-14 12:00:00 +00:00
rep movs byte [edi],[esi]
pop esi ecx
add al,cl
jc name_too_long
rep movs byte [edi],[esi]
pop edi
2006-05-07 12:00:00 +00:00
push ebx esi
2002-11-14 12:00:00 +00:00
movzx ecx,al
2003-09-16 12:00:00 +00:00
mov byte [ebx-1],al
2002-11-14 12:00:00 +00:00
mov esi,ebx
call get_label_id
2006-05-07 12:00:00 +00:00
pop esi ebx
cmp ebx,[eax+24]
jne composed_label_id_ok
lea edx,[ebx-2]
mov [additional_memory_end],edx
composed_label_id_ok:
2002-11-14 12:00:00 +00:00
ret
anonymous_label:
cmp ecx,2
jne standard_label
mov al,[esi+1]
mov ebx,characters
xlat byte [ebx]
cmp al,'@'
je new_anonymous
cmp al,'b'
je anonymous_back
cmp al,'r'
je anonymous_back
cmp al,'f'
jne standard_label
add esi,2
mov eax,[anonymous_forward]
or eax,eax
jnz anonymous_ok
2004-09-12 12:00:00 +00:00
mov eax,[current_line]
mov [error_line],eax
2006-05-07 12:00:00 +00:00
call allocate_label
2002-11-14 12:00:00 +00:00
mov [anonymous_forward],eax
anonymous_ok:
2003-01-19 12:00:00 +00:00
xor ebx,ebx
2005-03-12 12:00:00 +00:00
ret
2002-11-14 12:00:00 +00:00
anonymous_back:
mov eax,[anonymous_reverse]
2009-06-13 12:00:00 +00:00
add esi,2
2012-04-17 12:00:00 +00:00
or eax,eax
jz bogus_anonymous
jmp anonymous_ok
bogus_anonymous:
call allocate_label
mov [anonymous_reverse],eax
2003-01-19 12:00:00 +00:00
jmp anonymous_ok
2002-11-14 12:00:00 +00:00
new_anonymous:
add esi,2
mov eax,[anonymous_forward]
or eax,eax
jnz new_anonymous_ok
2006-05-07 12:00:00 +00:00
call allocate_label
2002-11-14 12:00:00 +00:00
new_anonymous_ok:
mov [anonymous_reverse],eax
mov [anonymous_forward],0
2003-01-19 12:00:00 +00:00
jmp anonymous_ok
2002-11-14 12:00:00 +00:00
standard_label:
2003-12-08 12:00:00 +00:00
cmp byte [esi],'%'
je get_predefined_id
2005-03-12 12:00:00 +00:00
cmp byte [esi],'$'
2012-04-17 12:00:00 +00:00
je current_address_label
cmp byte [esi],'?'
2002-11-14 12:00:00 +00:00
jne find_label
2012-04-17 12:00:00 +00:00
cmp ecx,1
jne find_label
inc esi
mov eax,0Fh
ret
current_address_label:
2019-12-05 12:35:34 +01:00
cmp ecx,3
je current_address_label_3_characters
2005-03-12 12:00:00 +00:00
ja find_label
inc esi
2019-12-05 12:35:34 +01:00
cmp ecx,1
jbe get_current_offset_id
2005-03-12 12:00:00 +00:00
inc esi
cmp byte [esi-1],'$'
je get_org_origin_id
2019-12-05 12:35:34 +01:00
cmp byte [esi-1],'%'
je get_file_offset_id
2014-12-07 12:00:00 +00:00
sub esi,2
2002-11-14 12:00:00 +00:00
jmp find_label
get_current_offset_id:
xor eax,eax
ret
get_counter_id:
mov eax,1
ret
2003-12-08 12:00:00 +00:00
get_timestamp_id:
mov eax,2
ret
2005-03-12 12:00:00 +00:00
get_org_origin_id:
mov eax,3
ret
2019-12-05 12:35:34 +01:00
get_file_offset_id:
mov eax,4
ret
current_address_label_3_characters:
cmp word [esi+1],'%%'
jne find_label
add esi,3
get_actual_file_offset_id:
mov eax,5
ret
2003-12-08 12:00:00 +00:00
get_predefined_id:
cmp ecx,2
ja find_label
inc esi
cmp cl,1
je get_counter_id
lods byte [esi]
mov ebx,characters
xlat [ebx]
cmp al,'t'
je get_timestamp_id
sub esi,2
2002-11-14 12:00:00 +00:00
find_label:
xor ebx,ebx
2004-01-31 12:00:00 +00:00
mov eax,2166136261
mov ebp,16777619
2002-11-14 12:00:00 +00:00
hash_label:
2004-01-31 12:00:00 +00:00
xor al,[esi+ebx]
mul ebp
2002-11-14 12:00:00 +00:00
inc bl
cmp bl,cl
jb hash_label
2004-01-31 12:00:00 +00:00
mov ebp,eax
shl eax,8
and ebp,0FFh shl 24
xor ebp,eax
2002-11-14 12:00:00 +00:00
or ebp,ebx
mov [label_hash],ebp
2004-01-31 12:00:00 +00:00
push edi esi
push ecx
mov ecx,32
mov ebx,hash_tree
follow_tree:
mov edx,[ebx]
or edx,edx
jz extend_tree
xor eax,eax
shl ebp,1
adc eax,0
lea ebx,[edx+eax*4]
dec ecx
jnz follow_tree
mov [label_leaf],ebx
pop edx
mov eax,[ebx]
or eax,eax
jz add_label
2002-11-14 12:00:00 +00:00
mov ebx,esi
2004-01-31 12:00:00 +00:00
mov ebp,[label_hash]
2005-03-12 12:00:00 +00:00
compare_labels:
2004-01-31 12:00:00 +00:00
mov esi,ebx
mov ecx,edx
mov edi,[eax+4]
2006-05-07 12:00:00 +00:00
mov edi,[edi+24]
2004-01-31 12:00:00 +00:00
repe cmps byte [esi],[edi]
2005-03-12 12:00:00 +00:00
je label_found
mov eax,[eax]
or eax,eax
jnz compare_labels
jmp add_label
2004-01-31 12:00:00 +00:00
label_found:
add esp,4
pop edi
2006-05-07 12:00:00 +00:00
mov eax,[eax+4]
2004-01-31 12:00:00 +00:00
ret
extend_tree:
mov edx,[free_additional_memory]
lea eax,[edx+8]
cmp eax,[additional_memory_end]
ja out_of_memory
mov [free_additional_memory],eax
xor eax,eax
mov [edx],eax
mov [edx+4],eax
shl ebp,1
adc eax,0
mov [ebx],edx
lea ebx,[edx+eax*4]
dec ecx
jnz extend_tree
mov [label_leaf],ebx
pop edx
2002-11-14 12:00:00 +00:00
add_label:
2003-01-19 12:00:00 +00:00
mov ecx,edx
2002-11-14 12:00:00 +00:00
pop esi
2003-09-16 12:00:00 +00:00
cmp byte [esi-2],0
2002-11-14 12:00:00 +00:00
je label_name_ok
mov al,[esi]
cmp al,30h
jb name_first_char_ok
cmp al,39h
2014-12-07 12:00:00 +00:00
jbe numeric_name
2002-11-14 12:00:00 +00:00
name_first_char_ok:
cmp al,'$'
2009-06-13 12:00:00 +00:00
jne check_for_reserved_word
2014-12-07 12:00:00 +00:00
numeric_name:
add esi,ecx
2009-06-13 12:00:00 +00:00
reserved_word:
mov eax,0Fh
pop edi
ret
2002-11-14 12:00:00 +00:00
check_for_reserved_word:
call get_instruction
jnc reserved_word
2009-06-13 12:00:00 +00:00
call get_data_directive
2002-11-14 12:00:00 +00:00
jnc reserved_word
call get_symbol
jnc reserved_word
2003-06-28 12:00:00 +00:00
sub esi,2
mov edi,operators
call get_operator
or al,al
jnz reserved_word
mov edi,single_operand_operators
call get_operator
or al,al
jnz reserved_word
mov edi,directive_operators
call get_operator
or al,al
jnz reserved_word
inc esi
movzx ecx,byte [esi]
inc esi
2002-11-14 12:00:00 +00:00
label_name_ok:
2005-03-12 12:00:00 +00:00
mov edx,[free_additional_memory]
2006-05-07 12:00:00 +00:00
lea eax,[edx+8]
2005-03-12 12:00:00 +00:00
cmp eax,[additional_memory_end]
ja out_of_memory
mov [free_additional_memory],eax
2003-01-19 12:00:00 +00:00
mov ebx,esi
2002-11-14 12:00:00 +00:00
add esi,ecx
2005-03-12 12:00:00 +00:00
mov eax,[label_leaf]
mov edi,[eax]
mov [edx],edi
2002-11-14 12:00:00 +00:00
mov [eax],edx
2006-05-07 12:00:00 +00:00
call allocate_label
mov [edx+4],eax
mov [eax+24],ebx
2002-11-14 12:00:00 +00:00
pop edi
2005-03-12 12:00:00 +00:00
ret
2006-05-07 12:00:00 +00:00
allocate_label:
mov eax,[labels_list]
mov ecx,LABEL_STRUCTURE_SIZE shr 2
initialize_label:
sub eax,4
mov dword [eax],0
loop initialize_label
mov [labels_list],eax
ret
2002-11-14 12:00:00 +00:00
2006-05-07 12:00:00 +00:00
LABEL_STRUCTURE_SIZE = 32