; flat assembler core
; Copyright (c) 1999-2013, Tomasz Grysztar.
; All rights reserved.
simple_instruction_except64:
cmp [code_type],64
je illegal_instruction
simple_instruction:
stos byte [edi]
jmp instruction_assembled
simple_instruction_only64:
cmp [code_type],64
jne illegal_instruction
jmp simple_instruction
simple_instruction_16bit_except64:
cmp [code_type],64
je illegal_instruction
simple_instruction_16bit:
cmp [code_type],16
jne size_prefix
stos byte [edi]
jmp instruction_assembled
size_prefix:
mov ah,al
mov al,66h
stos word [edi]
jmp instruction_assembled
simple_instruction_32bit_except64:
cmp [code_type],64
je illegal_instruction
simple_instruction_32bit:
cmp [code_type],16
je size_prefix
stos byte [edi]
jmp instruction_assembled
iret_instruction:
cmp [code_type],64
jne simple_instruction
simple_instruction_64bit:
cmp [code_type],64
jne illegal_instruction
mov ah,al
mov al,48h
stos word [edi]
jmp instruction_assembled
simple_extended_instruction_64bit:
cmp [code_type],64
jne illegal_instruction
mov byte [edi],48h
inc edi
simple_extended_instruction:
mov ah,al
mov al,0Fh
stos word [edi]
jmp instruction_assembled
prefix_instruction:
stos byte [edi]
or [prefixed_instruction],-1
jmp continue_line
segment_prefix:
mov ah,al
shr ah,4
cmp ah,6
jne illegal_instruction
and al,1111b
mov [segment_register],al
call store_segment_prefix
or [prefixed_instruction],-1
jmp continue_line
int_instruction:
lods byte [esi]
call get_size_operator
cmp ah,1
ja invalid_operand_size
cmp al,'('
jne invalid_operand
call get_byte_value
test eax,eax
jns int_imm_ok
call recoverable_overflow
int_imm_ok:
mov ah,al
mov al,0CDh
stos word [edi]
jmp instruction_assembled
aa_instruction:
cmp [code_type],64
je illegal_instruction
push eax
mov bl,10
cmp byte [esi],'('
jne aa_store
inc esi
xor al,al
xchg al,[operand_size]
cmp al,1
ja invalid_operand_size
call get_byte_value
mov bl,al
aa_store:
cmp [operand_size],0
jne invalid_operand
pop eax
mov ah,bl
stos word [edi]
jmp instruction_assembled
basic_instruction:
mov [base_code],al
lods byte [esi]
call get_size_operator
cmp al,10h
je basic_reg
cmp al,'['
jne invalid_operand
basic_mem:
call get_address
push edx ebx ecx
lods byte [esi]
cmp al,','
jne invalid_operand
lods byte [esi]
call get_size_operator
cmp al,'('
je basic_mem_imm
cmp al,10h
jne invalid_operand
basic_mem_reg:
lods byte [esi]
call convert_register
mov [postbyte_register],al
pop ecx ebx edx
mov al,ah
cmp al,1
je instruction_ready
call operand_autodetect
inc [base_code]
instruction_ready:
call store_instruction
jmp instruction_assembled
basic_mem_imm:
mov al,[operand_size]
cmp al,1
jb basic_mem_imm_nosize
je basic_mem_imm_8bit
cmp al,2
je basic_mem_imm_16bit
cmp al,4
je basic_mem_imm_32bit
cmp al,8
jne invalid_operand_size
basic_mem_imm_64bit:
cmp [size_declared],0
jne long_immediate_not_encodable
call operand_64bit
call get_simm32
cmp [value_type],4
jae long_immediate_not_encodable
jmp basic_mem_imm_32bit_ok
basic_mem_imm_nosize:
call recoverable_unknown_size
basic_mem_imm_8bit:
call get_byte_value
mov byte [value],al
mov al,[base_code]
shr al,3
mov [postbyte_register],al
pop ecx ebx edx
mov [base_code],80h
call store_instruction_with_imm8
jmp instruction_assembled
basic_mem_imm_16bit:
call operand_16bit
call get_word_value
mov word [value],ax
mov al,[base_code]
shr al,3
mov [postbyte_register],al
pop ecx ebx edx
cmp [value_type],0
jne basic_mem_imm_16bit_store
cmp [size_declared],0
jne basic_mem_imm_16bit_store
cmp word [value],80h
jb basic_mem_simm_8bit
cmp word [value],-80h
jae basic_mem_simm_8bit
basic_mem_imm_16bit_store:
mov [base_code],81h
call store_instruction_with_imm16
jmp instruction_assembled
basic_mem_simm_8bit:
mov [base_code],83h
call store_instruction_with_imm8
jmp instruction_assembled
basic_mem_imm_32bit:
call operand_32bit
call get_dword_value
basic_mem_imm_32bit_ok:
mov dword [value],eax
mov al,[base_code]
shr al,3
mov [postbyte_register],al
pop ecx ebx edx
cmp [value_type],0
jne basic_mem_imm_32bit_store
cmp [size_declared],0
jne basic_mem_imm_32bit_store
cmp dword [value],80h
jb basic_mem_simm_8bit
cmp dword [value],-80h
jae basic_mem_simm_8bit
basic_mem_imm_32bit_store:
mov [base_code],81h
call store_instruction_with_imm32
jmp instruction_assembled
get_simm32:
call get_qword_value
mov ecx,edx
cdq
cmp ecx,edx
jne value_out_of_range
cmp [value_type],4
jne get_simm32_ok
mov [value_type],2
get_simm32_ok:
ret
basic_reg:
lods byte [esi]
call convert_register
mov [postbyte_register],al
lods byte [esi]
cmp al,','
jne invalid_operand
lods byte [esi]
call get_size_operator
cmp al,10h
je basic_reg_reg
cmp al,'('
je basic_reg_imm
cmp al,'['
jne invalid_operand
basic_reg_mem:
call get_address
mov al,[operand_size]
cmp al,1
je basic_reg_mem_8bit
call operand_autodetect
add [base_code],3
jmp instruction_ready
basic_reg_mem_8bit:
add [base_code],2
jmp instruction_ready
basic_reg_reg:
lods byte [esi]
call convert_register
mov bl,[postbyte_register]
mov [postbyte_register],al
mov al,ah
cmp al,1
je nomem_instruction_ready
call operand_autodetect
inc [base_code]
nomem_instruction_ready:
call store_nomem_instruction
jmp instruction_assembled
basic_reg_imm:
mov al,[operand_size]
cmp al,1
je basic_reg_imm_8bit
cmp al,2
je basic_reg_imm_16bit
cmp al,4
je basic_reg_imm_32bit
cmp al,8
jne invalid_operand_size
basic_reg_imm_64bit:
cmp [size_declared],0
jne long_immediate_not_encodable
call operand_64bit
call get_simm32
cmp [value_type],4
jae long_immediate_not_encodable
jmp basic_reg_imm_32bit_ok
basic_reg_imm_8bit:
call get_byte_value
mov dl,al
mov bl,[base_code]
shr bl,3
xchg bl,[postbyte_register]
or bl,bl
jz basic_al_imm
mov [base_code],80h
call store_nomem_instruction
mov al,dl
stos byte [edi]
jmp instruction_assembled
basic_al_imm:
mov al,[base_code]
add al,4
stos byte [edi]
mov al,dl
stos byte [edi]
jmp instruction_assembled
basic_reg_imm_16bit:
call operand_16bit
call get_word_value
mov dx,ax
mov bl,[base_code]
shr bl,3
xchg bl,[postbyte_register]
cmp [value_type],0
jne basic_reg_imm_16bit_store
cmp [size_declared],0
jne basic_reg_imm_16bit_store
cmp dx,80h
jb basic_reg_simm_8bit
cmp dx,-80h
jae basic_reg_simm_8bit
basic_reg_imm_16bit_store:
or bl,bl
jz basic_ax_imm
mov [base_code],81h
call store_nomem_instruction
basic_store_imm_16bit:
mov ax,dx
call mark_relocation
stos word [edi]
jmp instruction_assembled
basic_reg_simm_8bit:
mov [base_code],83h
call store_nomem_instruction
mov al,dl
stos byte [edi]
jmp instruction_assembled
basic_ax_imm:
add [base_code],5
call store_instruction_code
jmp basic_store_imm_16bit
basic_reg_imm_32bit:
call operand_32bit
call get_dword_value
basic_reg_imm_32bit_ok:
mov edx,eax
mov bl,[base_code]
shr bl,3
xchg bl,[postbyte_register]
cmp [value_type],0
jne basic_reg_imm_32bit_store
cmp [size_declared],0
jne basic_reg_imm_32bit_store
cmp edx,80h
jb basic_reg_simm_8bit
cmp edx,-80h
jae basic_reg_simm_8bit
basic_reg_imm_32bit_store:
or bl,bl
jz basic_eax_imm
mov [base_code],81h
call store_nomem_instruction
basic_store_imm_32bit:
mov eax,edx
call mark_relocation
stos dword [edi]
jmp instruction_assembled
basic_eax_imm:
add [base_code],5
call store_instruction_code
jmp basic_store_imm_32bit
recoverable_unknown_size:
cmp [error_line],0
jne ignore_unknown_size
push [current_line]
pop [error_line]
mov [error],operand_size_not_specified
ignore_unknown_size:
ret
single_operand_instruction:
mov [base_code],0F6h
mov [postbyte_register],al
lods byte [esi]
call get_size_operator
cmp al,10h
je single_reg
cmp al,'['
jne invalid_operand
single_mem:
call get_address
mov al,[operand_size]
cmp al,1
je single_mem_8bit
jb single_mem_nosize
call operand_autodetect
inc [base_code]
jmp instruction_ready
single_mem_nosize:
call recoverable_unknown_size
single_mem_8bit:
jmp instruction_ready
single_reg:
lods byte [esi]
call convert_register
mov bl,al
mov al,ah
cmp al,1
je single_reg_8bit
call operand_autodetect
inc [base_code]
single_reg_8bit:
jmp nomem_instruction_ready
mov_instruction:
mov [base_code],88h
lods byte [esi]
call get_size_operator
cmp al,10h
je mov_reg
cmp al,'['
jne invalid_operand
mov_mem:
call get_address
push edx ebx ecx
lods byte [esi]
cmp al,','
jne invalid_operand
lods byte [esi]
call get_size_operator
cmp al,'('
je mov_mem_imm
cmp al,10h
jne invalid_operand
mov_mem_reg:
lods byte [esi]
cmp al,60h
jb mov_mem_general_reg
cmp al,70h
jb mov_mem_sreg
mov_mem_general_reg:
call convert_register
mov [postbyte_register],al
pop ecx ebx edx
cmp ah,1
je mov_mem_reg_8bit
mov al,ah
call operand_autodetect
mov al,[postbyte_register]
or al,bl
or al,bh
jz mov_mem_ax
inc [base_code]
jmp instruction_ready
mov_mem_reg_8bit:
or al,bl
or al,bh
jnz instruction_ready
mov_mem_al:
test ch,22h
jnz mov_mem_address16_al
test ch,44h
jnz mov_mem_address32_al
test ch,88h
jnz mov_mem_address64_al
or ch,ch
jnz invalid_address_size
cmp [code_type],64
je mov_mem_address64_al
cmp [code_type],32
je mov_mem_address32_al
cmp edx,10000h
jb mov_mem_address16_al
mov_mem_address32_al:
call store_segment_prefix_if_necessary
call address_32bit_prefix
mov [base_code],0A2h
store_mov_address32:
call store_instruction_code
call store_address_32bit_value
jmp instruction_assembled
mov_mem_address16_al:
call store_segment_prefix_if_necessary
call address_16bit_prefix
mov [base_code],0A2h
store_mov_address16:
cmp [code_type],64
je invalid_address
call store_instruction_code
mov eax,edx
stos word [edi]
cmp edx,10000h
jge value_out_of_range
jmp instruction_assembled
mov_mem_address64_al:
call store_segment_prefix_if_necessary
mov [base_code],0A2h
store_mov_address64:
call store_instruction_code
call store_address_64bit_value
jmp instruction_assembled
mov_mem_ax:
test ch,22h
jnz mov_mem_address16_ax
test ch,44h
jnz mov_mem_address32_ax
test ch,88h
jnz mov_mem_address64_ax
or ch,ch
jnz invalid_address_size
cmp [code_type],64
je mov_mem_address64_ax
cmp [code_type],32
je mov_mem_address32_ax
cmp edx,10000h
jb mov_mem_address16_ax
mov_mem_address32_ax:
call store_segment_prefix_if_necessary
call address_32bit_prefix
mov [base_code],0A3h
jmp store_mov_address32
mov_mem_address16_ax:
call store_segment_prefix_if_necessary
call address_16bit_prefix
mov [base_code],0A3h
jmp store_mov_address16
mov_mem_address64_ax:
call store_segment_prefix_if_necessary
mov [base_code],0A3h
jmp store_mov_address64
mov_mem_sreg:
sub al,61h
mov [postbyte_register],al
pop ecx ebx edx
mov ah,[operand_size]
or ah,ah
jz mov_mem_sreg_store
cmp ah,2
jne invalid_operand_size
mov_mem_sreg_store:
mov [base_code],8Ch
jmp instruction_ready
mov_mem_imm:
mov al,[operand_size]
cmp al,1
jb mov_mem_imm_nosize
je mov_mem_imm_8bit
cmp al,2
je mov_mem_imm_16bit
cmp al,4
je mov_mem_imm_32bit
cmp al,8
jne invalid_operand_size
mov_mem_imm_64bit:
cmp [size_declared],0
jne long_immediate_not_encodable
call operand_64bit
call get_simm32
cmp [value_type],4
jae long_immediate_not_encodable
jmp mov_mem_imm_32bit_store
mov_mem_imm_8bit:
call get_byte_value
mov byte [value],al
mov [postbyte_register],0
mov [base_code],0C6h
pop ecx ebx edx
call store_instruction_with_imm8
jmp instruction_assembled
mov_mem_imm_16bit:
call operand_16bit
call get_word_value
mov word [value],ax
mov [postbyte_register],0
mov [base_code],0C7h
pop ecx ebx edx
call store_instruction_with_imm16
jmp instruction_assembled
mov_mem_imm_nosize:
call recoverable_unknown_size
mov_mem_imm_32bit:
call operand_32bit
call get_dword_value
mov_mem_imm_32bit_store:
mov dword [value],eax
mov [postbyte_register],0
mov [base_code],0C7h
pop ecx ebx edx
call store_instruction_with_imm32
jmp instruction_assembled
mov_reg:
lods byte [esi]
mov ah,al
sub ah,10h
and ah,al
test ah,0F0h
jnz mov_sreg
call convert_register
mov [postbyte_register],al
lods byte [esi]
cmp al,','
jne invalid_operand
lods byte [esi]
call get_size_operator
cmp al,'['
je mov_reg_mem
cmp al,'('
je mov_reg_imm
cmp al,10h
jne invalid_operand
mov_reg_reg:
lods byte [esi]
mov ah,al
sub ah,10h
and ah,al
test ah,0F0h
jnz mov_reg_sreg
call convert_register
mov bl,[postbyte_register]
mov [postbyte_register],al
mov al,ah
cmp al,1
je mov_reg_reg_8bit
call operand_autodetect
inc [base_code]
mov_reg_reg_8bit:
jmp nomem_instruction_ready
mov_reg_sreg:
mov bl,[postbyte_register]
mov ah,al
and al,1111b
mov [postbyte_register],al
shr ah,4
cmp ah,5
je mov_reg_creg
cmp ah,7
je mov_reg_dreg
ja mov_reg_treg
dec [postbyte_register]
cmp [operand_size],8
je mov_reg_sreg64
cmp [operand_size],4
je mov_reg_sreg32
cmp [operand_size],2
jne invalid_operand_size
call operand_16bit
jmp mov_reg_sreg_store
mov_reg_sreg64:
call operand_64bit
jmp mov_reg_sreg_store
mov_reg_sreg32:
call operand_32bit
mov_reg_sreg_store:
mov [base_code],8Ch
jmp nomem_instruction_ready
mov_reg_treg:
cmp ah,9
jne invalid_operand
mov [extended_code],24h
jmp mov_reg_xrx
mov_reg_dreg:
mov [extended_code],21h
jmp mov_reg_xrx
mov_reg_creg:
mov [extended_code],20h
mov_reg_xrx:
mov [base_code],0Fh
cmp [code_type],64
je mov_reg_xrx_64bit
cmp [operand_size],4
jne invalid_operand_size
cmp [postbyte_register],8
jne mov_reg_xrx_store
cmp [extended_code],20h
jne mov_reg_xrx_store
mov al,0F0h
stos byte [edi]
mov [postbyte_register],0
mov_reg_xrx_store:
jmp nomem_instruction_ready
mov_reg_xrx_64bit:
cmp [operand_size],8
jne invalid_operand_size
jmp nomem_instruction_ready
mov_reg_mem:
call get_address
mov al,[operand_size]
cmp al,1
je mov_reg_mem_8bit
call operand_autodetect
mov al,[postbyte_register]
or al,bl
or al,bh
jz mov_ax_mem
add [base_code],3
jmp instruction_ready
mov_reg_mem_8bit:
mov al,[postbyte_register]
or al,bl
or al,bh
jz mov_al_mem
add [base_code],2
jmp instruction_ready
mov_al_mem:
test ch,22h
jnz mov_al_mem_address16
test ch,44h
jnz mov_al_mem_address32
test ch,88h
jnz mov_al_mem_address64
or ch,ch
jnz invalid_address_size
cmp [code_type],64
je mov_al_mem_address64
cmp [code_type],32
je mov_al_mem_address32
cmp edx,10000h
jb mov_al_mem_address16
mov_al_mem_address32:
call store_segment_prefix_if_necessary
call address_32bit_prefix
mov [base_code],0A0h
jmp store_mov_address32
mov_al_mem_address16:
call store_segment_prefix_if_necessary
call address_16bit_prefix
mov [base_code],0A0h
jmp store_mov_address16
mov_al_mem_address64:
call store_segment_prefix_if_necessary
mov [base_code],0A0h
jmp store_mov_address64
mov_ax_mem:
test ch,22h
jnz mov_ax_mem_address16
test ch,44h
jnz mov_ax_mem_address32
test ch,88h
jnz mov_ax_mem_address64
or ch,ch
jnz invalid_address_size
cmp [code_type],64
je mov_ax_mem_address64
cmp [code_type],32
je mov_ax_mem_address32
cmp edx,10000h
jb mov_ax_mem_address16
mov_ax_mem_address32:
call store_segment_prefix_if_necessary
call address_32bit_prefix
mov [base_code],0A1h
jmp store_mov_address32
mov_ax_mem_address16:
call store_segment_prefix_if_necessary
call address_16bit_prefix
mov [base_code],0A1h
jmp store_mov_address16
mov_ax_mem_address64:
call store_segment_prefix_if_necessary
mov [base_code],0A1h
jmp store_mov_address64
mov_reg_imm:
mov al,[operand_size]
cmp al,1
je mov_reg_imm_8bit
cmp al,2
je mov_reg_imm_16bit
cmp al,4
je mov_reg_imm_32bit
cmp al,8
jne invalid_operand_size
mov_reg_imm_64bit:
call operand_64bit
call get_qword_value
mov ecx,edx
cmp [size_declared],0
jne mov_reg_imm_64bit_store
cmp [value_type],4
jae mov_reg_imm_64bit_store
cdq
cmp ecx,edx
je mov_reg_64bit_imm_32bit
mov_reg_imm_64bit_store:
push eax ecx
mov al,0B8h
call store_mov_reg_imm_code
pop edx eax
call mark_relocation
stos dword [edi]
mov eax,edx
stos dword [edi]
jmp instruction_assembled
mov_reg_imm_8bit:
call get_byte_value
mov dl,al
mov al,0B0h
call store_mov_reg_imm_code
mov al,dl
stos byte [edi]
jmp instruction_assembled
mov_reg_imm_16bit:
call get_word_value
mov dx,ax
call operand_16bit
mov al,0B8h
call store_mov_reg_imm_code
mov ax,dx
call mark_relocation
stos word [edi]
jmp instruction_assembled
mov_reg_imm_32bit:
call operand_32bit
call get_dword_value
mov edx,eax
mov al,0B8h
call store_mov_reg_imm_code
mov_store_imm_32bit:
mov eax,edx
call mark_relocation
stos dword [edi]
jmp instruction_assembled
store_mov_reg_imm_code:
mov ah,[postbyte_register]
test ah,1000b
jz mov_reg_imm_prefix_ok
or [rex_prefix],41h
mov_reg_imm_prefix_ok:
and ah,111b
add al,ah
mov [base_code],al
call store_instruction_code
ret
mov_reg_64bit_imm_32bit:
mov edx,eax
mov bl,[postbyte_register]
mov [postbyte_register],0
mov [base_code],0C7h
call store_nomem_instruction
jmp mov_store_imm_32bit
mov_sreg:
mov ah,al
and al,1111b
mov [postbyte_register],al
shr ah,4
cmp ah,5
je mov_creg
cmp ah,7
je mov_dreg
ja mov_treg
cmp al,2
je illegal_instruction
dec [postbyte_register]
lods byte [esi]
cmp al,','
jne invalid_operand
lods byte [esi]
call get_size_operator
cmp al,'['
je mov_sreg_mem
cmp al,10h
jne invalid_operand
mov_sreg_reg:
lods byte [esi]
call convert_register
or ah,ah
jz mov_sreg_reg_size_ok
cmp ah,2
jne invalid_operand_size
mov bl,al
mov_sreg_reg_size_ok:
mov [base_code],8Eh
jmp nomem_instruction_ready
mov_sreg_mem:
call get_address
mov al,[operand_size]
or al,al
jz mov_sreg_mem_size_ok
cmp al,2
jne invalid_operand_size
mov_sreg_mem_size_ok:
mov [base_code],8Eh
jmp instruction_ready
mov_treg:
cmp ah,9
jne invalid_operand
mov [extended_code],26h
jmp mov_xrx
mov_dreg:
mov [extended_code],23h
jmp mov_xrx
mov_creg:
mov [extended_code],22h
mov_xrx:
mov [base_code],0Fh
lods byte [esi]
cmp al,','
jne invalid_operand
lods byte [esi]
cmp al,10h
jne invalid_operand
lods byte [esi]
call convert_register
mov bl,al
cmp [code_type],64
je mov_xrx_64bit
cmp ah,4
jne invalid_operand_size
cmp [postbyte_register],8
jne mov_xrx_store
cmp [extended_code],22h
jne mov_xrx_store
mov al,0F0h
stos byte [edi]
mov [postbyte_register],0
mov_xrx_store:
jmp nomem_instruction_ready
mov_xrx_64bit:
cmp ah,8
je mov_xrx_store
jmp invalid_operand_size
test_instruction:
mov [base_code],84h
lods byte [esi]
call get_size_operator
cmp al,10h
je test_reg
cmp al,'['
jne invalid_operand
test_mem:
call get_address
push edx ebx ecx
lods byte [esi]
cmp al,','
jne invalid_operand
lods byte [esi]
call get_size_operator
cmp al,'('
je test_mem_imm
cmp al,10h
jne invalid_operand
test_mem_reg:
lods byte [esi]
call convert_register
mov [postbyte_register],al
pop ecx ebx edx
mov al,ah
cmp al,1
je test_mem_reg_8bit
call operand_autodetect
inc [base_code]
test_mem_reg_8bit:
jmp instruction_ready
test_mem_imm:
mov al,[operand_size]
cmp al,1
jb test_mem_imm_nosize
je test_mem_imm_8bit
cmp al,2
je test_mem_imm_16bit
cmp al,4
je test_mem_imm_32bit
cmp al,8
jne invalid_operand_size
test_mem_imm_64bit:
cmp [size_declared],0
jne long_immediate_not_encodable
call operand_64bit
call get_simm32
cmp [value_type],4
jae long_immediate_not_encodable
jmp test_mem_imm_32bit_store
test_mem_imm_8bit:
call get_byte_value
mov byte [value],al
mov [postbyte_register],0
mov [base_code],0F6h
pop ecx ebx edx
call store_instruction_with_imm8
jmp instruction_assembled
test_mem_imm_16bit:
call operand_16bit
call get_word_value
mov word [value],ax
mov [postbyte_register],0
mov [base_code],0F7h
pop ecx ebx edx
call store_instruction_with_imm16
jmp instruction_assembled
test_mem_imm_nosize:
call recoverable_unknown_size
test_mem_imm_32bit:
call operand_32bit
call get_dword_value
test_mem_imm_32bit_store:
mov dword [value],eax
mov [postbyte_register],0
mov [base_code],0F7h
pop ecx ebx edx
call store_instruction_with_imm32
jmp instruction_assembled
test_reg:
lods byte [esi]
call convert_register
mov [postbyte_register],al
lods byte [esi]
cmp al,','
jne invalid_operand
lods byte [esi]
call get_size_operator
cmp al,'['
je test_reg_mem
cmp al,'('
je test_reg_imm
cmp al,10h
jne invalid_operand
test_reg_reg:
lods byte [esi]
call convert_register
mov bl,[postbyte_register]
mov [postbyte_register],al
mov al,ah
cmp al,1
je test_reg_reg_8bit
call operand_autodetect
inc [base_code]
test_reg_reg_8bit:
jmp nomem_instruction_ready
test_reg_imm:
mov al,[operand_size]
cmp al,1
je test_reg_imm_8bit
cmp al,2
je test_reg_imm_16bit
cmp al,4
je test_reg_imm_32bit
cmp al,8
jne invalid_operand_size
test_reg_imm_64bit:
cmp [size_declared],0
jne long_immediate_not_encodable
call operand_64bit
call get_simm32
cmp [value_type],4
jae long_immediate_not_encodable
jmp test_reg_imm_32bit_store
test_reg_imm_8bit:
call get_byte_value
mov dl,al
mov bl,[postbyte_register]
mov [postbyte_register],0
mov [base_code],0F6h
or bl,bl
jz test_al_imm
call store_nomem_instruction
mov al,dl
stos byte [edi]
jmp instruction_assembled
test_al_imm:
mov [base_code],0A8h
call store_instruction_code
mov al,dl
stos byte [edi]
jmp instruction_assembled
test_reg_imm_16bit:
call operand_16bit
call get_word_value
mov dx,ax
mov bl,[postbyte_register]
mov [postbyte_register],0
mov [base_code],0F7h
or bl,bl
jz test_ax_imm
call store_nomem_instruction
mov ax,dx
call mark_relocation
stos word [edi]
jmp instruction_assembled
test_ax_imm:
mov [base_code],0A9h
call store_instruction_code
mov ax,dx
stos word [edi]
jmp instruction_assembled
test_reg_imm_32bit:
call operand_32bit
call get_dword_value
test_reg_imm_32bit_store:
mov edx,eax
mov bl,[postbyte_register]
mov [postbyte_register],0
mov [base_code],0F7h
or bl,bl
jz test_eax_imm
call store_nomem_instruction
mov eax,edx
call mark_relocation
stos dword [edi]
jmp instruction_assembled
test_eax_imm:
mov [base_code],0A9h
call store_instruction_code
mov eax,edx
stos dword [edi]
jmp instruction_assembled
test_reg_mem:
call get_address
mov al,[operand_size]
cmp al,1
je test_reg_mem_8bit
call operand_autodetect
inc [base_code]
test_reg_mem_8bit:
jmp instruction_ready
xchg_instruction:
mov [base_code],86h
lods byte [esi]
call get_size_operator
cmp al,10h
je xchg_reg
cmp al,'['
jne invalid_operand
xchg_mem:
call get_address
push edx ebx ecx
lods byte [esi]
cmp al,','
jne invalid_operand
lods byte [esi]
call get_size_operator
cmp al,10h
je test_mem_reg
jmp invalid_operand
xchg_reg:
lods byte [esi]
call convert_register
mov [postbyte_register],al
lods byte [esi]
cmp al,','
jne invalid_operand
lods byte [esi]
call get_size_operator
cmp al,'['
je test_reg_mem
cmp al,10h
jne invalid_operand
xchg_reg_reg:
lods byte [esi]
call convert_register
mov bl,al
mov al,ah
cmp al,1
je xchg_reg_reg_8bit
call operand_autodetect
cmp [postbyte_register],0
je xchg_ax_reg
or bl,bl
jnz xchg_reg_reg_store
mov bl,[postbyte_register]
xchg_ax_reg:
cmp [code_type],64
jne xchg_ax_reg_ok
cmp ah,4
jne xchg_ax_reg_ok
or bl,bl
jz xchg_reg_reg_store
xchg_ax_reg_ok:
test bl,1000b
jz xchg_ax_reg_store
or [rex_prefix],41h
and bl,111b
xchg_ax_reg_store:
add bl,90h
mov [base_code],bl
call store_instruction_code
jmp instruction_assembled
xchg_reg_reg_store:
inc [base_code]
xchg_reg_reg_8bit:
jmp nomem_instruction_ready
push_instruction:
mov [push_size],al
push_next:
lods byte [esi]
call get_size_operator
cmp al,10h
je push_reg
cmp al,'('
je push_imm
cmp al,'['
jne invalid_operand
push_mem:
call get_address
mov al,[operand_size]
mov ah,[push_size]
cmp al,2
je push_mem_16bit
cmp al,4
je push_mem_32bit
cmp al,8
je push_mem_64bit
or al,al
jnz invalid_operand_size
cmp ah,2
je push_mem_16bit
cmp ah,4
je push_mem_32bit
cmp ah,8
je push_mem_64bit
call recoverable_unknown_size
jmp push_mem_store
push_mem_16bit:
test ah,not 2
jnz invalid_operand_size
call operand_16bit
jmp push_mem_store
push_mem_32bit:
test ah,not 4
jnz invalid_operand_size
cmp [code_type],64
je illegal_instruction
call operand_32bit
jmp push_mem_store
push_mem_64bit:
test ah,not 8
jnz invalid_operand_size
cmp [code_type],64
jne illegal_instruction
push_mem_store:
mov [base_code],0FFh
mov [postbyte_register],110b
call store_instruction
jmp push_done
push_reg:
lods byte [esi]
mov ah,al
sub ah,10h
and ah,al
test ah,0F0h
jnz push_sreg
call convert_register
test al,1000b
jz push_reg_ok
or [rex_prefix],41h
and al,111b
push_reg_ok:
add al,50h
mov [base_code],al
mov al,ah
mov ah,[push_size]
cmp al,2
je push_reg_16bit
cmp al,4
je push_reg_32bit
cmp al,8
jne invalid_operand_size
push_reg_64bit:
test ah,not 8
jnz invalid_operand_size
cmp [code_type],64
jne illegal_instruction
jmp push_reg_store
push_reg_32bit:
test ah,not 4
jnz invalid_operand_size
cmp [code_type],64
je illegal_instruction
call operand_32bit
jmp push_reg_store
push_reg_16bit:
test ah,not 2
jnz invalid_operand_size
call operand_16bit
push_reg_store:
call store_instruction_code
jmp push_done
push_sreg:
mov bl,al
mov dl,[operand_size]
mov dh,[push_size]
cmp dl,2
je push_sreg16
cmp dl,4
je push_sreg32
cmp dl,8
je push_sreg64
or dl,dl
jnz invalid_operand_size
cmp dh,2
je push_sreg16
cmp dh,4
je push_sreg32
cmp dh,8
je push_sreg64
jmp push_sreg_store
push_sreg16:
test dh,not 2
jnz invalid_operand_size
call operand_16bit
jmp push_sreg_store
push_sreg32:
test dh,not 4
jnz invalid_operand_size
cmp [code_type],64
je illegal_instruction
call operand_32bit
jmp push_sreg_store
push_sreg64:
test dh,not 8
jnz invalid_operand_size
cmp [code_type],64
jne illegal_instruction
push_sreg_store:
mov al,bl
cmp al,70h
jae invalid_operand
sub al,61h
jc invalid_operand
cmp al,4
jae push_sreg_386
shl al,3
add al,6
mov [base_code],al
cmp [code_type],64
je illegal_instruction
jmp push_reg_store
push_sreg_386:
sub al,4
shl al,3
add al,0A0h
mov [extended_code],al
mov [base_code],0Fh
jmp push_reg_store
push_imm:
mov al,[operand_size]
mov ah,[push_size]
or al,al
je push_imm_size_ok
or ah,ah
je push_imm_size_ok
cmp al,ah
jne invalid_operand_size
push_imm_size_ok:
cmp al,2
je push_imm_16bit
cmp al,4
je push_imm_32bit
cmp al,8
je push_imm_64bit
cmp ah,2
je push_imm_optimized_16bit
cmp ah,4
je push_imm_optimized_32bit
cmp ah,8
je push_imm_optimized_64bit
or al,al
jnz invalid_operand_size
cmp [code_type],16
je push_imm_optimized_16bit
cmp [code_type],32
je push_imm_optimized_32bit
push_imm_optimized_64bit:
cmp [code_type],64
jne illegal_instruction
call get_simm32
mov edx,eax
cmp [value_type],0
jne push_imm_32bit_store
cmp eax,-80h
jl push_imm_32bit_store
cmp eax,80h
jge push_imm_32bit_store
jmp push_imm_8bit
push_imm_optimized_32bit:
cmp [code_type],64
je illegal_instruction
call get_dword_value
mov edx,eax
call operand_32bit
cmp [value_type],0
jne push_imm_32bit_store
cmp eax,-80h
jl push_imm_32bit_store
cmp eax,80h
jge push_imm_32bit_store
jmp push_imm_8bit
push_imm_optimized_16bit:
call get_word_value
mov dx,ax
call operand_16bit
cmp [value_type],0
jne push_imm_16bit_store
cmp ax,-80h
jl push_imm_16bit_store
cmp ax,80h
jge push_imm_16bit_store
push_imm_8bit:
mov ah,al
mov [base_code],6Ah
call store_instruction_code
mov al,ah
stos byte [edi]
jmp push_done
push_imm_16bit:
call get_word_value
mov dx,ax
call operand_16bit
push_imm_16bit_store:
mov [base_code],68h
call store_instruction_code
mov ax,dx
call mark_relocation
stos word [edi]
jmp push_done
push_imm_64bit:
cmp [code_type],64
jne illegal_instruction
call get_simm32
mov edx,eax
jmp push_imm_32bit_store
push_imm_32bit:
cmp [code_type],64
je illegal_instruction
call get_dword_value
mov edx,eax
call operand_32bit
push_imm_32bit_store:
mov [base_code],68h
call store_instruction_code
mov eax,edx
call mark_relocation
stos dword [edi]
push_done:
lods byte [esi]
dec esi
cmp al,0Fh
je instruction_assembled
or al,al
jz instruction_assembled
mov [operand_size],0
mov [size_override],0
mov [operand_prefix],0
mov [rex_prefix],0
jmp push_next
pop_instruction:
mov [push_size],al
pop_next:
lods byte [esi]
call get_size_operator
cmp al,10h
je pop_reg
cmp al,'['
jne invalid_operand
pop_mem:
call get_address
mov al,[operand_size]
mov ah,[push_size]
cmp al,2
je pop_mem_16bit
cmp al,4
je pop_mem_32bit
cmp al,8
je pop_mem_64bit
or al,al
jnz invalid_operand_size
cmp ah,2
je pop_mem_16bit
cmp ah,4
je pop_mem_32bit
cmp ah,8
je pop_mem_64bit
call recoverable_unknown_size
jmp pop_mem_store
pop_mem_16bit:
test ah,not 2
jnz invalid_operand_size
call operand_16bit
jmp pop_mem_store
pop_mem_32bit:
test ah,not 4
jnz invalid_operand_size
cmp [code_type],64
je illegal_instruction
call operand_32bit
jmp pop_mem_store
pop_mem_64bit:
test ah,not 8
jnz invalid_operand_size
cmp [code_type],64
jne illegal_instruction
pop_mem_store:
mov [base_code],08Fh
mov [postbyte_register],0
call store_instruction
jmp pop_done
pop_reg:
lods byte [esi]
mov ah,al
sub ah,10h
and ah,al
test ah,0F0h
jnz pop_sreg
call convert_register
test al,1000b
jz pop_reg_ok
or [rex_prefix],41h
and al,111b
pop_reg_ok:
add al,58h
mov [base_code],al
mov al,ah
mov ah,[push_size]
cmp al,2
je pop_reg_16bit
cmp al,4
je pop_reg_32bit
cmp al,8
je pop_reg_64bit
jmp invalid_operand_size
pop_reg_64bit:
test ah,not 8
jnz invalid_operand_size
cmp [code_type],64
jne illegal_instruction
jmp pop_reg_store
pop_reg_32bit:
test ah,not 4
jnz invalid_operand_size
cmp [code_type],64
je illegal_instruction
call operand_32bit
jmp pop_reg_store
pop_reg_16bit:
test ah,not 2
jnz invalid_operand_size
call operand_16bit
pop_reg_store:
call store_instruction_code
pop_done:
lods byte [esi]
dec esi
cmp al,0Fh
je instruction_assembled
or al,al
jz instruction_assembled
mov [operand_size],0
mov [size_override],0
mov [operand_prefix],0
mov [rex_prefix],0
jmp pop_next
pop_sreg:
mov dl,[operand_size]
mov dh,[push_size]
cmp al,62h
je pop_cs
mov bl,al
cmp dl,2
je pop_sreg16
cmp dl,4
je pop_sreg32
cmp dl,8
je pop_sreg64
or dl,dl
jnz invalid_operand_size
cmp dh,2
je pop_sreg16
cmp dh,4
je pop_sreg32
cmp dh,8
je pop_sreg64
jmp pop_sreg_store
pop_sreg16:
test dh,not 2
jnz invalid_operand_size
call operand_16bit
jmp pop_sreg_store
pop_sreg32:
test dh,not 4
jnz invalid_operand_size
cmp [code_type],64
je illegal_instruction
call operand_32bit
jmp pop_sreg_store
pop_sreg64:
test dh,not 8
jnz invalid_operand_size
cmp [code_type],64
jne illegal_instruction
pop_sreg_store:
mov al,bl
cmp al,70h
jae invalid_operand
sub al,61h
jc invalid_operand
cmp al,4
jae pop_sreg_386
shl al,3
add al,7
mov [base_code],al
cmp [code_type],64
je illegal_instruction
jmp pop_reg_store
pop_cs:
cmp [code_type],16
jne illegal_instruction
cmp dl,2
je pop_cs_store
or dl,dl
jnz invalid_operand_size
cmp dh,2
je pop_cs_store
or dh,dh
jnz illegal_instruction
pop_cs_store:
test dh,not 2
jnz invalid_operand_size
mov al,0Fh
stos byte [edi]
jmp pop_done
pop_sreg_386:
sub al,4
shl al,3
add al,0A1h
mov [extended_code],al
mov [base_code],0Fh
jmp pop_reg_store
inc_instruction:
mov [base_code],al
lods byte [esi]
call get_size_operator
cmp al,10h
je inc_reg
cmp al,'['
je inc_mem
jne invalid_operand
inc_mem:
call get_address
mov al,[operand_size]
cmp al,1
je inc_mem_8bit
jb inc_mem_nosize
call operand_autodetect
mov al,0FFh
xchg al,[base_code]
mov [postbyte_register],al
jmp instruction_ready
inc_mem_nosize:
call recoverable_unknown_size
inc_mem_8bit:
mov al,0FEh
xchg al,[base_code]
mov [postbyte_register],al
jmp instruction_ready
inc_reg:
lods byte [esi]
call convert_register
mov bl,al
mov al,0FEh
xchg al,[base_code]
mov [postbyte_register],al
mov al,ah
cmp al,1
je inc_reg_8bit
call operand_autodetect
cmp [code_type],64
je inc_reg_long_form
mov al,[postbyte_register]
shl al,3
add al,bl
add al,40h
mov [base_code],al
call store_instruction_code
jmp instruction_assembled
inc_reg_long_form:
inc [base_code]
inc_reg_8bit:
jmp nomem_instruction_ready
set_instruction:
mov [base_code],0Fh
mov [extended_code],al
lods byte [esi]
call get_size_operator
cmp al,10h
je set_reg
cmp al,'['
jne invalid_operand
set_mem:
call get_address
cmp [operand_size],1
ja invalid_operand_size
mov [postbyte_register],0
jmp instruction_ready
set_reg:
lods byte [esi]
call convert_register
cmp ah,1
jne invalid_operand_size
mov bl,al
mov [postbyte_register],0
jmp nomem_instruction_ready
arpl_instruction:
cmp [code_type],64
je illegal_instruction
mov [base_code],63h
lods byte [esi]
call get_size_operator
cmp al,10h
je arpl_reg
cmp al,'['
jne invalid_operand
call get_address
lods byte [esi]
cmp al,','
jne invalid_operand
lods byte [esi]
cmp al,10h
jne invalid_operand
lods byte [esi]
call convert_register
mov [postbyte_register],al
cmp ah,2
jne invalid_operand_size
jmp instruction_ready
arpl_reg:
lods byte [esi]
call convert_register
cmp ah,2
jne invalid_operand_size
mov bl,al
lods byte [esi]
cmp al,','
jne invalid_operand
lods byte [esi]
cmp al,10h
jne invalid_operand
lods byte [esi]
call convert_register
mov [postbyte_register],al
jmp nomem_instruction_ready
bound_instruction:
cmp [code_type],64
je illegal_instruction
lods byte [esi]
call get_size_operator
cmp al,10h
jne invalid_operand
lods byte [esi]
call convert_register
mov [postbyte_register],al
lods byte [esi]
cmp al,','
jne invalid_operand
lods byte [esi]
call get_size_operator
cmp al,'['
jne invalid_operand
call get_address
mov al,[operand_size]
cmp al,2
je bound_store
cmp al,4
jne invalid_operand_size
bound_store:
call operand_autodetect
mov [base_code],62h
jmp instruction_ready
enter_instruction:
lods byte [esi]
call get_size_operator
cmp ah,2
je enter_imm16_size_ok
or ah,ah
jnz invalid_operand_size
enter_imm16_size_ok:
cmp al,'('
jne invalid_operand
call get_word_value
cmp [next_pass_needed],0
jne enter_imm16_ok
cmp [value_type],0
jne invalid_use_of_symbol
test eax,eax
js value_out_of_range
enter_imm16_ok:
push eax
mov [operand_size],0
lods byte [esi]
cmp al,','
jne invalid_operand
lods byte [esi]
call get_size_operator
cmp ah,1
je enter_imm8_size_ok
or ah,ah
jnz invalid_operand_size
enter_imm8_size_ok:
cmp al,'('
jne invalid_operand
call get_byte_value
cmp [next_pass_needed],0
jne enter_imm8_ok
test eax,eax
js value_out_of_range
enter_imm8_ok:
mov dl,al
pop ebx
mov al,0C8h
stos byte [edi]
mov ax,bx
stos word [edi]
mov al,dl
stos byte [edi]
jmp instruction_assembled
ret_instruction_only64:
cmp [code_type],64
jne illegal_instruction
jmp ret_instruction
ret_instruction_32bit_except64:
cmp [code_type],64
je illegal_instruction
ret_instruction_32bit:
call operand_32bit
jmp ret_instruction
ret_instruction_16bit:
call operand_16bit
jmp ret_instruction
retf_instruction:
cmp [code_type],64
jne ret_instruction
ret_instruction_64bit:
call operand_64bit
ret_instruction:
mov [base_code],al
lods byte [esi]
dec esi
or al,al
jz simple_ret
cmp al,0Fh
je simple_ret
lods byte [esi]
call get_size_operator
or ah,ah
jz ret_imm
cmp ah,2
je ret_imm
jmp invalid_operand_size
ret_imm:
cmp al,'('
jne invalid_operand
call get_word_value
cmp [next_pass_needed],0
jne ret_imm_ok
cmp [value_type],0
jne invalid_use_of_symbol
test eax,eax
js value_out_of_range
ret_imm_ok:
cmp [size_declared],0
jne ret_imm_store
or ax,ax
jz simple_ret
ret_imm_store:
mov dx,ax
call store_instruction_code
mov ax,dx
stos word [edi]
jmp instruction_assembled
simple_ret:
inc [base_code]
call store_instruction_code
jmp instruction_assembled
lea_instruction:
mov [base_code],8Dh
lods byte [esi]
call get_size_operator
cmp al,10h
jne invalid_operand
lods byte [esi]
call convert_register
mov [postbyte_register],al
lods byte [esi]
cmp al,','
jne invalid_operand
xor al,al
xchg al,[operand_size]
push eax
lods byte [esi]
call get_size_operator
cmp al,'['
jne invalid_operand
mov [size_override],-1
call get_address
pop eax
mov [operand_size],al
call operand_autodetect
jmp instruction_ready
ls_instruction:
or al,al
jz les_instruction
cmp al,3
jz lds_instruction
add al,0B0h
mov [extended_code],al
mov [base_code],0Fh
jmp ls_code_ok
les_instruction:
mov [base_code],0C4h
jmp ls_short_code
lds_instruction:
mov [base_code],0C5h
ls_short_code:
cmp [code_type],64
je illegal_instruction
ls_code_ok:
lods byte [esi]
call get_size_operator
cmp al,10h
jne invalid_operand
lods byte [esi]
call convert_register
mov [postbyte_register],al
lods byte [esi]
cmp al,','
jne invalid_operand
add [operand_size],2
lods byte [esi]
call get_size_operator
cmp al,'['
jne invalid_operand
call get_address
mov al,[operand_size]
cmp al,4
je ls_16bit
cmp al,6
je ls_32bit
cmp al,10
je ls_64bit
jmp invalid_operand_size
ls_16bit:
call operand_16bit
jmp instruction_ready
ls_32bit:
call operand_32bit
jmp instruction_ready
ls_64bit:
call operand_64bit
jmp instruction_ready
sh_instruction:
mov [postbyte_register],al
lods byte [esi]
call get_size_operator
cmp al,10h
je sh_reg
cmp al,'['
jne invalid_operand
sh_mem:
call get_address
push edx ebx ecx
mov al,[operand_size]
push eax
mov [operand_size],0
lods byte [esi]
cmp al,','
jne invalid_operand
lods byte [esi]
call get_size_operator
cmp al,'('
je sh_mem_imm
cmp al,10h
jne invalid_operand
sh_mem_reg:
lods byte [esi]
cmp al,11h
jne invalid_operand
pop eax ecx ebx edx
cmp al,1
je sh_mem_cl_8bit
jb sh_mem_cl_nosize
call operand_autodetect
mov [base_code],0D3h
jmp instruction_ready
sh_mem_cl_nosize:
call recoverable_unknown_size
sh_mem_cl_8bit:
mov [base_code],0D2h
jmp instruction_ready
sh_mem_imm:
mov al,[operand_size]
or al,al
jz sh_mem_imm_size_ok
cmp al,1
jne invalid_operand_size
sh_mem_imm_size_ok:
call get_byte_value
mov byte [value],al
pop eax ecx ebx edx
cmp al,1
je sh_mem_imm_8bit
jb sh_mem_imm_nosize
call operand_autodetect
cmp byte [value],1
je sh_mem_1
mov [base_code],0C1h
call store_instruction_with_imm8
jmp instruction_assembled
sh_mem_1:
mov [base_code],0D1h
jmp instruction_ready
sh_mem_imm_nosize:
call recoverable_unknown_size
sh_mem_imm_8bit:
cmp byte [value],1
je sh_mem_1_8bit
mov [base_code],0C0h
call store_instruction_with_imm8
jmp instruction_assembled
sh_mem_1_8bit:
mov [base_code],0D0h
jmp instruction_ready
sh_reg:
lods byte [esi]
call convert_register
mov bx,ax
mov [operand_size],0
lods byte [esi]
cmp al,','
jne invalid_operand
lods byte [esi]
call get_size_operator
cmp al,'('
je sh_reg_imm
cmp al,10h
jne invalid_operand
sh_reg_reg:
lods byte [esi]
cmp al,11h
jne invalid_operand
mov al,bh
cmp al,1
je sh_reg_cl_8bit
call operand_autodetect
mov [base_code],0D3h
jmp nomem_instruction_ready
sh_reg_cl_8bit:
mov [base_code],0D2h
jmp nomem_instruction_ready
sh_reg_imm:
mov al,[operand_size]
or al,al
jz sh_reg_imm_size_ok
cmp al,1
jne invalid_operand_size
sh_reg_imm_size_ok:
push ebx
call get_byte_value
mov dl,al
pop ebx
mov al,bh
cmp al,1
je sh_reg_imm_8bit
call operand_autodetect
cmp dl,1
je sh_reg_1
mov [base_code],0C1h
call store_nomem_instruction
mov al,dl
stos byte [edi]
jmp instruction_assembled
sh_reg_1:
mov [base_code],0D1h
jmp nomem_instruction_ready
sh_reg_imm_8bit:
cmp dl,1
je sh_reg_1_8bit
mov [base_code],0C0h
call store_nomem_instruction
mov al,dl
stos byte [edi]
jmp instruction_assembled
sh_reg_1_8bit:
mov [base_code],0D0h
jmp nomem_instruction_ready
shd_instruction:
mov [base_code],0Fh
mov [extended_code],al
lods byte [esi]
call get_size_operator
cmp al,10h
je shd_reg
cmp al,'['
jne invalid_operand
shd_mem:
call get_address
push edx ebx ecx
lods byte [esi]
cmp al,','
jne invalid_operand
lods byte [esi]
call get_size_operator
cmp al,10h
jne invalid_operand
lods byte [esi]
call convert_register
mov [postbyte_register],al
lods byte [esi]
cmp al,','
jne invalid_operand
mov al,ah
mov [operand_size],0
push eax
lods byte [esi]
call get_size_operator
cmp al,'('
je shd_mem_reg_imm
cmp al,10h
jne invalid_operand
lods byte [esi]
cmp al,11h
jne invalid_operand
pop eax ecx ebx edx
call operand_autodetect
inc [extended_code]
jmp instruction_ready
shd_mem_reg_imm:
mov al,[operand_size]
or al,al
jz shd_mem_reg_imm_size_ok
cmp al,1
jne invalid_operand_size
shd_mem_reg_imm_size_ok:
call get_byte_value
mov byte [value],al
pop eax ecx ebx edx
call operand_autodetect
call store_instruction_with_imm8
jmp instruction_assembled
shd_reg:
lods byte [esi]
call convert_register
mov [postbyte_register],al
lods byte [esi]
cmp al,','
jne invalid_operand
lods byte [esi]
call get_size_operator
cmp al,10h
jne invalid_operand
lods byte [esi]
call convert_register
mov bl,[postbyte_register]
mov [postbyte_register],al
mov al,ah
push eax ebx
lods byte [esi]
cmp al,','
jne invalid_operand
mov [operand_size],0
lods byte [esi]
call get_size_operator
cmp al,'('
je shd_reg_reg_imm
cmp al,10h
jne invalid_operand
lods byte [esi]
cmp al,11h
jne invalid_operand
pop ebx eax
call operand_autodetect
inc [extended_code]
jmp nomem_instruction_ready
shd_reg_reg_imm:
mov al,[operand_size]
or al,al
jz shd_reg_reg_imm_size_ok
cmp al,1
jne invalid_operand_size
shd_reg_reg_imm_size_ok:
call get_byte_value
mov dl,al
pop ebx eax
call operand_autodetect
call store_nomem_instruction
mov al,dl
stos byte [edi]
jmp instruction_assembled
movx_instruction:
mov [base_code],0Fh
mov [extended_code],al
lods byte [esi]
call get_size_operator
cmp al,10h
jne invalid_operand
lods byte [esi]
call convert_register
mov [postbyte_register],al
mov al,ah
push eax
lods byte [esi]
cmp al,','
jne invalid_operand
mov [operand_size],0
lods byte [esi]
call get_size_operator
cmp al,10h
je movx_reg
cmp al,'['
jne invalid_operand
call get_address
pop eax
mov ah,[operand_size]
or ah,ah
jz movx_unknown_size
cmp ah,al
jae invalid_operand_size
cmp ah,1
je movx_mem_store
cmp ah,2
jne invalid_operand_size
inc [extended_code]
movx_mem_store:
call operand_autodetect
jmp instruction_ready
movx_unknown_size:
call recoverable_unknown_size
jmp movx_mem_store
movx_reg:
lods byte [esi]
call convert_register
pop ebx
xchg bl,al
cmp ah,al
jae invalid_operand_size
cmp ah,1
je movx_reg_8bit
cmp ah,2
je movx_reg_16bit
jmp invalid_operand_size
movx_reg_8bit:
call operand_autodetect
jmp nomem_instruction_ready
movx_reg_16bit:
call operand_autodetect
inc [extended_code]
jmp nomem_instruction_ready
movsxd_instruction:
mov [base_code],al
lods byte [esi]
call get_size_operator
cmp al,10h
jne invalid_operand
lods byte [esi]
call convert_register
mov [postbyte_register],al
cmp ah,8
jne invalid_operand_size
lods byte [esi]
cmp al,','
jne invalid_operand
mov [operand_size],0
lods byte [esi]
call get_size_operator
cmp al,10h
je movsxd_reg
cmp al,'['
jne invalid_operand
call get_address
cmp [operand_size],4
je movsxd_mem_store
cmp [operand_size],0
jne invalid_operand_size
movsxd_mem_store:
call operand_64bit
jmp instruction_ready
movsxd_reg:
lods byte [esi]
call convert_register
cmp ah,4
jne invalid_operand_size
mov bl,al
call operand_64bit
jmp nomem_instruction_ready
bt_instruction:
mov [postbyte_register],al
shl al,3
add al,83h
mov [extended_code],al
mov [base_code],0Fh
lods byte [esi]
call get_size_operator
cmp al,10h
je bt_reg
cmp al,'['
jne invalid_operand
call get_address
push eax ebx ecx
lods byte [esi]
cmp al,','
jne invalid_operand
cmp byte [esi],'('
je bt_mem_imm
cmp byte [esi],11h
jne bt_mem_reg
cmp byte [esi+2],'('
je bt_mem_imm
bt_mem_reg:
lods byte [esi]
call get_size_operator
cmp al,10h
jne invalid_operand
lods byte [esi]
call convert_register
mov [postbyte_register],al
pop ecx ebx edx
mov al,ah
call operand_autodetect
jmp instruction_ready
bt_mem_imm:
xor al,al
xchg al,[operand_size]
push eax
lods byte [esi]
call get_size_operator
cmp al,'('
jne invalid_operand
mov al,[operand_size]
or al,al
jz bt_mem_imm_size_ok
cmp al,1
jne invalid_operand_size
bt_mem_imm_size_ok:
call get_byte_value
mov byte [value],al
pop eax
or al,al
jz bt_mem_imm_nosize
call operand_autodetect
bt_mem_imm_store:
pop ecx ebx edx
mov [extended_code],0BAh
call store_instruction_with_imm8
jmp instruction_assembled
bt_mem_imm_nosize:
call recoverable_unknown_size
jmp bt_mem_imm_store
bt_reg:
lods byte [esi]
call convert_register
mov bl,al
lods byte [esi]
cmp al,','
jne invalid_operand
cmp byte [esi],'('
je bt_reg_imm
cmp byte [esi],11h
jne bt_reg_reg
cmp byte [esi+2],'('
je bt_reg_imm
bt_reg_reg:
lods byte [esi]
call get_size_operator
cmp al,10h
jne invalid_operand
lods byte [esi]
call convert_register
mov [postbyte_register],al
mov al,ah
call operand_autodetect
jmp nomem_instruction_ready
bt_reg_imm:
xor al,al
xchg al,[operand_size]
push eax ebx
lods byte [esi]
call get_size_operator
cmp al,'('
jne invalid_operand
mov al,[operand_size]
or al,al
jz bt_reg_imm_size_ok
cmp al,1
jne invalid_operand_size
bt_reg_imm_size_ok:
call get_byte_value
mov byte [value],al
pop ebx eax
call operand_autodetect
bt_reg_imm_store:
mov [extended_code],0BAh
call store_nomem_instruction
mov al,byte [value]
stos byte [edi]
jmp instruction_assembled
bs_instruction:
mov [extended_code],al
mov [base_code],0Fh
call get_reg_mem
jc bs_reg_reg
mov al,[operand_size]
call operand_autodetect
jmp instruction_ready
bs_reg_reg:
mov al,ah
call operand_autodetect
jmp nomem_instruction_ready
get_reg_mem:
lods byte [esi]
call get_size_operator
cmp al,10h
jne invalid_operand
lods byte [esi]
call convert_register
mov [postbyte_register],al
lods byte [esi]
cmp al,','
jne invalid_operand
lods byte [esi]
call get_size_operator
cmp al,10h
je get_reg_reg
cmp al,'['
jne invalid_argument
call get_address
clc
ret
get_reg_reg:
lods byte [esi]
call convert_register
mov bl,al
stc
ret
imul_instruction:
mov [base_code],0F6h
mov [postbyte_register],5
lods byte [esi]
call get_size_operator
cmp al,10h
je imul_reg
cmp al,'['
jne invalid_operand
imul_mem:
call get_address
mov al,[operand_size]
cmp al,1
je imul_mem_8bit
jb imul_mem_nosize
call operand_autodetect
inc [base_code]
jmp instruction_ready
imul_mem_nosize:
call recoverable_unknown_size
imul_mem_8bit:
jmp instruction_ready
imul_reg:
lods byte [esi]
call convert_register
cmp byte [esi],','
je imul_reg_
mov bl,al
mov al,ah
cmp al,1
je imul_reg_8bit
call operand_autodetect
inc [base_code]
imul_reg_8bit:
jmp nomem_instruction_ready
imul_reg_:
mov [postbyte_register],al
inc esi
cmp byte [esi],'('
je imul_reg_imm
cmp byte [esi],11h
jne imul_reg_noimm
cmp byte [esi+2],'('
je imul_reg_imm
imul_reg_noimm:
lods byte [esi]
call get_size_operator
cmp al,10h
je imul_reg_reg
cmp al,'['
jne invalid_operand
imul_reg_mem:
call get_address
push edx ebx ecx
cmp byte [esi],','
je imul_reg_mem_imm
mov al,[operand_size]
call operand_autodetect
pop ecx ebx edx
mov [base_code],0Fh
mov [extended_code],0AFh
jmp instruction_ready
imul_reg_mem_imm:
inc esi
lods byte [esi]
call get_size_operator
cmp al,'('
jne invalid_operand
mov al,[operand_size]
cmp al,2
je imul_reg_mem_imm_16bit
cmp al,4
je imul_reg_mem_imm_32bit
cmp al,8
jne invalid_operand_size
imul_reg_mem_imm_64bit:
cmp [size_declared],0
jne long_immediate_not_encodable
call operand_64bit
call get_simm32
cmp [value_type],4
jae long_immediate_not_encodable
jmp imul_reg_mem_imm_32bit_ok
imul_reg_mem_imm_16bit:
call operand_16bit
call get_word_value
mov word [value],ax
cmp [value_type],0
jne imul_reg_mem_imm_16bit_store
cmp [size_declared],0
jne imul_reg_mem_imm_16bit_store
cmp ax,-80h
jl imul_reg_mem_imm_16bit_store
cmp ax,80h
jl imul_reg_mem_imm_8bit_store
imul_reg_mem_imm_16bit_store:
pop ecx ebx edx
mov [base_code],69h
call store_instruction_with_imm16
jmp instruction_assembled
imul_reg_mem_imm_32bit:
call operand_32bit
call get_dword_value
imul_reg_mem_imm_32bit_ok:
mov dword [value],eax
cmp [value_type],0
jne imul_reg_mem_imm_32bit_store
cmp [size_declared],0
jne imul_reg_mem_imm_32bit_store
cmp eax,-80h
jl imul_reg_mem_imm_32bit_store
cmp eax,80h
jl imul_reg_mem_imm_8bit_store
imul_reg_mem_imm_32bit_store:
pop ecx ebx edx
mov [base_code],69h
call store_instruction_with_imm32
jmp instruction_assembled
imul_reg_mem_imm_8bit_store:
pop ecx ebx edx
mov [base_code],6Bh
call store_instruction_with_imm8
jmp instruction_assembled
imul_reg_imm:
mov bl,[postbyte_register]
dec esi
jmp imul_reg_reg_imm
imul_reg_reg:
lods byte [esi]
call convert_register
mov bl,al
cmp byte [esi],','
je imul_reg_reg_imm
mov al,ah
call operand_autodetect
mov [base_code],0Fh
mov [extended_code],0AFh
jmp nomem_instruction_ready
imul_reg_reg_imm:
inc esi
lods byte [esi]
call get_size_operator
cmp al,'('
jne invalid_operand
mov al,[operand_size]
cmp al,2
je imul_reg_reg_imm_16bit
cmp al,4
je imul_reg_reg_imm_32bit
cmp al,8
jne invalid_operand_size
imul_reg_reg_imm_64bit:
cmp [size_declared],0
jne long_immediate_not_encodable
call operand_64bit
push ebx
call get_simm32
cmp [value_type],4
jae long_immediate_not_encodable
jmp imul_reg_reg_imm_32bit_ok
imul_reg_reg_imm_16bit:
call operand_16bit
push ebx
call get_word_value
pop ebx
mov dx,ax
cmp [value_type],0
jne imul_reg_reg_imm_16bit_store
cmp [size_declared],0
jne imul_reg_reg_imm_16bit_store
cmp ax,-80h
jl imul_reg_reg_imm_16bit_store
cmp ax,80h
jl imul_reg_reg_imm_8bit_store
imul_reg_reg_imm_16bit_store:
mov [base_code],69h
call store_nomem_instruction
mov ax,dx
call mark_relocation
stos word [edi]
jmp instruction_assembled
imul_reg_reg_imm_32bit:
call operand_32bit
push ebx
call get_dword_value
imul_reg_reg_imm_32bit_ok:
pop ebx
mov edx,eax
cmp [value_type],0
jne imul_reg_reg_imm_32bit_store
cmp [size_declared],0
jne imul_reg_reg_imm_32bit_store
cmp eax,-80h
jl imul_reg_reg_imm_32bit_store
cmp eax,80h
jl imul_reg_reg_imm_8bit_store
imul_reg_reg_imm_32bit_store:
mov [base_code],69h
call store_nomem_instruction
mov eax,edx
call mark_relocation
stos dword [edi]
jmp instruction_assembled
imul_reg_reg_imm_8bit_store:
mov [base_code],6Bh
call store_nomem_instruction
mov al,dl
stos byte [edi]
jmp instruction_assembled
in_instruction:
lods byte [esi]
call get_size_operator
cmp al,10h
jne invalid_operand
lods byte [esi]
call convert_register
or al,al
jnz invalid_operand
lods byte [esi]
cmp al,','
jne invalid_operand
mov al,ah
push eax
mov [operand_size],0
lods byte [esi]
call get_size_operator
cmp al,'('
je in_imm
cmp al,10h
je in_reg
jmp invalid_operand
in_reg:
lods byte [esi]
cmp al,22h
jne invalid_operand
pop eax
cmp al,1
je in_al_dx
cmp al,2
je in_ax_dx
cmp al,4
jne invalid_operand_size
in_ax_dx:
call operand_autodetect
mov [base_code],0EDh
call store_instruction_code
jmp instruction_assembled
in_al_dx:
mov al,0ECh
stos byte [edi]
jmp instruction_assembled
in_imm:
mov al,[operand_size]
or al,al
jz in_imm_size_ok
cmp al,1
jne invalid_operand_size
in_imm_size_ok:
call get_byte_value
mov dl,al
pop eax
cmp al,1
je in_al_imm
cmp al,2
je in_ax_imm
cmp al,4
jne invalid_operand_size
in_ax_imm:
call operand_autodetect
mov [base_code],0E5h
call store_instruction_code
mov al,dl
stos byte [edi]
jmp instruction_assembled
in_al_imm:
mov al,0E4h
stos byte [edi]
mov al,dl
stos byte [edi]
jmp instruction_assembled
out_instruction:
lods byte [esi]
call get_size_operator
cmp al,'('
je out_imm
cmp al,10h
jne invalid_operand
lods byte [esi]
cmp al,22h
jne invalid_operand
lods byte [esi]
cmp