2006-07-28 17:39:16 +04:00
|
|
|
|
|
|
|
; flat assembler core
|
|
|
|
; Copyright (c) 1999-2006, Tomasz Grysztar.
|
|
|
|
; All rights reserved.
|
|
|
|
|
|
|
|
parser:
|
2006-09-22 19:55:59 +04:00
|
|
|
mov eax,[memory_end]
|
|
|
|
mov [labels_list],eax
|
|
|
|
mov eax,[additional_memory]
|
|
|
|
mov [free_additional_memory],eax
|
|
|
|
xor eax,eax
|
|
|
|
mov [current_locals_prefix],eax
|
|
|
|
mov [anonymous_reverse],eax
|
|
|
|
mov [anonymous_forward],eax
|
|
|
|
mov [hash_tree],eax
|
|
|
|
mov [blocks_stack],eax
|
2006-12-21 09:34:09 +03:00
|
|
|
mov [parsed_lines],eax
|
2006-09-22 19:55:59 +04:00
|
|
|
mov esi,[memory_start]
|
|
|
|
mov edi,[source_start]
|
2006-07-28 17:39:16 +04:00
|
|
|
parser_loop:
|
2006-09-22 19:55:59 +04:00
|
|
|
mov [current_line],esi
|
|
|
|
lea eax,[edi+100h]
|
|
|
|
cmp eax,[labels_list]
|
|
|
|
jae out_of_memory
|
|
|
|
cmp byte [esi+16],0
|
|
|
|
je empty_line
|
|
|
|
mov al,0Fh
|
|
|
|
stos byte [edi]
|
|
|
|
mov eax,esi
|
|
|
|
stos dword [edi]
|
2006-12-21 09:34:09 +03:00
|
|
|
inc [parsed_lines]
|
2006-09-22 19:55:59 +04:00
|
|
|
add esi,16
|
2006-07-28 17:39:16 +04:00
|
|
|
parse_line:
|
2006-09-22 19:55:59 +04:00
|
|
|
cmp byte [esi],1Ah
|
|
|
|
jne empty_instruction
|
|
|
|
push edi
|
|
|
|
add esi,2
|
|
|
|
movzx ecx,byte [esi-1]
|
|
|
|
cmp byte [esi+ecx],':'
|
|
|
|
je simple_label
|
|
|
|
cmp byte [esi+ecx],'='
|
|
|
|
je constant_label
|
|
|
|
call get_instruction
|
|
|
|
jnc main_instruction_identified
|
|
|
|
cmp byte [esi+ecx],1Ah
|
|
|
|
jne no_data_label
|
|
|
|
push esi ecx
|
|
|
|
lea esi,[esi+ecx+2]
|
|
|
|
movzx ecx,byte [esi-1]
|
|
|
|
call get_data_directive
|
|
|
|
jnc data_label
|
|
|
|
pop ecx esi
|
2006-07-28 17:39:16 +04:00
|
|
|
no_data_label:
|
2006-09-22 19:55:59 +04:00
|
|
|
call get_data_directive
|
|
|
|
jnc main_instruction_identified
|
|
|
|
pop edi
|
|
|
|
sub esi,2
|
|
|
|
xor bx,bx
|
|
|
|
call parse_line_contents
|
|
|
|
jmp parse_next_line
|
2006-07-28 17:39:16 +04:00
|
|
|
simple_label:
|
2006-09-22 19:55:59 +04:00
|
|
|
pop edi
|
|
|
|
call identify_label
|
|
|
|
mov byte [edi],2
|
|
|
|
inc edi
|
|
|
|
stos dword [edi]
|
|
|
|
inc esi
|
|
|
|
xor al,al
|
|
|
|
stos byte [edi]
|
|
|
|
jmp parse_line
|
2006-07-28 17:39:16 +04:00
|
|
|
constant_label:
|
2006-09-22 19:55:59 +04:00
|
|
|
pop edi
|
|
|
|
call get_label_id
|
|
|
|
mov byte [edi],3
|
|
|
|
inc edi
|
|
|
|
stos dword [edi]
|
|
|
|
xor al,al
|
|
|
|
stos byte [edi]
|
|
|
|
inc esi
|
|
|
|
xor bx,bx
|
|
|
|
call parse_line_contents
|
|
|
|
jmp parse_next_line
|
2006-07-28 17:39:16 +04:00
|
|
|
data_label:
|
2006-09-22 19:55:59 +04:00
|
|
|
pop ecx edx
|
|
|
|
pop edi
|
|
|
|
push eax ebx esi
|
|
|
|
mov esi,edx
|
|
|
|
movzx ecx,byte [esi-1]
|
|
|
|
call identify_label
|
|
|
|
mov byte [edi],2
|
|
|
|
inc edi
|
|
|
|
stos dword [edi]
|
|
|
|
pop esi ebx eax
|
|
|
|
stos byte [edi]
|
|
|
|
push edi
|
2006-07-28 17:39:16 +04:00
|
|
|
main_instruction_identified:
|
2006-09-22 19:55:59 +04:00
|
|
|
pop edi
|
|
|
|
mov dl,al
|
|
|
|
mov al,1
|
|
|
|
stos byte [edi]
|
|
|
|
mov ax,bx
|
|
|
|
stos word [edi]
|
|
|
|
mov al,dl
|
|
|
|
stos byte [edi]
|
|
|
|
cmp bx,if_directive-assembler
|
|
|
|
je parse_block
|
|
|
|
cmp bx,repeat_directive-assembler
|
|
|
|
je parse_block
|
|
|
|
cmp bx,while_directive-assembler
|
|
|
|
je parse_block
|
|
|
|
cmp bx,end_directive-assembler
|
|
|
|
je parse_end_directive
|
|
|
|
cmp bx,else_directive-assembler
|
|
|
|
je parse_else
|
2006-07-28 17:39:16 +04:00
|
|
|
common_parse:
|
2006-09-22 19:55:59 +04:00
|
|
|
call parse_line_contents
|
|
|
|
jmp parse_next_line
|
2006-07-28 17:39:16 +04:00
|
|
|
empty_instruction:
|
2006-09-22 19:55:59 +04:00
|
|
|
lods byte [esi]
|
|
|
|
or al,al
|
|
|
|
jz parse_next_line
|
|
|
|
cmp al,':'
|
|
|
|
je invalid_name
|
|
|
|
cmp al,3Bh
|
|
|
|
je skip_preprocessed_symbol
|
|
|
|
dec esi
|
|
|
|
call parse_argument
|
|
|
|
jmp parse_next_line
|
2006-07-28 17:39:16 +04:00
|
|
|
skip_preprocessed_symbol:
|
2006-09-22 19:55:59 +04:00
|
|
|
lods byte [esi]
|
|
|
|
movzx eax,al
|
|
|
|
add esi,eax
|
2006-07-28 17:39:16 +04:00
|
|
|
skip_next:
|
2006-09-22 19:55:59 +04:00
|
|
|
lods byte [esi]
|
|
|
|
or al,al
|
|
|
|
jz parse_next_line
|
|
|
|
cmp al,1Ah
|
|
|
|
je skip_preprocessed_symbol
|
|
|
|
cmp al,3Bh
|
|
|
|
je skip_preprocessed_symbol
|
|
|
|
cmp al,22h
|
|
|
|
je skip_preprocessed_string
|
|
|
|
jmp skip_next
|
2006-07-28 17:39:16 +04:00
|
|
|
skip_preprocessed_string:
|
2006-09-22 19:55:59 +04:00
|
|
|
lods dword [esi]
|
|
|
|
add esi,eax
|
|
|
|
jmp skip_next
|
2006-07-28 17:39:16 +04:00
|
|
|
empty_line:
|
2006-09-22 19:55:59 +04:00
|
|
|
add esi,17
|
2006-07-28 17:39:16 +04:00
|
|
|
parse_next_line:
|
2006-09-22 19:55:59 +04:00
|
|
|
cmp esi,[source_start]
|
|
|
|
jb parser_loop
|
2006-07-28 17:39:16 +04:00
|
|
|
source_parsed:
|
2006-09-22 19:55:59 +04:00
|
|
|
cmp [blocks_stack],0
|
|
|
|
je blocks_stack_ok
|
|
|
|
pop eax
|
|
|
|
pop [current_line]
|
|
|
|
jmp missing_end_directive
|
2006-07-28 17:39:16 +04:00
|
|
|
blocks_stack_ok:
|
2006-09-22 19:55:59 +04:00
|
|
|
xor al,al
|
|
|
|
stos byte [edi]
|
|
|
|
mov eax,[error_line]
|
|
|
|
mov [current_line],eax
|
|
|
|
cmp [anonymous_forward],0
|
|
|
|
jne invalid_value
|
|
|
|
add edi,0Fh
|
|
|
|
and edi,not 0Fh
|
|
|
|
mov [code_start],edi
|
|
|
|
ret
|
2006-07-28 17:39:16 +04:00
|
|
|
parse_block:
|
2006-09-22 19:55:59 +04:00
|
|
|
mov eax,esp
|
|
|
|
sub eax,100h
|
|
|
|
jc stack_overflow
|
|
|
|
cmp eax,[stack_limit]
|
|
|
|
jb stack_overflow
|
|
|
|
push [current_line]
|
|
|
|
mov ax,bx
|
|
|
|
shl eax,16
|
|
|
|
push eax
|
|
|
|
inc [blocks_stack]
|
|
|
|
cmp bx,if_directive-assembler
|
|
|
|
je parse_if
|
|
|
|
cmp bx,while_directive-assembler
|
|
|
|
je parse_while
|
|
|
|
call parse_line_contents
|
|
|
|
jmp parse_next_line
|
2006-07-28 17:39:16 +04:00
|
|
|
parse_end_directive:
|
2006-09-22 19:55:59 +04:00
|
|
|
cmp byte [esi],1Ah
|
|
|
|
jne common_parse
|
|
|
|
push edi
|
|
|
|
inc esi
|
|
|
|
movzx ecx,byte [esi]
|
|
|
|
inc esi
|
|
|
|
call get_instruction
|
|
|
|
pop edi
|
|
|
|
jnc parse_end_block
|
|
|
|
sub esi,2
|
|
|
|
jmp common_parse
|
2006-07-28 17:39:16 +04:00
|
|
|
parse_end_block:
|
2006-09-22 19:55:59 +04:00
|
|
|
mov dl,al
|
|
|
|
mov al,1
|
|
|
|
stos byte [edi]
|
|
|
|
mov ax,bx
|
|
|
|
stos word [edi]
|
|
|
|
mov al,dl
|
|
|
|
stos byte [edi]
|
|
|
|
lods byte [esi]
|
|
|
|
or al,al
|
|
|
|
jnz extra_characters_on_line
|
|
|
|
cmp bx,if_directive-assembler
|
|
|
|
je close_parsing_block
|
|
|
|
cmp bx,repeat_directive-assembler
|
|
|
|
je close_parsing_block
|
|
|
|
cmp bx,while_directive-assembler
|
|
|
|
je close_parsing_block
|
|
|
|
jmp parse_next_line
|
2006-07-28 17:39:16 +04:00
|
|
|
close_parsing_block:
|
2006-09-22 19:55:59 +04:00
|
|
|
cmp [blocks_stack],0
|
|
|
|
je unexpected_instruction
|
|
|
|
cmp bx,[esp+2]
|
|
|
|
jne unexpected_instruction
|
|
|
|
dec [blocks_stack]
|
|
|
|
pop eax edx
|
|
|
|
cmp bx,if_directive-assembler
|
|
|
|
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
|
2006-07-28 17:39:16 +04:00
|
|
|
parse_if:
|
2006-09-22 19:55:59 +04:00
|
|
|
push edi
|
|
|
|
call parse_line_contents
|
|
|
|
xor al,al
|
|
|
|
stos byte [edi]
|
|
|
|
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
|
2006-07-28 17:39:16 +04:00
|
|
|
parse_while:
|
2006-09-22 19:55:59 +04:00
|
|
|
push edi
|
|
|
|
call parse_line_contents
|
|
|
|
xor al,al
|
|
|
|
stos byte [edi]
|
|
|
|
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
|
2006-07-28 17:39:16 +04:00
|
|
|
parse_false_condition_block:
|
2006-09-22 19:55:59 +04:00
|
|
|
or byte [esp],1
|
|
|
|
sub edi,4
|
|
|
|
jmp skip_parsing
|
2006-07-28 17:39:16 +04:00
|
|
|
parse_true_condition_block:
|
2006-09-22 19:55:59 +04:00
|
|
|
or byte [esp],100b
|
|
|
|
sub edi,4
|
|
|
|
jmp parse_next_line
|
2006-07-28 17:39:16 +04:00
|
|
|
parse_else:
|
2006-09-22 19:55:59 +04:00
|
|
|
cmp [blocks_stack],0
|
|
|
|
je unexpected_instruction
|
|
|
|
cmp word [esp+2],if_directive-assembler
|
|
|
|
jne unexpected_instruction
|
|
|
|
lods byte [esi]
|
|
|
|
or al,al
|
|
|
|
jz parse_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
|
|
|
|
cmp bx,if_directive-assembler
|
|
|
|
jne extra_characters_on_line
|
|
|
|
test byte [esp],100b
|
|
|
|
jnz skip_true_condition_else
|
|
|
|
mov dl,al
|
|
|
|
mov al,1
|
|
|
|
stos byte [edi]
|
|
|
|
mov ax,bx
|
|
|
|
stos word [edi]
|
|
|
|
mov al,dl
|
|
|
|
stos byte [edi]
|
|
|
|
jmp parse_if
|
2006-07-28 17:39:16 +04:00
|
|
|
skip_true_condition_else:
|
2006-09-22 19:55:59 +04:00
|
|
|
sub edi,4
|
|
|
|
or byte [esp],1
|
|
|
|
jmp skip_parsing_contents
|
2006-07-28 17:39:16 +04:00
|
|
|
parse_pure_else:
|
2006-09-22 19:55:59 +04:00
|
|
|
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
|
2006-07-28 17:39:16 +04:00
|
|
|
skip_parsing:
|
2006-09-22 19:55:59 +04:00
|
|
|
cmp esi,[source_start]
|
|
|
|
jae source_parsed
|
|
|
|
mov [current_line],esi
|
|
|
|
add esi,16
|
2006-07-28 17:39:16 +04:00
|
|
|
skip_parsing_line:
|
2006-09-22 19:55:59 +04:00
|
|
|
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
|
2006-07-28 17:39:16 +04:00
|
|
|
skip_parsing_label:
|
2006-09-22 19:55:59 +04:00
|
|
|
lea esi,[esi+ecx+1]
|
|
|
|
jmp skip_parsing_line
|
2006-07-28 17:39:16 +04:00
|
|
|
skip_parsing_instruction:
|
2006-09-22 19:55:59 +04:00
|
|
|
cmp bx,if_directive-assembler
|
|
|
|
je skip_parsing_block
|
|
|
|
cmp bx,repeat_directive-assembler
|
|
|
|
je skip_parsing_block
|
|
|
|
cmp bx,while_directive-assembler
|
|
|
|
je skip_parsing_block
|
|
|
|
cmp bx,end_directive-assembler
|
|
|
|
je skip_parsing_end_directive
|
|
|
|
cmp bx,else_directive-assembler
|
|
|
|
je skip_parsing_else
|
2006-07-28 17:39:16 +04:00
|
|
|
skip_parsing_contents:
|
2006-09-22 19:55:59 +04:00
|
|
|
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
|
2006-07-28 17:39:16 +04:00
|
|
|
skip_parsing_symbol:
|
2006-09-22 19:55:59 +04:00
|
|
|
lods byte [esi]
|
|
|
|
movzx eax,al
|
|
|
|
add esi,eax
|
|
|
|
jmp skip_parsing_contents
|
2006-07-28 17:39:16 +04:00
|
|
|
skip_parsing_string:
|
2006-09-22 19:55:59 +04:00
|
|
|
lods dword [esi]
|
|
|
|
add esi,eax
|
|
|
|
jmp skip_parsing_contents
|
2006-07-28 17:39:16 +04:00
|
|
|
skip_parsing_block:
|
2006-09-22 19:55:59 +04:00
|
|
|
mov eax,esp
|
|
|
|
sub eax,100h
|
|
|
|
jc stack_overflow
|
|
|
|
cmp eax,[stack_limit]
|
|
|
|
jb stack_overflow
|
|
|
|
push [current_line]
|
|
|
|
mov ax,bx
|
|
|
|
shl eax,16
|
|
|
|
push eax
|
|
|
|
inc [blocks_stack]
|
|
|
|
jmp skip_parsing_contents
|
2006-07-28 17:39:16 +04:00
|
|
|
skip_parsing_end_directive:
|
2006-09-22 19:55:59 +04:00
|
|
|
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
|
2006-07-28 17:39:16 +04:00
|
|
|
skip_parsing_end_block:
|
2006-09-22 19:55:59 +04:00
|
|
|
lods byte [esi]
|
|
|
|
or al,al
|
|
|
|
jnz extra_characters_on_line
|
|
|
|
cmp bx,if_directive-assembler
|
|
|
|
je close_skip_parsing_block
|
|
|
|
cmp bx,repeat_directive-assembler
|
|
|
|
je close_skip_parsing_block
|
|
|
|
cmp bx,while_directive-assembler
|
|
|
|
je close_skip_parsing_block
|
|
|
|
jmp skip_parsing
|
2006-07-28 17:39:16 +04:00
|
|
|
close_skip_parsing_block:
|
2006-09-22 19:55:59 +04:00
|
|
|
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
|
|
|
|
cmp bx,if_directive-assembler
|
|
|
|
jne parse_next_line
|
|
|
|
test al,10000b
|
|
|
|
jz parse_next_line
|
|
|
|
mov al,0Fh
|
|
|
|
stos byte [edi]
|
|
|
|
mov eax,[current_line]
|
|
|
|
stos dword [edi]
|
2006-12-21 09:34:09 +03:00
|
|
|
inc [parsed_lines]
|
2006-09-22 19:55:59 +04:00
|
|
|
mov eax,1 + (end_directive-assembler) shl 8
|
|
|
|
stos dword [edi]
|
|
|
|
mov eax,1 + (if_directive-assembler) shl 8
|
|
|
|
stos dword [edi]
|
|
|
|
jmp parse_next_line
|
2006-07-28 17:39:16 +04:00
|
|
|
skip_parsing_else:
|
2006-09-22 19:55:59 +04:00
|
|
|
cmp [blocks_stack],0
|
|
|
|
je unexpected_instruction
|
|
|
|
cmp word [esp+2],if_directive-assembler
|
|
|
|
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
|
|
|
|
cmp bx,if_directive-assembler
|
|
|
|
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]
|
2006-12-21 09:34:09 +03:00
|
|
|
inc [parsed_lines]
|
2006-07-28 17:39:16 +04:00
|
|
|
parse_else_if:
|
2006-09-22 19:55:59 +04:00
|
|
|
mov eax,1 + (if_directive-assembler) shl 8
|
|
|
|
stos dword [edi]
|
|
|
|
jmp parse_if
|
2006-07-28 17:39:16 +04:00
|
|
|
skip_parsing_pure_else:
|
2006-09-22 19:55:59 +04:00
|
|
|
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
|
2006-07-28 17:39:16 +04:00
|
|
|
|
|
|
|
parse_line_contents:
|
2006-09-22 19:55:59 +04:00
|
|
|
mov [parenthesis_stack],0
|
2006-07-28 17:39:16 +04:00
|
|
|
parse_instruction_arguments:
|
2006-09-22 19:55:59 +04:00
|
|
|
cmp bx,prefix_instruction-assembler
|
|
|
|
je allow_embedded_instruction
|
|
|
|
cmp bx,times_directive-assembler
|
|
|
|
je parse_times_directive
|
|
|
|
cmp bx,end_directive-assembler
|
|
|
|
je allow_embedded_instruction
|
|
|
|
cmp bx,label_directive-assembler
|
|
|
|
je parse_label_directive
|
|
|
|
cmp bx,segment_directive-assembler
|
|
|
|
je parse_label_directive
|
|
|
|
cmp bx,load_directive-assembler
|
|
|
|
je parse_load_directive
|
|
|
|
cmp bx,extrn_directive-assembler
|
|
|
|
je parse_extrn_directive
|
|
|
|
cmp bx,public_directive-assembler
|
|
|
|
je parse_public_directive
|
2006-07-28 17:39:16 +04:00
|
|
|
parse_argument:
|
2006-09-22 19:55:59 +04:00
|
|
|
lea eax,[edi+100h]
|
|
|
|
cmp eax,[labels_list]
|
|
|
|
jae out_of_memory
|
|
|
|
lods byte [esi]
|
|
|
|
cmp al,':'
|
|
|
|
je instruction_separator
|
|
|
|
cmp al,','
|
|
|
|
je separator
|
|
|
|
cmp al,'='
|
|
|
|
je separator
|
|
|
|
cmp al,'|'
|
|
|
|
je separator
|
|
|
|
cmp al,'&'
|
|
|
|
je separator
|
|
|
|
cmp al,'~'
|
|
|
|
je separator
|
|
|
|
cmp al,'>'
|
|
|
|
je greater
|
|
|
|
cmp al,'<'
|
|
|
|
je less
|
|
|
|
cmp al,')'
|
|
|
|
je close_parenthesis
|
|
|
|
or al,al
|
|
|
|
jz contents_parsed
|
|
|
|
cmp al,'['
|
|
|
|
je address_argument
|
|
|
|
cmp al,']'
|
|
|
|
je separator
|
|
|
|
cmp al,'{'
|
|
|
|
je unallowed_character
|
|
|
|
cmp al,'}'
|
|
|
|
je unallowed_character
|
|
|
|
cmp al,'#'
|
|
|
|
je unallowed_character
|
|
|
|
cmp al,'`'
|
|
|
|
je unallowed_character
|
|
|
|
dec esi
|
|
|
|
cmp al,1Ah
|
|
|
|
jne expression_argument
|
|
|
|
push edi
|
|
|
|
mov edi,directive_operators
|
|
|
|
call get_operator
|
|
|
|
or al,al
|
|
|
|
jnz operator_argument
|
|
|
|
inc esi
|
|
|
|
movzx ecx,byte [esi]
|
|
|
|
inc esi
|
|
|
|
call get_symbol
|
|
|
|
jnc symbol_argument
|
|
|
|
cmp ecx,1
|
|
|
|
jne check_argument
|
|
|
|
cmp byte [esi],'?'
|
|
|
|
jne check_argument
|
|
|
|
pop edi
|
|
|
|
movs byte [edi],[esi]
|
|
|
|
jmp argument_parsed
|
2006-07-28 17:39:16 +04:00
|
|
|
symbol_argument:
|
2006-09-22 19:55:59 +04:00
|
|
|
pop edi
|
|
|
|
stos word [edi]
|
|
|
|
jmp argument_parsed
|
2006-07-28 17:39:16 +04:00
|
|
|
operator_argument:
|
2006-09-22 19:55:59 +04:00
|
|
|
pop edi
|
|
|
|
cmp al,85h
|
|
|
|
je ptr_argument
|
|
|
|
stos byte [edi]
|
|
|
|
cmp al,80h
|
|
|
|
je forced_expression
|
|
|
|
cmp al,81h
|
|
|
|
je forced_parenthesis
|
|
|
|
cmp al,82h
|
|
|
|
je parse_from_operator
|
|
|
|
cmp al,89h
|
|
|
|
je parse_label_operator
|
|
|
|
jmp argument_parsed
|
2006-07-28 17:39:16 +04:00
|
|
|
allow_embedded_instruction:
|
2006-09-22 19:55:59 +04:00
|
|
|
cmp byte [esi],1Ah
|
|
|
|
jne parse_argument
|
|
|
|
push edi
|
|
|
|
inc esi
|
|
|
|
movzx ecx,byte [esi]
|
|
|
|
inc esi
|
|
|
|
call get_instruction
|
|
|
|
jnc embedded_instruction
|
|
|
|
call get_data_directive
|
|
|
|
jnc embedded_instruction
|
|
|
|
pop edi
|
|
|
|
sub esi,2
|
|
|
|
jmp parse_argument
|
2006-07-28 17:39:16 +04:00
|
|
|
embedded_instruction:
|
2006-09-22 19:55:59 +04:00
|
|
|
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
|
2006-07-28 17:39:16 +04:00
|
|
|
parse_times_directive:
|
2006-09-22 19:55:59 +04:00
|
|
|
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
|
2006-07-28 17:39:16 +04:00
|
|
|
parse_label_directive:
|
2006-09-22 19:55:59 +04:00
|
|
|
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
|
2006-07-28 17:39:16 +04:00
|
|
|
non_label_identified:
|
2006-09-22 19:55:59 +04:00
|
|
|
mov esi,ebx
|
|
|
|
jmp argument_parsed
|
2006-07-28 17:39:16 +04:00
|
|
|
parse_load_directive:
|
2006-09-22 19:55:59 +04:00
|
|
|
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
|
2006-07-28 17:39:16 +04:00
|
|
|
parse_public_directive:
|
2006-09-22 19:55:59 +04:00
|
|
|
cmp byte [esi],1Ah
|
|
|
|
jne parse_argument
|
|
|
|
inc esi
|
|
|
|
push esi
|
|
|
|
movzx ecx,byte [esi]
|
|
|
|
inc esi
|
|
|
|
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
|
|
|
|
mov ax,'('
|
|
|
|
stos word [edi]
|
|
|
|
mov eax,ecx
|
|
|
|
stos dword [edi]
|
|
|
|
rep movs byte [edi],[esi]
|
|
|
|
xor al,al
|
|
|
|
stos byte [edi]
|
|
|
|
xchg esi,ebx
|
|
|
|
jmp argument_parsed
|
2006-07-28 17:39:16 +04:00
|
|
|
parse_extrn_directive:
|
2006-09-22 19:55:59 +04:00
|
|
|
cmp byte [esi],22h
|
|
|
|
je parse_quoted_extrn
|
|
|
|
cmp byte [esi],1Ah
|
|
|
|
jne parse_argument
|
|
|
|
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]
|
|
|
|
pop esi
|
2006-07-28 17:39:16 +04:00
|
|
|
parse_label_operator:
|
2006-09-22 19:55:59 +04:00
|
|
|
cmp byte [esi],1Ah
|
|
|
|
jne argument_parsed
|
|
|
|
inc esi
|
|
|
|
movzx ecx,byte [esi]
|
|
|
|
inc esi
|
|
|
|
mov al,2
|
|
|
|
stos byte [edi]
|
|
|
|
call get_label_id
|
|
|
|
stos dword [edi]
|
|
|
|
xor al,al
|
|
|
|
stos byte [edi]
|
|
|
|
jmp argument_parsed
|
2006-07-28 17:39:16 +04:00
|
|
|
parse_from_operator:
|
2006-09-22 19:55:59 +04:00
|
|
|
cmp byte [esi],22h
|
|
|
|
jne forced_expression
|
|
|
|
jmp argument_parsed
|
2006-07-28 17:39:16 +04:00
|
|
|
parse_quoted_extrn:
|
2006-09-22 19:55:59 +04:00
|
|
|
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
|
2006-07-28 17:39:16 +04:00
|
|
|
ptr_argument:
|
2006-09-22 19:55:59 +04:00
|
|
|
call parse_address
|
|
|
|
jmp address_parsed
|
2006-07-28 17:39:16 +04:00
|
|
|
check_argument:
|
2006-09-22 19:55:59 +04:00
|
|
|
push esi ecx
|
|
|
|
sub esi,2
|
|
|
|
mov edi,single_operand_operators
|
|
|
|
call get_operator
|
|
|
|
pop ecx esi
|
|
|
|
or al,al
|
|
|
|
jnz not_instruction
|
|
|
|
call get_instruction
|
|
|
|
jnc embedded_instruction
|
|
|
|
call get_data_directive
|
|
|
|
jnc embedded_instruction
|
2006-07-28 17:39:16 +04:00
|
|
|
not_instruction:
|
2006-09-22 19:55:59 +04:00
|
|
|
pop edi
|
|
|
|
sub esi,2
|
2006-07-28 17:39:16 +04:00
|
|
|
expression_argument:
|
2006-09-22 19:55:59 +04:00
|
|
|
cmp byte [esi],22h
|
|
|
|
jne not_string
|
|
|
|
mov eax,[esi+1]
|
|
|
|
lea ebx,[esi+5+eax]
|
|
|
|
push ebx ecx esi edi
|
|
|
|
mov al,'('
|
|
|
|
stos byte [edi]
|
|
|
|
call convert_expression
|
|
|
|
mov al,')'
|
|
|
|
stos byte [edi]
|
|
|
|
pop eax edx ecx ebx
|
|
|
|
cmp esi,ebx
|
|
|
|
jne expression_parsed
|
|
|
|
mov edi,eax
|
|
|
|
mov esi,edx
|
2006-07-28 17:39:16 +04:00
|
|
|
string_argument:
|
2006-09-22 19:55:59 +04:00
|
|
|
inc esi
|
|
|
|
mov ax,'('
|
|
|
|
stos word [edi]
|
|
|
|
lods dword [esi]
|
|
|
|
mov ecx,eax
|
|
|
|
stos dword [edi]
|
|
|
|
shr ecx,1
|
|
|
|
jnc string_movsb_ok
|
|
|
|
movs byte [edi],[esi]
|
2006-07-28 17:39:16 +04:00
|
|
|
string_movsb_ok:
|
2006-09-22 19:55:59 +04:00
|
|
|
shr ecx,1
|
|
|
|
jnc string_movsw_ok
|
|
|
|
movs word [edi],[esi]
|
2006-07-28 17:39:16 +04:00
|
|
|
string_movsw_ok:
|
2006-09-22 19:55:59 +04:00
|
|
|
rep movs dword [edi],[esi]
|
|
|
|
xor al,al
|
|
|
|
stos byte [edi]
|
|
|
|
jmp expression_parsed
|
2006-07-28 17:39:16 +04:00
|
|
|
not_string:
|
2006-09-22 19:55:59 +04:00
|
|
|
cmp byte [esi],'('
|
|
|
|
jne expression
|
|
|
|
mov eax,esp
|
|
|
|
sub eax,100h
|
|
|
|
jc stack_overflow
|
|
|
|
cmp eax,[stack_limit]
|
|
|
|
jb stack_overflow
|
|
|
|
push esi edi
|
|
|
|
inc esi
|
|
|
|
mov al,'{'
|
|
|
|
stos byte [edi]
|
|
|
|
inc [parenthesis_stack]
|
|
|
|
jmp parse_argument
|
2006-07-28 17:39:16 +04:00
|
|
|
expression:
|
2006-09-22 19:55:59 +04:00
|
|
|
mov al,'('
|
|
|
|
stos byte [edi]
|
|
|
|
call convert_expression
|
|
|
|
mov al,')'
|
|
|
|
stos byte [edi]
|
|
|
|
jmp expression_parsed
|
2006-07-28 17:39:16 +04:00
|
|
|
forced_expression:
|
2006-09-22 19:55:59 +04:00
|
|
|
mov al,'('
|
|
|
|
stos byte [edi]
|
|
|
|
call convert_expression
|
|
|
|
mov al,')'
|
|
|
|
stos byte [edi]
|
|
|
|
jmp argument_parsed
|
2006-07-28 17:39:16 +04:00
|
|
|
address_argument:
|
2006-09-22 19:55:59 +04:00
|
|
|
call parse_address
|
|
|
|
lods byte [esi]
|
|
|
|
cmp al,']'
|
|
|
|
je address_parsed
|
|
|
|
dec esi
|
|
|
|
mov al,')'
|
|
|
|
stos byte [edi]
|
|
|
|
jmp argument_parsed
|
2006-07-28 17:39:16 +04:00
|
|
|
address_parsed:
|
2006-09-22 19:55:59 +04:00
|
|
|
mov al,']'
|
|
|
|
stos byte [edi]
|
|
|
|
jmp argument_parsed
|
2006-07-28 17:39:16 +04:00
|
|
|
parse_address:
|
2006-09-22 19:55:59 +04:00
|
|
|
mov al,'['
|
|
|
|
stos byte [edi]
|
|
|
|
cmp word [esi],021Ah
|
|
|
|
jne convert_address
|
|
|
|
push esi
|
|
|
|
add esi,4
|
|
|
|
lea ebx,[esi+1]
|
|
|
|
cmp byte [esi],':'
|
|
|
|
pop esi
|
|
|
|
jne convert_address
|
|
|
|
add esi,2
|
|
|
|
mov ecx,2
|
|
|
|
push ebx edi
|
|
|
|
call get_symbol
|
|
|
|
pop edi esi
|
|
|
|
jc unknown_segment_prefix
|
|
|
|
cmp al,10h
|
|
|
|
jne unknown_segment_prefix
|
|
|
|
mov al,ah
|
|
|
|
and ah,11110000b
|
|
|
|
cmp ah,60h
|
|
|
|
jne unknown_segment_prefix
|
|
|
|
stos byte [edi]
|
|
|
|
jmp convert_address
|
2006-07-28 17:39:16 +04:00
|
|
|
unknown_segment_prefix:
|
2006-09-22 19:55:59 +04:00
|
|
|
sub esi,5
|
2006-07-28 17:39:16 +04:00
|
|
|
convert_address:
|
2006-09-22 19:55:59 +04:00
|
|
|
push edi
|
|
|
|
mov edi,address_sizes
|
|
|
|
call get_operator
|
|
|
|
pop edi
|
|
|
|
or al,al
|
|
|
|
jz convert_expression
|
|
|
|
add al,70h
|
|
|
|
stos byte [edi]
|
|
|
|
jmp convert_expression
|
2006-07-28 17:39:16 +04:00
|
|
|
forced_parenthesis:
|
2006-09-22 19:55:59 +04:00
|
|
|
cmp byte [esi],'('
|
|
|
|
jne argument_parsed
|
|
|
|
inc esi
|
|
|
|
mov al,'{'
|
|
|
|
jmp separator
|
2006-07-28 17:39:16 +04:00
|
|
|
unallowed_character:
|
2006-09-22 19:55:59 +04:00
|
|
|
mov al,0FFh
|
|
|
|
jmp separator
|
2006-07-28 17:39:16 +04:00
|
|
|
close_parenthesis:
|
2006-09-22 19:55:59 +04:00
|
|
|
mov al,'}'
|
2006-07-28 17:39:16 +04:00
|
|
|
separator:
|
2006-09-22 19:55:59 +04:00
|
|
|
stos byte [edi]
|
|
|
|
jmp argument_parsed
|
2006-07-28 17:39:16 +04:00
|
|
|
instruction_separator:
|
2006-09-22 19:55:59 +04:00
|
|
|
stos byte [edi]
|
|
|
|
jmp allow_embedded_instruction
|
2006-07-28 17:39:16 +04:00
|
|
|
greater:
|
2006-09-22 19:55:59 +04:00
|
|
|
cmp byte [esi],'='
|
|
|
|
jne separator
|
|
|
|
inc esi
|
|
|
|
mov al,0F2h
|
|
|
|
jmp separator
|
2006-07-28 17:39:16 +04:00
|
|
|
less:
|
2006-09-22 19:55:59 +04:00
|
|
|
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
|
2006-07-28 17:39:16 +04:00
|
|
|
not_equal:
|
2006-09-22 19:55:59 +04:00
|
|
|
inc esi
|
|
|
|
mov al,0F1h
|
|
|
|
jmp separator
|
2006-07-28 17:39:16 +04:00
|
|
|
argument_parsed:
|
2006-09-22 19:55:59 +04:00
|
|
|
cmp [parenthesis_stack],0
|
|
|
|
je parse_argument
|
|
|
|
dec [parenthesis_stack]
|
|
|
|
add esp,8
|
|
|
|
jmp argument_parsed
|
2006-07-28 17:39:16 +04:00
|
|
|
expression_parsed:
|
2006-09-22 19:55:59 +04:00
|
|
|
cmp [parenthesis_stack],0
|
|
|
|
je parse_argument
|
|
|
|
cmp byte [esi],')'
|
|
|
|
jne argument_parsed
|
|
|
|
dec [parenthesis_stack]
|
|
|
|
pop edi esi
|
|
|
|
jmp expression
|
2006-07-28 17:39:16 +04:00
|
|
|
contents_parsed:
|
2006-09-22 19:55:59 +04:00
|
|
|
cmp [parenthesis_stack],0
|
2006-12-21 09:34:09 +03:00
|
|
|
; jne invalid_expression
|
|
|
|
je contents_ok
|
|
|
|
dec [parenthesis_stack]
|
|
|
|
add esp,8
|
|
|
|
jmp contents_parsed
|
|
|
|
contents_ok:
|
2006-09-22 19:55:59 +04:00
|
|
|
ret
|
2006-07-28 17:39:16 +04:00
|
|
|
|
|
|
|
identify_label:
|
2006-09-22 19:55:59 +04:00
|
|
|
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
|
2006-07-28 17:39:16 +04:00
|
|
|
label_identified:
|
2006-09-22 19:55:59 +04:00
|
|
|
ret
|
2006-07-28 17:39:16 +04:00
|
|
|
anonymous_label_name:
|
2006-09-22 19:55:59 +04:00
|
|
|
cmp byte [esi-1],'@'
|
|
|
|
je anonymous_label_name_ok
|
|
|
|
mov eax,0Fh
|
2006-07-28 17:39:16 +04:00
|
|
|
anonymous_label_name_ok:
|
2006-09-22 19:55:59 +04:00
|
|
|
ret
|
2006-07-28 17:39:16 +04:00
|
|
|
local_label_name:
|
2006-09-22 19:55:59 +04:00
|
|
|
call get_label_id
|
|
|
|
ret
|
2006-07-28 17:39:16 +04:00
|
|
|
|
|
|
|
get_operator:
|
2006-09-22 19:55:59 +04:00
|
|
|
cmp byte [esi],1Ah
|
|
|
|
jne get_simple_operator
|
|
|
|
mov edx,esi
|
|
|
|
push ebp
|
|
|
|
inc esi
|
|
|
|
lods byte [esi]
|
|
|
|
movzx ebp,al
|
|
|
|
push edi
|
|
|
|
mov ecx,ebp
|
|
|
|
call lower_case
|
|
|
|
pop edi
|
2006-07-28 17:39:16 +04:00
|
|
|
check_operator:
|
2006-09-22 19:55:59 +04:00
|
|
|
mov esi,converted
|
|
|
|
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
|
2006-07-28 17:39:16 +04:00
|
|
|
next_operator:
|
2006-09-22 19:55:59 +04:00
|
|
|
mov edi,ebx
|
|
|
|
inc edi
|
|
|
|
jmp check_operator
|
2006-07-28 17:39:16 +04:00
|
|
|
no_operator:
|
2006-09-22 19:55:59 +04:00
|
|
|
mov esi,edx
|
|
|
|
mov ecx,ebp
|
|
|
|
pop ebp
|
2006-07-28 17:39:16 +04:00
|
|
|
no_simple_operator:
|
2006-09-22 19:55:59 +04:00
|
|
|
xor al,al
|
|
|
|
ret
|
2006-07-28 17:39:16 +04:00
|
|
|
operator_found:
|
2006-09-22 19:55:59 +04:00
|
|
|
lea esi,[edx+2+ebp]
|
|
|
|
mov ecx,ebp
|
|
|
|
pop ebp
|
|
|
|
mov al,[edi]
|
|
|
|
ret
|
2006-07-28 17:39:16 +04:00
|
|
|
get_simple_operator:
|
2006-09-22 19:55:59 +04:00
|
|
|
mov al,[esi]
|
|
|
|
cmp al,22h
|
|
|
|
je no_simple_operator
|
2006-07-28 17:39:16 +04:00
|
|
|
simple_operator:
|
2006-09-22 19:55:59 +04:00
|
|
|
cmp byte [edi],1
|
|
|
|
jb no_simple_operator
|
|
|
|
ja simple_next_operator
|
|
|
|
cmp al,[edi+1]
|
|
|
|
je simple_operator_found
|
2006-07-28 17:39:16 +04:00
|
|
|
simple_next_operator:
|
2006-09-22 19:55:59 +04:00
|
|
|
movzx ecx,byte [edi]
|
|
|
|
lea edi,[edi+1+ecx+1]
|
|
|
|
jmp simple_operator
|
2006-07-28 17:39:16 +04:00
|
|
|
simple_operator_found:
|
2006-09-22 19:55:59 +04:00
|
|
|
inc esi
|
|
|
|
mov al,[edi+2]
|
|
|
|
ret
|
2006-07-28 17:39:16 +04:00
|
|
|
|
|
|
|
get_symbol:
|
2006-09-22 19:55:59 +04:00
|
|
|
push esi
|
|
|
|
mov ebp,ecx
|
|
|
|
call lower_case
|
|
|
|
mov ecx,ebp
|
|
|
|
cmp cl,11
|
|
|
|
ja no_symbol
|
|
|
|
sub cl,2
|
|
|
|
jc no_symbol
|
|
|
|
movzx ebx,word [symbols+ecx*4]
|
|
|
|
add ebx,symbols
|
|
|
|
movzx edx,word [symbols+ecx*4+2]
|
2006-07-28 17:39:16 +04:00
|
|
|
scan_symbols:
|
2006-09-22 19:55:59 +04:00
|
|
|
or edx,edx
|
|
|
|
jz no_symbol
|
|
|
|
mov eax,edx
|
|
|
|
shr eax,1
|
|
|
|
lea edi,[ebp+2]
|
|
|
|
imul eax,edi
|
|
|
|
lea edi,[ebx+eax]
|
|
|
|
mov esi,converted
|
|
|
|
mov ecx,ebp
|
|
|
|
repe cmps byte [esi],[edi]
|
|
|
|
ja symbols_up
|
|
|
|
jb symbols_down
|
|
|
|
pop esi
|
|
|
|
add esi,ebp
|
|
|
|
mov ax,[edi]
|
|
|
|
clc
|
|
|
|
ret
|
2006-07-28 17:39:16 +04:00
|
|
|
no_symbol:
|
2006-09-22 19:55:59 +04:00
|
|
|
pop esi
|
|
|
|
mov ecx,ebp
|
|
|
|
stc
|
|
|
|
ret
|
2006-07-28 17:39:16 +04:00
|
|
|
symbols_down:
|
2006-09-22 19:55:59 +04:00
|
|
|
shr edx,1
|
|
|
|
jmp scan_symbols
|
2006-07-28 17:39:16 +04:00
|
|
|
symbols_up:
|
2006-09-22 19:55:59 +04:00
|
|
|
lea ebx,[edi+ecx+2]
|
|
|
|
shr edx,1
|
|
|
|
adc edx,-1
|
|
|
|
jmp scan_symbols
|
2006-07-28 17:39:16 +04:00
|
|
|
|
|
|
|
get_data_directive:
|
2006-09-22 19:55:59 +04:00
|
|
|
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
|
2006-07-28 17:39:16 +04:00
|
|
|
|
|
|
|
get_instruction:
|
2006-09-22 19:55:59 +04:00
|
|
|
push esi
|
|
|
|
mov ebp,ecx
|
|
|
|
call lower_case
|
|
|
|
mov ecx,ebp
|
|
|
|
cmp cl,11
|
|
|
|
ja no_instruction
|
|
|
|
sub cl,2
|
|
|
|
jc no_instruction
|
|
|
|
movzx ebx,word [instructions+ecx*4]
|
|
|
|
add ebx,instructions
|
|
|
|
movzx edx,word [instructions+ecx*4+2]
|
2006-07-28 17:39:16 +04:00
|
|
|
scan_instructions:
|
2006-09-22 19:55:59 +04:00
|
|
|
or edx,edx
|
|
|
|
jz no_instruction
|
|
|
|
mov eax,edx
|
|
|
|
shr eax,1
|
|
|
|
lea edi,[ebp+3]
|
|
|
|
imul eax,edi
|
|
|
|
lea edi,[ebx+eax]
|
|
|
|
mov esi,converted
|
|
|
|
mov ecx,ebp
|
|
|
|
repe cmps byte [esi],[edi]
|
|
|
|
ja instructions_up
|
|
|
|
jb instructions_down
|
|
|
|
pop esi
|
|
|
|
add esi,ebp
|
|
|
|
mov al,[edi]
|
|
|
|
mov bx,[edi+1]
|
|
|
|
clc
|
|
|
|
ret
|
2006-07-28 17:39:16 +04:00
|
|
|
no_instruction:
|
2006-09-22 19:55:59 +04:00
|
|
|
pop esi
|
|
|
|
mov ecx,ebp
|
|
|
|
stc
|
|
|
|
ret
|
2006-07-28 17:39:16 +04:00
|
|
|
instructions_down:
|
2006-09-22 19:55:59 +04:00
|
|
|
shr edx,1
|
|
|
|
jmp scan_instructions
|
2006-07-28 17:39:16 +04:00
|
|
|
instructions_up:
|
2006-09-22 19:55:59 +04:00
|
|
|
lea ebx,[edi+ecx+3]
|
|
|
|
shr edx,1
|
|
|
|
adc edx,-1
|
|
|
|
jmp scan_instructions
|
2006-07-28 17:39:16 +04:00
|
|
|
|
|
|
|
get_label_id:
|
2006-09-22 19:55:59 +04:00
|
|
|
cmp ecx,100h
|
|
|
|
jae name_too_long
|
|
|
|
cmp byte [esi],'@'
|
|
|
|
je anonymous_label
|
|
|
|
cmp byte [esi],'.'
|
|
|
|
jne standard_label
|
|
|
|
cmp byte [esi+1],'.'
|
|
|
|
je standard_label
|
|
|
|
cmp [current_locals_prefix],0
|
|
|
|
je standard_label
|
|
|
|
push edi
|
|
|
|
mov edi,[additional_memory_end]
|
|
|
|
sub edi,2
|
|
|
|
sub edi,ecx
|
|
|
|
push ecx esi
|
|
|
|
mov esi,[current_locals_prefix]
|
|
|
|
lods byte [esi]
|
|
|
|
movzx ecx,al
|
|
|
|
sub edi,ecx
|
|
|
|
cmp edi,[free_additional_memory]
|
|
|
|
jb out_of_memory
|
|
|
|
mov word [edi],0
|
|
|
|
add edi,2
|
|
|
|
mov ebx,edi
|
|
|
|
rep movs byte [edi],[esi]
|
|
|
|
pop esi ecx
|
|
|
|
add al,cl
|
|
|
|
jc name_too_long
|
|
|
|
rep movs byte [edi],[esi]
|
|
|
|
pop edi
|
|
|
|
push ebx esi
|
|
|
|
movzx ecx,al
|
|
|
|
mov byte [ebx-1],al
|
|
|
|
mov esi,ebx
|
|
|
|
call get_label_id
|
|
|
|
pop esi ebx
|
|
|
|
cmp ebx,[eax+24]
|
|
|
|
jne composed_label_id_ok
|
|
|
|
lea edx,[ebx-2]
|
|
|
|
mov [additional_memory_end],edx
|
2006-07-28 17:39:16 +04:00
|
|
|
composed_label_id_ok:
|
2006-09-22 19:55:59 +04:00
|
|
|
ret
|
2006-07-28 17:39:16 +04:00
|
|
|
anonymous_label:
|
2006-09-22 19:55:59 +04:00
|
|
|
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
|
|
|
|
mov eax,[current_line]
|
|
|
|
mov [error_line],eax
|
|
|
|
call allocate_label
|
|
|
|
mov [anonymous_forward],eax
|
2006-07-28 17:39:16 +04:00
|
|
|
anonymous_ok:
|
2006-09-22 19:55:59 +04:00
|
|
|
xor ebx,ebx
|
|
|
|
ret
|
2006-07-28 17:39:16 +04:00
|
|
|
anonymous_back:
|
2006-09-22 19:55:59 +04:00
|
|
|
add esi,2
|
|
|
|
mov eax,[anonymous_reverse]
|
|
|
|
or eax,eax
|
|
|
|
jz invalid_value
|
|
|
|
jmp anonymous_ok
|
2006-07-28 17:39:16 +04:00
|
|
|
new_anonymous:
|
2006-09-22 19:55:59 +04:00
|
|
|
add esi,2
|
|
|
|
mov eax,[anonymous_forward]
|
|
|
|
or eax,eax
|
|
|
|
jnz new_anonymous_ok
|
|
|
|
call allocate_label
|
2006-07-28 17:39:16 +04:00
|
|
|
new_anonymous_ok:
|
2006-09-22 19:55:59 +04:00
|
|
|
mov [anonymous_reverse],eax
|
|
|
|
mov [anonymous_forward],0
|
|
|
|
jmp anonymous_ok
|
2006-07-28 17:39:16 +04:00
|
|
|
standard_label:
|
2006-09-22 19:55:59 +04:00
|
|
|
cmp byte [esi],'%'
|
|
|
|
je get_predefined_id
|
|
|
|
cmp byte [esi],'$'
|
|
|
|
jne find_label
|
|
|
|
cmp ecx,2
|
|
|
|
ja find_label
|
|
|
|
inc esi
|
|
|
|
jb get_current_offset_id
|
|
|
|
inc esi
|
|
|
|
cmp byte [esi-1],'$'
|
|
|
|
je get_org_origin_id
|
|
|
|
sub esi,ecx
|
|
|
|
jmp find_label
|
2006-07-28 17:39:16 +04:00
|
|
|
get_current_offset_id:
|
2006-09-22 19:55:59 +04:00
|
|
|
xor eax,eax
|
|
|
|
ret
|
2006-07-28 17:39:16 +04:00
|
|
|
get_counter_id:
|
2006-09-22 19:55:59 +04:00
|
|
|
mov eax,1
|
|
|
|
ret
|
2006-07-28 17:39:16 +04:00
|
|
|
get_timestamp_id:
|
2006-09-22 19:55:59 +04:00
|
|
|
mov eax,2
|
|
|
|
ret
|
2006-07-28 17:39:16 +04:00
|
|
|
get_org_origin_id:
|
2006-09-22 19:55:59 +04:00
|
|
|
mov eax,3
|
|
|
|
ret
|
2006-07-28 17:39:16 +04:00
|
|
|
get_predefined_id:
|
2006-09-22 19:55:59 +04:00
|
|
|
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
|
2006-07-28 17:39:16 +04:00
|
|
|
find_label:
|
2006-09-22 19:55:59 +04:00
|
|
|
xor ebx,ebx
|
|
|
|
mov eax,2166136261
|
|
|
|
mov ebp,16777619
|
2006-07-28 17:39:16 +04:00
|
|
|
hash_label:
|
2006-09-22 19:55:59 +04:00
|
|
|
xor al,[esi+ebx]
|
|
|
|
mul ebp
|
|
|
|
inc bl
|
|
|
|
cmp bl,cl
|
|
|
|
jb hash_label
|
|
|
|
mov ebp,eax
|
|
|
|
shl eax,8
|
|
|
|
and ebp,0FFh shl 24
|
|
|
|
xor ebp,eax
|
|
|
|
or ebp,ebx
|
|
|
|
mov [label_hash],ebp
|
|
|
|
push edi esi
|
|
|
|
push ecx
|
|
|
|
mov ecx,32
|
|
|
|
mov ebx,hash_tree
|
2006-07-28 17:39:16 +04:00
|
|
|
follow_tree:
|
2006-09-22 19:55:59 +04:00
|
|
|
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
|
|
|
|
mov ebx,esi
|
|
|
|
mov ebp,[label_hash]
|
2006-07-28 17:39:16 +04:00
|
|
|
compare_labels:
|
2006-09-22 19:55:59 +04:00
|
|
|
mov esi,ebx
|
|
|
|
mov ecx,edx
|
|
|
|
mov edi,[eax+4]
|
|
|
|
mov edi,[edi+24]
|
|
|
|
repe cmps byte [esi],[edi]
|
|
|
|
je label_found
|
|
|
|
mov eax,[eax]
|
|
|
|
or eax,eax
|
|
|
|
jnz compare_labels
|
|
|
|
jmp add_label
|
2006-07-28 17:39:16 +04:00
|
|
|
label_found:
|
2006-09-22 19:55:59 +04:00
|
|
|
add esp,4
|
|
|
|
pop edi
|
|
|
|
mov eax,[eax+4]
|
|
|
|
ret
|
2006-07-28 17:39:16 +04:00
|
|
|
extend_tree:
|
2006-09-22 19:55:59 +04:00
|
|
|
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
|
2006-07-28 17:39:16 +04:00
|
|
|
add_label:
|
2006-09-22 19:55:59 +04:00
|
|
|
mov ecx,edx
|
|
|
|
pop esi
|
|
|
|
cmp byte [esi-2],0
|
|
|
|
je label_name_ok
|
|
|
|
mov al,[esi]
|
|
|
|
cmp al,30h
|
|
|
|
jb name_first_char_ok
|
|
|
|
cmp al,39h
|
|
|
|
jbe invalid_name
|
2006-07-28 17:39:16 +04:00
|
|
|
name_first_char_ok:
|
2006-09-22 19:55:59 +04:00
|
|
|
cmp ecx,1
|
|
|
|
jne check_for_reserved_word
|
|
|
|
cmp al,'$'
|
|
|
|
je reserved_word
|
2006-07-28 17:39:16 +04:00
|
|
|
check_for_reserved_word:
|
2006-09-22 19:55:59 +04:00
|
|
|
call get_instruction
|
|
|
|
jnc reserved_word
|
|
|
|
call get_data_directive
|
|
|
|
jnc reserved_word
|
|
|
|
call get_symbol
|
|
|
|
jnc reserved_word
|
|
|
|
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
|
2006-07-28 17:39:16 +04:00
|
|
|
label_name_ok:
|
2006-09-22 19:55:59 +04:00
|
|
|
mov edx,[free_additional_memory]
|
|
|
|
lea eax,[edx+8]
|
|
|
|
cmp eax,[additional_memory_end]
|
|
|
|
ja out_of_memory
|
|
|
|
mov [free_additional_memory],eax
|
|
|
|
mov ebx,esi
|
|
|
|
add esi,ecx
|
|
|
|
mov eax,[label_leaf]
|
|
|
|
mov edi,[eax]
|
|
|
|
mov [edx],edi
|
|
|
|
mov [eax],edx
|
|
|
|
call allocate_label
|
|
|
|
mov [edx+4],eax
|
|
|
|
mov [eax+24],ebx
|
|
|
|
pop edi
|
|
|
|
ret
|
2006-07-28 17:39:16 +04:00
|
|
|
reserved_word:
|
2006-09-22 19:55:59 +04:00
|
|
|
mov eax,0Fh
|
|
|
|
pop edi
|
|
|
|
ret
|
2006-07-28 17:39:16 +04:00
|
|
|
allocate_label:
|
2006-09-22 19:55:59 +04:00
|
|
|
mov eax,[labels_list]
|
|
|
|
mov ecx,LABEL_STRUCTURE_SIZE shr 2
|
2006-07-28 17:39:16 +04:00
|
|
|
initialize_label:
|
2006-09-22 19:55:59 +04:00
|
|
|
sub eax,4
|
|
|
|
mov dword [eax],0
|
|
|
|
loop initialize_label
|
|
|
|
mov [labels_list],eax
|
|
|
|
ret
|
2006-07-28 17:39:16 +04:00
|
|
|
|
|
|
|
LABEL_STRUCTURE_SIZE = 32
|