org 100h

jmp start

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

%include "dos-lib.asm"
%include "debug.asm"
%include "parser.asm"
%include "string.asm"
%include "version.inc"

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
start:
	push cs
	pop ax
	mov ds,ax
	mov es,ax
	mov fs,ax
	mov gs,ax

	call init_memory
	cmp ax,0xffff
	je near .end

	mov si,msg_startup
	call print

	mov di,buffer_cmdline
	call get_cmdline

	cmp ax,0xffff
	je near .end

	mov si,buffer_cmdline
	call parse_cmdline

	cmp ax,0xffff
	je near .end

	xor al,al
	mov dx,word[file_in]
	call open_file
	cmp ax,0xffff
	je near .end
	mov word[file_in_handle],ax

	mov bx,0x1000
	call alloc_memory
	cmp ax,0xffff
	je near .end
	mov word[mem_offset],ax

	call alloc_memory
	cmp ax,0xffff
	je near .end
	mov word[mem_label],ax

	call alloc_memory
	cmp ax,0xffff
	je near .end
	mov word[mem_fileout],ax

	mov bx,word[file_in_handle]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.loop_pass1
	mov byte[failure],0

	mov bx,word[file_in_handle]
	call read_line
	inc dword[lines]
	mov word[pointer_read],0

	cmp byte[failure],0x0d
	je .end_pass1

	call create_label_table

	cmp byte[ffailure],0x0d
	je short .end_pass1

	cmp byte[ffailure],0xff
	je near .end

	jmp short .loop_pass1
.end_pass1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	mov byte[ffailure],0
	mov word[act_label],-1

	mov ah,42h
	xor al,al
	xor dx,dx
	xor cx,cx
	mov bx,word[file_in_handle]
	int 21h

	jc near .end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.loop_pass2
	mov byte[failure],0

	mov bx,word[file_in_handle]
	call read_line
	inc dword[line]
	mov word[pointer_read],0

	cmp byte[failure],0x0d
	je .end_pass2

	call asm_line

	cmp byte[ffailure],0x0d
	je short .end_pass2

	cmp byte[ffailure],0xff
	je near .end

	jmp short .loop_pass2
.end_pass2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

	test byte[options],10000000b
	je .loop_pass3

	mov si,msg_label_table
	call print
	call print_label_table
	mov si,msg_newline
	call print
	mov si,msg_offset_table
	call print
	call print_offset_table
	mov si,msg_newline
	call print

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.loop_pass3
	call create_fileout
.end_pass3
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	cmp al,0xff
	je .end

	mov si,[file_out]
	cmp si,0
	jne .file_out_ok

	mov si,[file_in]

.loop_file_out
	lodsb

	cmp al,'.'
	jne .loop_file_out

	dec si
	mov byte[ds:si],0

	mov ax,word[file_in]
	mov word[file_out],ax

.file_out_ok

	mov dx,[file_out]
	xor cx,cx
	call create_file
	cmp ax,0xffff
	je .end

	mov [file_out_handle],ax

	mov bx,ax
	mov cx,word[pointer_write]
	push ds
	mov ds,[mem_fileout]
	xor dx,dx
	call write_file
	pop ds
	cmp ax,0xffff
	je .end

	mov bx,[file_out_handle]
	call close_file

	mov si,msg_newline
	call print

	mov eax,dword[lines]
	mov si,lines_str
	call bin2decascii
	call print

	mov si,msg_lines_asm
	call print

.end
	mov bx,word[file_in_handle]
	call close_file

	mov es,[mem_label]
	call dealloc_memory

	mov es,[mem_offset]
	call dealloc_memory

	mov es,[mem_fileout]
	call dealloc_memory

	mov ax,4c00h
	int 21h
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
init_memory:
	pusha

	mov bx,end_progg
	shr bx,4
	inc bx

	call resize_memory

	cmp ax,0xffff
	je .end_failure

.end
	popa
	ret
.end_failure
	popa
	mov ax,0xffff
	ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;	Input:
;;	SI = pointer to buffer of the cmdline (first word have to be the number of arguments)
parse_cmdline:
	pusha

	lodsw
	mov cx,ax
.loop_parse
	lodsb

	cmp al,'-'
	je .cmd


	dec si
	and al,al
	jz .end_loop_parse

	mov word[file_in],si
.loop_filein
	lodsb

	and al,al
	jnz .loop_filein

	jmp short .end_loop_parse
.cmd
	lodsb

	cmp al,'o'
	je .cmd_out

	cmp al,'h'
	je .cmd_help

	cmp al,'d'
	je .cmd_debug

	cmp al,'l'
	je .cmd_line_buf

.cmd_unkwn
	mov si,msg_unknown_para
	call print

	jmp short .end_failure
.cmd_out
	lodsb

	and al,al
	jz .cmd_out1

	dec si
	mov word[file_out],si

	dec cx

	jmp .cmd_out_loop
.cmd_out1
	lodsb

	and al,al
	jz .cmd_out_error

	dec si
	mov word[file_out],si

.cmd_out_loop
	lodsb

	and al,al
	jnz .cmd_out_loop

	jmp .end_loop_parse
.cmd_out_error
	mov si,msg_incomplete_para
	call print
	jmp short .end_failure
.cmd_help
	lodsb
	and al,al
	jnz .cmd_unkwn

	mov si,msg_info
	call print
	jmp .end_failure
.cmd_debug
	lodsb
	and al,al
	jnz .cmd_unkwn

	or byte[options],10000000b

	jmp short .end_loop_parse
.cmd_line_buf
	lodsb

	cmp al,'b'
	jne .cmd_unkwn

	lodsb

	and al,al
	jnz .cmd_unkwn

	mov di,buffer_opcode
.cmd_line_buf@loop
	lodsb

	stosb

	and al,al
	jnz .cmd_line_buf@loop

	push si
	mov si,buffer_opcode
	call decascii2bin
	pop si

	mov word[line_buf_len],ax

	dec cx

	jmp short .end_loop_parse

.end_loop_parse
	dec cx
	and cx,cx
	jnz near .loop_parse

	mov si,[file_in]
	cmp si,0
	je .no_in

.end
	popa
	ret
.no_in
	mov si,msg_no_in
	call print
.end_failure
	popa
	mov ax,0xffff
	ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 	IN :
;;	SI=pointer to error message
;;	AX=line where error is
print_error:
	pushad

	push si
	mov si,word[file_in]
	call print

	mov dl,':'
	call printc

	mov si,lines_str
	call bin2decascii
	call print

	mov dl,':'
	call printc

	mov si,msg_error
	call print

	pop si
	call print
.end
	popad
	ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;	Input :
;;	SI = pointer to label string (0-terminated)
add_label2table:
	pusha
	push es

	mov es,[mem_label]
	mov di,word[label_free]

	add di,2
	mov ax,-1
	stosw

.loop
	lodsb

	stosb
	and al,al
	jnz short .loop

	mov ax,word[label_free]
	mov [label_free],word di

	push di
	mov di,ax
	pop ax
	stosw

.end
	pop es
	popa
	ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;	Input :
;;	CX = offset (where label is)
;;	AX = offset (of the label)
add_offset2label:
	pusha
	push es

	mov es,[mem_label]
	mov di,cx

	add di,2
	stosw

.end
	pop es
	popa
	ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;	Input :
;;	SI = pointer to label string (0-terminated)
;;	Output :
;;	AL = 0 / BX = label offset / CX = pointer to label
;;	AL = 1 (no label found)
look4label:
	push di
	push si
	push es

	mov es,[mem_label]
	xor di,di
	xor bx,bx

	lodsb
	dec si

	cmp al,'.'
	jnz .loop_local

	mov di,word[act_label]
	mov bx,word[es:di]
.loop_no_local
	mov di,bx

	mov bx,word[es:di]

	cmp di,word[label_free]
	je .end_not

	add di,4

	mov al,byte[es:di]
	cmp al,'.'
	jne .end_not

	call string_cmp

	and ax,ax
	jnz .loop_no_local
	jz .end

.loop_local
	mov di,bx

	mov bx,word[es:di]

	cmp di,word[label_free]
	je .end_not

	add di,4

	call string_cmp

	and ax,ax
	jnz .loop_local

.end
	sub di,4
	mov cx,di
	add di,2
	mov bx,word[es:di]
	xor al,al

	pop es
	pop si
	pop di
	ret
.end_not
	mov al,1

	pop es
	pop si
	pop di
	ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
create_label_table:
	pusha

	mov si,line_buf
	mov di,buffer_opcode
	mov cx,word[pointer_read]
	call parse_line
	add word[pointer_read],cx

	cmp byte[failure],0
	jne near .end

	mov si,buffer_opcode
	call string_len

	add si,cx
	dec si
	lodsb
	cmp al,':'
	je .label_dpoint

	sub si,cx
	lodsb
	dec si
	cmp al,'.'
	je .label_point

	mov si,line_buf
	mov di,buffer_bef1
	mov cx,word[pointer_read]
	call parse_line

	cmp byte[failure],0
	jne .end

	mov si,op_db
	call string_cmp
	and ax,ax
	jz .label_var

	mov si,op_dw
	call string_cmp
	and ax,ax
	jz .label_var

	mov si,op_dd
	call string_cmp
	and ax,ax
	jnz .end

.label_var
	mov si,buffer_opcode

	call look4label
	and al,al
	jz .error_label_is_there

	call add_label2table

	jmp short .end
.label_point
	cmp word[act_label],-1
	je .error_no_local_label

	call look4label
	and al,al
	jz .error_label_is_there

	call add_label2table

	jmp short .end
.label_dpoint
	dec si
	mov byte[si],0
	inc si
	sub si,cx

	call look4label
	and al,al
	jz .error_label_is_there

	call add_label2table

	call look4label

	mov word[act_label],cx

.end
	popa
	ret
.error_no_local_label
	mov ax,word[lines]
	mov si,msg_no_local_label
	call print_error
	mov byte[ffailure],0xff
	popa
	ret
.error_label_is_there
	mov ax,word[lines]
	mov si,msg_label_is_there
	call print_error
	mov byte[ffailure],0xff
	popa
	ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
print_label_table:
	pusha

	mov fs,[mem_label]
	xor si,si

.loop
	cmp si,word[label_free]
	je near .end

	add si,2
	mov bx,word[fs:si]
	add si,2
	mov di,buffer_opcode
.loop_label
	mov al,byte[fs:si]
	inc si

	stosb

	and al,al
	jz .loop_end

	jmp .loop_label
.loop_end
	push si
	mov si,buffer_opcode
	call print
	mov dl,9
	call printc
	mov ax,bx
	call hex2ascii16bit_str
	mov si,msg_newline
	call print
	pop si
	jmp .loop

.end
	popa
	ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
print_offset_table:
	pusha
	push es

	mov es,[mem_offset]
	xor di,di

.loop
	cmp di,word[offset_free]
	je near .end
	mov al,byte[es:di]
	inc di

	mov si,msg_newline
	call print

.loop_type1
	cmp al,1
	jne .loop_type2

	mov ax,word[es:di]
	add di,2

	call hex2ascii16bit_str
	mov dl,' '
	call printc

	mov ax,word[es:di]
	add di,2

	call hex2ascii16bit_str

	jmp .loop
.loop_type2
	cmp al,2
	jne .loop_type3

	mov ax,word[es:di]
	add di,2

	call hex2ascii16bit_str
	mov dl,' '
	call printc

	mov ax,word[es:di]
	add di,2

	call hex2ascii16bit_str
	mov dl,' '
	call printc

	mov ax,word[es:di]
	add di,2

	call hex2ascii16bit_str

	jmp .loop
.loop_type3
	mov ax,word[es:di]
	add di,2

	call hex2ascii16bit_str
	mov dl,' '
	call printc

	mov ax,word[es:di]
	add di,2

	call hex2ascii16bit_str
	mov dl,' '
	call printc

	mov ax,word[es:di]
	add di,2

	call hex2ascii16bit_str
	mov dl,' '
	call printc

	mov ax,word[es:di]
	add di,2

	call hex2ascii16bit_str

	jmp .loop

.end
	pop es
	popa
	ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
asm_line:
	pushad

	mov gs,[mem_fileout]
	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_opcode
	call parse_line
	add word[pointer_read],cx

	cmp byte[failure],0
	jne near .end

	mov si,buffer_opcode
	lodsb
	dec si

	cmp al,'.'
	je .label_point

	call string_len
	add si,cx
	dec si
	lodsb

	cmp al,':'
	je .label_dpoint

	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef1
	call parse_line

	cmp byte[failure],0
	jne .end_label_test

	mov si,op_db
	call string_cmp
	and ax,ax
	jz .label_var

	mov si,op_dw
	call string_cmp
	and ax,ax
	jz .label_var

	mov si,op_dd
	call string_cmp
	and ax,ax
	jz .label_var

.end_label_test
	mov si,buffer_opcode

	jmp short .start_asm
.label_point
	call look4label

	mov ax,word[act_offset]
	call add_offset2label

	jmp near .end
.label_dpoint
	dec si
	mov byte[ds:si],0
	inc si
	sub si,cx

	call look4label

	mov word[act_label],cx

	mov ax,word[act_offset]
	call add_offset2label

	jmp near .end
.label_var
	add word[pointer_read],cx

	mov si,buffer_opcode
	call look4label

	mov ax,word[act_offset]
	call add_offset2label

	mov si,buffer_bef1
.start_asm

.op_db
	mov di,op_db
	call string_cmp
	and ax,ax
	jnz .op_dw

.op_db@loop
	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef1
	call parse_line
	add word[pointer_read],cx

	mov si,buffer_bef1
	lodsb

	mov di,word[pointer_write]

	and al,al
	jz near .end

	cmp al,0x27
	je .op_db@ascii
	cmp al,0x22
	je .op_db@ascii

	dec si

	call format_numbers_8bit
	jc near .error_opcode

	mov byte[gs:di],al

	inc word[pointer_write]
	inc word[act_offset]

	jmp short .op_db@loop
.op_db@ascii
	mov dl,al
.op_db@ascii@loop
	lodsb

	cmp al,dl
	je short .op_db@loop

	mov byte[gs:di],al
	inc di
	inc word[pointer_write]
	inc word[act_offset]

	jmp short .op_db@ascii@loop
.op_dw
	mov di,op_dw
	call string_cmp
	and ax,ax
	jnz .op_dd

.op_dw@loop
	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef1
	call parse_line
	add word[pointer_read],cx

	mov si,buffer_bef1
	lodsb

	mov di,word[pointer_write]

	and al,al
	jz near .end

	dec si
	call format_numbers_16bit
	jc near .error_opcode

	mov word[gs:di],ax

	add word[pointer_write],2
	add word[act_offset],2

	jmp short .op_dw@loop
.op_dd
	mov di,op_dd
	call string_cmp
	and ax,ax
	jnz .op_org

.op_dd@loop
	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef1
	call parse_line
	add word[pointer_read],cx

	mov si,buffer_bef1
	lodsb

	mov di,word[pointer_write]

	and al,al
	jz near .end

	dec si
	call format_numbers_32bit
	jc near .error_opcode

	mov dword[gs:di],eax

	add word[pointer_write],4
	add word[act_offset],4

	jmp short .op_dd@loop
.op_org
	mov di,op_org
	call string_cmp
	and ax,ax
	jnz .op_int

	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef1
	call parse_line
	add word[pointer_read],cx

	cmp byte[failure],0
	jne near .error_opcode

	mov si,buffer_bef1
	call format_numbers_16bit
	jc near .error_opcode

	mov word[act_offset],ax
	mov word[act_org],ax

	jmp near .end
.op_int
	mov di,op_int
	call string_cmp
	and ax,ax
	jnz .op_pop

	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef1
	call parse_line
	add word[pointer_read],cx

	cmp byte[failure],0
	jne near .error_opcode

	mov si,buffer_bef1
	call format_numbers_8bit
	jc near .error_opcode

	mov di,word[pointer_write]
	mov ah,0xcd
	xchg al,ah
	mov word[gs:di],ax

	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.op_pop
	mov di,op_pop
	call string_cmp
	and ax,ax
	jnz near .op_push

	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef1
	call parse_line
	add word[pointer_read],cx

	cmp byte[failure],0
	jne near .error_opcode

	jmp short .op_pop@asm
.op_pop@many_op
	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef1
	call parse_line
	add word[pointer_read],cx

	cmp byte[failure],0
	jne near .end
.op_pop@asm
	mov si,buffer_bef1

	call translate_16bit_reg
	cmp al,0xff
	jne .op_pop@reg16bit

	call translate_32bit_reg
	cmp al,0xff
	jne .op_pop@reg32bit

	call translate_seg_reg
	cmp al,0xff
	jne .op_pop@regseg

	push si
	mov di,op_word
	cmpsd
	pop si
	je near .op_pop@var_word

	push si
	mov di,op_dword
	mov cx,5
	rep cmpsb
	pop si
	je near .op_pop@var_dword

	jmp near .error_opcode
.op_pop@reg16bit
	add al,58h

	mov si,word[pointer_write]
	mov byte[gs:si],al
	inc word[pointer_write]
	inc word[act_offset]

	jmp near .op_pop@many_op
.op_pop@reg32bit
	add al,58h
	mov ah,66h
	xchg al,ah

	mov si,word[pointer_write]
	mov word[gs:si],ax
	add word[pointer_write],2
	add word[act_offset],2

	jmp near .op_pop@many_op
.op_pop@regseg
	mov si,word[pointer_write]

	and al,al
	jnz .op_pop@regseg@1

	mov byte[gs:si],07h
	inc word[pointer_write]
	inc word[act_offset]

	jmp near .op_pop@many_op
.op_pop@regseg@1
	cmp al,1
	jne .op_pop@regseg@2

	jmp near .error_opcode
.op_pop@regseg@2
	cmp al,2
	jne .op_pop@regseg@3

	mov byte[gs:si],17h
	inc word[pointer_write]
	inc word[act_offset]

	jmp near .op_pop@many_op
.op_pop@regseg@3
	cmp al,3
	jne .op_pop@regseg@4

	mov byte[gs:si],1fh
	inc word[pointer_write]
	inc word[act_offset]

	jmp near .op_pop@many_op
.op_pop@regseg@4
	cmp al,4
	jne .op_pop@regseg@5

	mov word[gs:si],0xa10f
	add word[pointer_write],2
	add word[act_offset],2

	jmp near .op_pop@many_op
.op_pop@regseg@5
	mov word[gs:si],0xa90f
	add word[pointer_write],2
	add word[act_offset],2

	jmp near .op_pop@many_op
.op_pop@var_word
	add si,4
	call test_clips
	cmp al,0xff
	je near .error_no_clips

	call look4label
	and al,al
	jnz near .error_label

	mov si,word[pointer_write]
	mov word[gs:si],0x068f
	add word[pointer_write],2
	add word[act_offset],2
	add si,2

	cmp bx,-1
	je near .op_pop@var_word@no_offset

	call .asm@offset

	jmp near .op_pop@many_op
.op_pop@var_word@no_offset
	mov al,1
	call add_offset2offset_table

	add word[pointer_write],2
	add word[act_offset],2

	jmp near .op_pop@many_op
.op_pop@var_dword
	add si,5
	call test_clips
	cmp al,0xff
	je near .error_no_clips

	call look4label
	and al,al
	jnz near .error_label

	mov si,word[pointer_write]
	mov byte[gs:si],66h
	inc si
	mov word[gs:si],0x068f
	add si,2
	add word[pointer_write],3
	add word[act_offset],3

	cmp bx,-1
	je near .op_pop@var_dword@no_offset

	call .asm@offset

	jmp near .op_pop@many_op
.op_pop@var_dword@no_offset
	mov al,1
	call add_offset2offset_table

	add word[pointer_write],2
	add word[act_offset],2

	jmp near .op_pop@many_op
.op_push
	mov di,op_push
	call string_cmp
	and ax,ax
	jnz near .op_mov

	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef1
	call parse_line
	add word[pointer_read],cx

	cmp byte[failure],0
	jne near .error_opcode

	jmp short .op_push@asm
.op_push@many_op
	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef1
	call parse_line
	add word[pointer_read],cx

	cmp byte[failure],0
	jne near .end
.op_push@asm
	mov si,buffer_bef1

	call translate_16bit_reg
	cmp al,0xff
	jne .op_push@reg16bit

	call translate_32bit_reg
	cmp al,0xff
	jne .op_push@reg32bit

	call translate_seg_reg
	cmp al,0xff
	jne .op_push@regseg

	mov di,op_byte
	call string_cmp
	and ax,ax
	jz near .op_push@num_byte

	push si
	mov di,op_word
	cmpsd
	pop si
	je near .op_push@var_word

	push si
	mov di,op_dword
	mov cx,5
	rep cmpsb
	pop si
	je near .op_push@var_dword

	jmp near .error_opcode
.op_push@reg16bit
	add al,50h

	mov si,word[pointer_write]
	mov byte[gs:si],al
	inc word[pointer_write]
	inc word[act_offset]

	jmp near .op_push@many_op
.op_push@reg32bit
	add al,50h
	mov ah,66h
	xchg al,ah

	mov si,word[pointer_write]
	mov word[gs:si],ax
	add word[pointer_write],2
	add word[act_offset],2

	jmp near .op_push@many_op
.op_push@regseg
	mov si,word[pointer_write]

	and al,al
	jnz .op_push@regseg@1

	mov byte[gs:si],06h
	inc word[pointer_write]
	inc word[act_offset]

	jmp near .op_push@many_op
.op_push@regseg@1
	cmp al,1
	jne .op_push@regseg@2

	mov byte[gs:si],0eh
	inc word[pointer_write]
	inc word[act_offset]

	jmp near .op_push@many_op
.op_push@regseg@2
	cmp al,2
	jne .op_push@regseg@3

	mov byte[gs:si],16h
	inc word[pointer_write]
	inc word[act_offset]

	jmp near .op_push@many_op
.op_push@regseg@3
	cmp al,3
	jne .op_push@regseg@4

	mov byte[gs:si],1eh
	inc word[pointer_write]
	inc word[act_offset]

	jmp near .op_push@many_op
.op_push@regseg@4
	cmp al,4
	jne .op_push@regseg@5

	mov word[gs:si],0xa00f
	add word[pointer_write],2
	add word[act_offset],2

	jmp near .op_push@many_op
.op_push@regseg@5
	mov word[gs:si],0xa80f
	add word[pointer_write],2
	add word[act_offset],2

	jmp near .op_push@many_op
.op_push@var_word
	add si,4

	lodsb
	dec si
	and al,al
	jz near .op_push@num_word

	call test_clips
	cmp al,0xff
	je near .error_no_clips

	call look4label
	and al,al
	jnz near .error_label

	mov si,word[pointer_write]
	mov word[gs:si],0x36ff
	add word[pointer_write],2
	add word[act_offset],2
	add si,2

	cmp bx,-1
	je near .op_push@var_word@no_offset

	call .asm@offset

	jmp near .op_push@many_op
.op_push@var_word@no_offset
	mov al,1
	call add_offset2offset_table

	add word[pointer_write],2
	add word[act_offset],2

	jmp near .op_push@many_op
.op_push@var_dword
	add si,5

	lodsb
	dec si
	and al,al
	jz near .op_push@num_dword

	call test_clips
	cmp al,0xff
	je near .error_no_clips

	call look4label
	and al,al
	jnz near .error_label

	mov si,word[pointer_write]
	mov byte[gs:si],66h
	inc si
	mov word[gs:si],0x36ff
	add si,2
	add word[pointer_write],3
	add word[act_offset],3

	cmp bx,-1
	je near .op_push@var_dword@no_offset

	call .asm@offset

	jmp near .op_push@many_op
.op_push@var_dword@no_offset
	mov al,1
	call add_offset2offset_table

	add word[pointer_write],2
	add word[act_offset],2

	jmp near .op_push@many_op
.op_push@num_byte
	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef2
	call parse_line
	add word[pointer_read],cx

	cmp byte[failure],0
	jne near .error_opcode

	mov si,buffer_bef2
	call format_numbers_8bit
	jc near .error_opcode

	mov si,word[pointer_write]
	mov ah,6ah
	xchg al,ah

	mov word[gs:si],ax
	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.op_push@num_word
	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef2
	call parse_line
	add word[pointer_read],cx

	cmp byte[failure],0
	jne near .error_opcode

	mov si,buffer_bef2
	call format_numbers_16bit
	jc near .error_opcode

	mov si,word[pointer_write]

	mov byte[gs:si],68h
	inc si
	mov word[gs:si],ax
	add word[pointer_write],3
	add word[act_offset],3

	jmp near .end
.op_push@num_dword
	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef2
	call parse_line
	add word[pointer_read],cx

	cmp byte[failure],0
	jne near .error_opcode

	mov si,buffer_bef2
	call format_numbers_32bit
	jc near .error_opcode

	mov si,word[pointer_write]

	mov word[gs:si],0x6866
	add si,2
	mov dword[gs:si],eax
	add word[pointer_write],6
	add word[act_offset],6

	jmp near .end
.op_mov
	mov di,op_mov
	call string_cmp
	and ax,ax
	jnz near .op_jmp

	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef1
	call parse_line
	add word[pointer_read],cx

	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef2
	call parse_line
	add word[pointer_read],cx

	cmp byte[failure],0
	jne near .error_opcode

	mov si,buffer_bef1
	call translate_8bit_reg
	cmp al,0xff
	jne near .op_mov@reg_var_byte

	call translate_16bit_reg
	cmp al,0xff
	jne near .op_mov@reg_var_word

	call translate_32bit_reg
	cmp al,0xff
	jne near .op_mov@reg_var_dword

	call translate_seg_reg
	cmp al,0xff
	jne near .op_mov@seg_reg

	push si
	mov di,op_byte
	cmpsd
	pop si
	je near .op_mov@reg_var_byte

	push si
	mov di,op_word
	cmpsd
	pop si
	je near .op_mov@reg_var_word

	push si
	mov di,op_dword
	mov cx,5
	rep cmpsb
	pop si
	je near .op_mov@reg_var_dword

	push si
	mov di,reg_dr
	cmpsw
	pop si
	je .op_mov@dr_reg

	push si
	mov di,reg_cr
	cmpsw
	pop si
	je .op_mov@cr_reg

	jmp near .error_opcode
.op_mov@dr_reg
	add si,2
	lodsb
	and al,al
	jz near .error_opcode
	cmp al,'7'
	jg near .error_opcode
	cmp al,'0'
	jl near .error_opcode
	mov dl,al
	lodsb
	and al,al
	jnz near .error_opcode

	mov si,buffer_bef2
	call translate_32bit_reg
	cmp al,0xff
	je near .error_opcode

	push ax
	mov al,dl
	call ascii_char2hex
	mov dl,al
	pop ax

	shl dl,3
	or al,dl
	or al,11000000b
	mov si,word[pointer_write]
	mov word[gs:si],0x230f
	add si,2
	mov byte[gs:si],al
	add word[pointer_write],3
	add word[act_offset],3

	jmp	near .end
.op_mov@cr_reg
	add si,2
	lodsb
	and al,al
	jz near .error_opcode
	cmp al,'4'
	jg near .error_opcode
	cmp al,'0'
	jl near .error_opcode
	mov dl,al
	lodsb
	and al,al
	jnz near .error_opcode

	mov si,buffer_bef2
	call translate_32bit_reg
	cmp al,0xff
	je near .error_opcode

	push ax
	mov al,dl
	call ascii_char2hex
	mov dl,al
	pop ax

	shl dl,3
	or al,dl
	or al,11000000b
	mov si,word[pointer_write]
	mov word[gs:si],0x220f
	add si,2
	mov byte[gs:si],al
	add word[pointer_write],3
	add word[act_offset],3

	jmp	near .end
.op_mov@seg_reg
	mov dl,al

	mov si,buffer_bef2
	call translate_16bit_reg
	cmp al,0xff
	jne .op_mov@seg_reg@reg

	mov di,op_word
	cmpsd
	jne near .error_opcode
.op_mov@seg_reg@var
	call test_clips
	and al,al
	jnz near .error_no_clips

	call look4label
	and al,al
	jnz near .error_label

	mov si,word[pointer_write]

	shl dl,3
	or dl,6
	mov byte[gs:si],0x8e
	inc si
	mov byte[gs:si],dl
	inc si
	add word[pointer_write],2
	add word[act_offset],2

	cmp bx,-1
	je .op_mov@seg_reg@var@no_offset

	call .asm@offset

	jmp near .end
.op_mov@seg_reg@var@no_offset
	mov al,1
	call add_offset2offset_table

	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.op_mov@seg_reg@reg
	mov si,word[pointer_write]

	shl dl,3
	or dl,al
	or dl,11000000b
	mov byte[gs:si],8eh
	inc si
	mov byte[gs:si],dl
	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.op_mov@reg_var_byte
	mov dl,al

	cmp dl,0xff
	je near .op_mov@reg_var_byte@var

	mov si,buffer_bef2
	call translate_8bit_reg
	cmp al,0xff
	jne near .op_mov@reg_var_byte@reg

	call format_numbers_8bit
	jnc near .op_mov@reg_var_byte@num

	mov di,op_byte
	cmpsd
	jne near .error_opcode

	call test_clips
	and al,al
	jnz near .error_no_clips

	call format_address_16bit
	cmp ax,0xffff
	jne .op_mov@reg_var_byte@addr@var

	call look4label
	and al,al
	jnz near .error_label

	mov si,word[pointer_write]
	shl dl,3
	or dl,6
	mov byte[gs:si],8ah
	inc si
	mov byte[gs:si],dl
	inc si
	add word[pointer_write],2
	add word[act_offset],2

	cmp bx,-1
	je .op_mov@reg_var_byte@no_offset

	call .asm@offset

	jmp near .end
.op_mov@reg_var_byte@no_offset
	mov al,1
	call add_offset2offset_table

	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.op_mov@reg_var_byte@addr@var
	mov si,word[pointer_write]
	mov byte[gs:si],al
	inc si
	mov byte[gs:si],8ah
	inc si

	shl dl,3
	or dl,ah
	mov byte[gs:si],dl
	add word[pointer_write],3
	add word[act_offset],3

	jmp near .end
.op_mov@reg_var_byte@var
	add si,4
	call test_clips
	and al,al
	jnz near .error_no_clips

	call format_address_16bit
	cmp ax,0xffff
	jne .op_mov@reg_var_byte@addr@reg

	call look4label
	and al,al
	jnz near .error_label

	mov si,buffer_bef2
	call translate_8bit_reg
	cmp al,0xff
	jne .op_mov@reg_var_byte@var@reg

	call format_numbers_8bit
	jc near .error_opcode

	mov si,word[pointer_write]
	mov word[gs:si],0x06c6
	add si,2
	add word[pointer_write],2
	add word[act_offset],2
	push ax

	cmp bx,-1
	je near .asm_set5@var_byte@no_offset
	jmp near .asm_set5@var_byte@offset
.op_mov@reg_var_byte@addr@reg
	mov bx,ax
	mov si,buffer_bef2
	call translate_8bit_reg
	cmp al,0xff
	je near .error_opcode

	mov si,word[pointer_write]
	mov byte[gs:si],bl
	inc si
	mov byte[gs:si],88h
	inc si

	shl al,3
	or al,bh
	mov byte[gs:si],al
	add word[pointer_write],3
	add word[act_offset],3

	jmp near .end
.op_mov@reg_var_byte@var@reg
	shl al,3
	or al,00000110b
	mov si,word[pointer_write]
	mov byte[gs:si],88h
	inc si
	mov byte[gs:si],al
	inc si
	add word[pointer_write],2
	add word[act_offset],2

	cmp bx,-1
	je .op_mov@reg_var_byte@var@no_offset

	call .asm@offset

	jmp near .end
.op_mov@reg_var_byte@var@no_offset
	mov al,1
	call add_offset2offset_table

	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.op_mov@reg_var_byte@num
	mov si,word[pointer_write]
	add dl,0xb0
	mov byte[gs:si],dl
	inc si
	mov byte[gs:si],al
	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.op_mov@reg_var_byte@reg
	mov si,word[pointer_write]

	shl dl,3
	or dl,al
	or dl,11000000b
	mov byte[gs:si],8ah
	inc si
	mov byte[gs:si],dl
	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.op_mov@reg_var_word
	mov dl,al

	mov si,buffer_bef2
	call translate_seg_reg
	cmp al,0xff
	jne near .op_mov@reg_var_word@seg

	mov si,buffer_bef1
	cmp dl,0xff
	je near .op_mov@reg_var_word@var

	mov si,buffer_bef2
	call translate_16bit_reg
	cmp al,0xff
	jne near .op_mov@reg_var_word@reg

	call format_numbers_16bit
	jnc near .op_mov@reg_var_word@num

	push si
	mov di,op_word
	cmpsd
	pop si
	jne near .op_mov@reg_var_word@var_num

	add si,4

	call test_clips
	and al,al
	jnz near .error_no_clips

	call format_address_16bit
	cmp ax,0xffff
	jne near .op_mov@reg_var_word@addr@var

	call look4label
	and al,al
	jnz near .error_label

	mov si,word[pointer_write]
	shl dl,3
	or dl,6
	mov byte[gs:si],8bh
	inc si
	mov byte[gs:si],dl
	inc si
	add word[pointer_write],2
	add word[act_offset],2

	cmp bx,-1
	je .op_mov@reg_var_word@no_offset

	call .asm@offset

	jmp near .end
.op_mov@reg_var_word@no_offset
	mov al,1
	call add_offset2offset_table

	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.op_mov@reg_var_word@var_num
	call look4label
	and al,al
	jnz near .error_label

	mov si,word[pointer_write]
	add dl,0xb8
	mov byte[gs:si],dl
	inc si
	inc word[pointer_write]
	inc word[act_offset]

	cmp bx,-1
	je .op_mov@reg_var_word@var_num@no_offset

	call .asm@offset

	jmp near .end
.op_mov@reg_var_word@var_num@no_offset
	mov al,1
	call add_offset2offset_table

	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.op_mov@reg_var_word@addr@var
	mov si,word[pointer_write]
	mov byte[gs:si],al
	inc si
	mov byte[gs:si],8bh
	inc si

	shl dl,3
	or dl,ah
	mov byte[gs:si],dl
	add word[pointer_write],3
	add word[act_offset],3

	jmp near .end
.op_mov@reg_var_word@var
	add si,4
	call test_clips
	and al,al
	jnz near .error_no_clips

	call format_address_16bit
	cmp ax,0xffff
	jne .op_mov@reg_var_word@addr

	call look4label
	and al,al
	jnz near .error_label

	mov si,buffer_bef2
	call translate_16bit_reg
	cmp al,0xff
	jne .op_mov@reg_var_word@var@reg

	call format_numbers_16bit
	jc near .error_opcode

	mov si,word[pointer_write]
	mov word[gs:si],0x06c7
	add si,2
	add word[pointer_write],2
	add word[act_offset],2
	push ax

	cmp bx,-1
	je near .asm_set5@var_word@no_offset
	jmp near .asm_set5@var_word@offset
.op_mov@reg_var_word@addr
	mov bx,ax
	mov si,buffer_bef2
	call translate_16bit_reg
	cmp al,0xff
	je near .error_opcode

	mov si,word[pointer_write]
	mov byte[gs:si],bl
	inc si
	mov byte[gs:si],89h
	inc si

	shl al,3
	or al,bh
	mov byte[gs:si],al
	add word[pointer_write],3
	add word[act_offset],3

	jmp near .end
.op_mov@reg_var_word@var@reg
	shl al,3
	or al,00000110b
	mov si,word[pointer_write]
	mov byte[gs:si],89h
	inc si
	mov byte[gs:si],al
	inc si
	add word[pointer_write],2
	add word[act_offset],2

	cmp bx,-1
	je .op_mov@reg_var_word@reg@no_offset

	call .asm@offset

	jmp near .end
.op_mov@reg_var_word@reg@no_offset
	mov al,1
	call add_offset2offset_table

	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.op_mov@reg_var_word@num
	mov si,word[pointer_write]
	add dl,0xb8
	mov byte[gs:si],dl
	inc si
	mov word[gs:si],ax
	add word[pointer_write],3
	add word[act_offset],3

	jmp near .end
.op_mov@reg_var_word@reg
	mov si,word[pointer_write]

	shl dl,3
	or dl,al
	or dl,11000000b
	mov byte[gs:si],8bh
	inc si
	mov byte[gs:si],dl
	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.op_mov@reg_var_word@seg
	cmp dl,0xff
	jne .op_mov@reg_var_word@seg_reg
	mov dl,al

	mov si,buffer_bef1
	mov di,op_word
	cmpsd
	jne near .error_opcode

	call test_clips
	and al,al
	jnz near .error_no_clips

	call look4label
	and al,al
	jnz near .error_label

	mov si,word[pointer_write]
	shl dl,3
	or dl,6
	mov byte[gs:si],8ch
	inc si
	mov byte[gs:si],dl
	inc si
	add word[pointer_write],2
	add word[act_offset],2

	cmp bx,-1
	je .op_mov@reg_var_word@seg@no_offset

	call .asm@offset

	jmp near .end
.op_mov@reg_var_word@seg@no_offset
	mov al,1
	call add_offset2offset_table

	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.op_mov@reg_var_word@seg_reg
	shl al,3
	or al,dl
	or al,11000000b

	mov si,word[pointer_write]
	mov byte[gs:si],8ch
	inc si
	mov byte[gs:si],al
	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.op_mov@reg_var_dword
	mov dl,al

	cmp dl,0xff
	je near .op_mov@reg_var_dword@var

	mov si,buffer_bef2
	call translate_32bit_reg
	cmp al,0xff
	jne near .op_mov@reg_var_dword@reg

	call format_numbers_32bit
	jnc near .op_mov@reg_var_dword@num

	push si
	mov di,reg_dr
	cmpsw
	pop si
	je near .op_mov@reg_var_dword@reg_dr

	push si
	mov di,reg_cr
	cmpsw
	pop si
	je near .op_mov@reg_var_dword@reg_cr

	mov di,op_dword
	mov cx,5
	rep cmpsb
	jne near .error_opcode

	call test_clips
	and al,al
	jnz near .error_no_clips

	call format_address_16bit
	cmp ax,0xffff
	jne .op_mov@reg_var_dword@addr@var

	call look4label
	and al,al
	jnz near .error_label

	mov si,word[pointer_write]
	shl dl,3
	or dl,6
	mov word[gs:si],0x8b66
	add si,2
	mov byte[gs:si],dl
	inc si
	add word[pointer_write],3
	add word[act_offset],3

	cmp bx,-1
	je .op_mov@reg_var_dword@no_offset

	call .asm@offset

	jmp near .end
.op_mov@reg_var_dword@no_offset
	mov al,1
	call add_offset2offset_table

	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.op_mov@reg_var_dword@addr@var
	mov si,word[pointer_write]
	mov byte[gs:si],al
	inc si
	mov word[gs:si],0x8b66
	add si,2

	shl dl,3
	or dl,ah
	mov byte[gs:si],dl
	add word[pointer_write],4
	add word[act_offset],4

	jmp near .end
.op_mov@reg_var_dword@reg_dr
	add si,2
	lodsb
	and al,al
	jz near .error_opcode
	cmp al,'7'
	jg near .error_opcode
	cmp al,'0'
	jl near .error_opcode
	push ax
	lodsb
	and al,al
	pop ax
	jnz near .error_opcode

	call ascii_char2hex

	shl al,3
	or al,dl
	or al,11000000b
	mov si,word[pointer_write]
	mov word[gs:si],0x210f
	add si,2
	mov byte[gs:si],al
	add word[pointer_write],3
	add word[act_offset],3

	jmp	near .end
.op_mov@reg_var_dword@reg_cr
	add si,2
	lodsb
	and al,al
	jz near .error_opcode
	cmp al,'4'
	jg near .error_opcode
	cmp al,'0'
	jl near .error_opcode
	push ax
	lodsb
	and al,al
	pop ax
	jnz near .error_opcode

	call ascii_char2hex

	shl al,3
	or al,dl
	or al,11000000b
	mov si,word[pointer_write]
	mov word[gs:si],0x200f
	add si,2
	mov byte[gs:si],al
	add word[pointer_write],3
	add word[act_offset],3

	jmp	near .end
.op_mov@reg_var_dword@var
	add si,5
	call test_clips
	and al,al
	jnz near .error_no_clips

	call format_address_16bit
	cmp ax,0xffff
	jne .op_mov@reg_var_dword@addr

	call look4label
	and al,al
	jnz near .error_label

	mov si,buffer_bef2
	call translate_32bit_reg
	cmp al,0xff
	jne .op_mov@reg_var_dword@var@reg

	call format_numbers_32bit
	jc near .error_opcode

	mov si,word[pointer_write]
	mov byte[gs:si],66h
	inc si
	mov word[gs:si],0x06c7
	add si,2
	add word[pointer_write],3
	add word[act_offset],3
	push eax

	cmp bx,-1
	je near .asm_set5@var_dword@no_offset
	jmp near .asm_set5@var_dword@offset
.op_mov@reg_var_dword@addr
	mov bx,ax
	mov si,buffer_bef2
	call translate_32bit_reg
	cmp al,0xff
	je near .error_opcode

	mov si,word[pointer_write]
	mov byte[gs:si],bl
	inc si
	mov word[gs:si],0x8966
	add si,2

	shl al,3
	or al,bh
	mov byte[gs:si],al
	add word[pointer_write],4
	add word[act_offset],4

	jmp near .end
.op_mov@reg_var_dword@var@reg
	shl al,3
	or al,00000110b
	mov si,word[pointer_write]
	mov word[gs:si],0x8966
	add si,2
	mov byte[gs:si],al
	inc si
	add word[pointer_write],3
	add word[act_offset],3

	cmp bx,-1
	je .op_mov@reg_var_dword@var@no_offset

	call .asm@offset

	jmp near .end
.op_mov@reg_var_dword@var@no_offset
	mov al,1
	call add_offset2offset_table

	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.op_mov@reg_var_dword@num
	mov si,word[pointer_write]
	add dl,0xb8
	mov dh,0x66
	xchg dl,dh
	mov word[gs:si],dx
	add si,2
	mov dword[gs:si],eax
	add word[pointer_write],6
	add word[act_offset],6

	jmp near .end
.op_mov@reg_var_dword@reg
	mov si,word[pointer_write]

	shl dl,3
	or dl,al
	or dl,11000000b
	mov word[gs:si],0x8b66
	add si,2
	mov byte[gs:si],dl
	add word[pointer_write],3
	add word[act_offset],3

	jmp near .end
.op_jmp
	mov di,op_jmp
	call string_cmp
	and ax,ax
	jnz near .op_call

	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef1
	call parse_line
	add word[pointer_read],cx

	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef2
	call parse_line
	add word[pointer_read],cx

	mov si,buffer_bef2
	push si
	mov si,buffer_bef1
	mov di,op_near
	call string_cmp
	pop si
	and ax,ax
	jz .op_jmp@near

	push si
	mov si,buffer_bef1
	mov di,op_short
	call string_cmp
	pop si
	and ax,ax
	jz .op_jmp@short

	mov si,buffer_bef1
.op_jmp@near
	call look4label
	and al,al
	jnz near .error_label

	mov si,word[pointer_write]
	mov byte[gs:si],0xe9
	inc si
	inc word[pointer_write]
	inc word[act_offset]

	cmp bx,-1
	je near .asm@no_offset@jmp

	mov ax,word[act_offset]
	add ax,2
	sub bx,ax
	mov word[gs:si],bx
	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.op_jmp@short
	call look4label
	and al,al
	jnz near .error_label

	mov si,word[pointer_write]
	mov byte[gs:si],0xeb
	inc si
	inc word[pointer_write]
	inc word[act_offset]

	cmp bx,-1
	je .op_jmp@short@no_offset

	mov ax,word[act_offset]
	inc ax
	sub bx,ax

	cmp bx,-128
	jl near .error_short_jmp

	mov byte[gs:si],bl
	inc word[pointer_write]
	inc word[act_offset]

	jmp near .end
.op_jmp@short@no_offset
	mov al,3
	call add_offset2offset_table

	inc word[pointer_write]
	inc word[act_offset]

	jmp near .end
.op_jmp@reg16bit
.op_jmp@reg32bit
	jmp near .end
.op_call
	mov di,op_call
	call string_cmp
	and ax,ax
	jnz near .op_arpl

	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef1
	call parse_line
	add word[pointer_read],cx

	mov si,buffer_bef1
	call translate_16bit_reg
	cmp al,0xff
	jne .op_call@reg16bit

	call translate_32bit_reg
	cmp al,0xff
	jne .op_call@reg32bit

	call look4label
	and al,al
	jnz near .error_label

	mov si,word[pointer_write]
	mov byte[gs:si],0xe8
	inc si
	inc word[pointer_write]
	inc word[act_offset]

	cmp bx,-1
	je near .asm@no_offset@jmp
	mov ax,word[act_offset]
	add ax,2
	sub bx,ax
	mov word[gs:si],bx
	add word[pointer_write],2
	add word[act_offset],2
	jmp near .end
.op_call@reg16bit
.op_call@reg32bit
	jmp near .end
.op_arpl
	mov di,op_arpl
	call string_cmp
	and ax,ax
	jnz near .op_enter

	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef1
	call parse_line
	add word[pointer_read],cx

	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef2
	call parse_line
	add word[pointer_read],cx

	cmp byte[failure],0
	jne near .error_opcode

	mov si,buffer_bef1
	call translate_16bit_reg
	cmp al,0xff
	jne .op_arpl@reg

	mov di,op_word
	cmpsd
	je .op_arpl@var

	jmp near .end
.op_arpl@reg
	mov dl,al
	mov si,buffer_bef2
	call translate_16bit_reg
	cmp al,0xff
	je near .error_opcode

	mov si,word[pointer_write]
	mov byte[gs:si],0x63
	inc si

	shl al,3
	or al,dl
	or al,11000000b
	mov byte[gs:si],al
	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.op_arpl@var
	call test_clips
	and al,al
	jnz near .error_no_clips

	call format_address_16bit
	cmp ax,0xffff
	jne .op_arpl@addr

	call look4label
	and al,al
	jnz near .error_label

	mov si,buffer_bef2
	call translate_16bit_reg
	cmp al,0xff
	je near .error_opcode

	mov si,word[pointer_write]
	mov byte[gs:si],0x63
	inc si

	shl al,3
	or al,6
	mov byte[gs:si],al
	inc si
	add word[pointer_write],2
	add word[act_offset],2

	cmp bx,-1
	je .op_arpl@var@no_offset

	call .asm@offset

	jmp near .end
.op_arpl@var@no_offset
	mov al,1
	call add_offset2offset_table

	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.op_arpl@addr
	mov bx,ax

	mov si,buffer_bef2
	call translate_16bit_reg
	cmp al,0xff
	je near .error_opcode

	mov si,word[pointer_write]
	mov byte[gs:si],bl
	inc si
	mov byte[gs:si],0x63
	inc si

	shl al,3
	or al,bh
	mov byte[gs:si],al
	add word[pointer_write],3
	add word[act_offset],3

	jmp near .end
.op_enter
	mov di,op_enter
	call string_cmp
	and ax,ax
	jnz near .op_imul

	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef1
	call parse_line
	add word[pointer_read],cx

	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef2
	call parse_line
	add word[pointer_read],cx

	cmp byte[failure],0
	jne near .error_opcode

	mov si,buffer_bef1
	call format_numbers_16bit
	jc near .error_opcode

	mov bx,ax

	mov si,buffer_bef2
	call format_numbers_8bit
	jc near .error_opcode

	mov si,word[pointer_write]
	mov byte[gs:si],0xc8
	inc si
	mov word[gs:si],bx
	add si,2
	mov byte[gs:si],al
	add word[pointer_write],4
	add word[act_offset],4

	jmp near .end
.op_imul
	mov di,op_imul
	call string_cmp
	and ax,ax
	jnz near .op_in

	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_opcode
	call parse_line
	add word[pointer_read],cx

	cmp byte[failure],0
	jne .op_imul@1operand

	jmp near .end
.op_imul@1operand
	jmp near .end

.op_in
	mov di,op_in
	call string_cmp
	and ax,ax
	jnz near .op_out

	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef1
	call parse_line
	add word[pointer_read],cx

	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef2
	call parse_line
	add word[pointer_read],cx

	cmp byte[failure],0
	jne near .error_opcode

	mov si,buffer_bef1
	call translate_8bit_reg
	and al,al
	jz .op_in@byte

	call translate_16bit_reg
	and al,al
	jz .op_in@word

	call translate_32bit_reg
	and al,al
	jz .op_in@dword

	jmp near .error_opcode
.op_in@byte
	mov si,buffer_bef2
	call format_numbers_8bit
	jc .op_in@byte@dx

	mov si,word[pointer_write]
	mov ah,0e4h
	xchg al,ah
	mov word[gs:si],ax
	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.op_in@byte@dx
	call translate_16bit_reg
	cmp al,2
	jne near .error_opcode

	mov si,word[pointer_write]
	mov byte[gs:si],0ech
	inc word[pointer_write]
	inc word[act_offset]

	jmp near .end
.op_in@word
	mov si,buffer_bef2
	call format_numbers_8bit
	jc .op_in@word@dx

	mov si,word[pointer_write]
	mov ah,0e5h
	xchg al,ah
	mov word[gs:si],ax
	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.op_in@word@dx
	call translate_16bit_reg
	cmp al,2
	jne near .error_opcode

	mov si,word[pointer_write]
	mov byte[gs:si],0edh
	inc word[pointer_write]
	inc word[act_offset]

	jmp near .end
.op_in@dword
	mov si,buffer_bef2
	call format_numbers_8bit
	jc .op_in@dword@dx

	mov si,word[pointer_write]
	mov word[gs:si],0x0e566
	add si,2
	mov byte[gs:si],al
	add word[pointer_write],3
	add word[act_offset],3

	jmp near .end
.op_in@dword@dx
	call translate_16bit_reg
	cmp al,2
	jne near .error_opcode

	mov si,word[pointer_write]
	mov word[gs:si],0xed66
	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.op_out
	mov di,op_out
	call string_cmp
	and ax,ax
	jnz near .asm_opcodes

	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef1
	call parse_line
	add word[pointer_read],cx

	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef2
	call parse_line
	add word[pointer_read],cx

	cmp byte[failure],0
	jne near .error_opcode

	mov si,buffer_bef2
	call translate_8bit_reg
	and al,al
	jz .op_out@byte

	call translate_16bit_reg
	and al,al
	jz .op_out@word

	call translate_32bit_reg
	and al,al
	jz .op_out@dword

	jmp near .error_opcode
.op_out@byte
	mov si,buffer_bef1
	call format_numbers_8bit
	jc .op_out@byte@al

	mov si,word[pointer_write]
	mov ah,0e6h
	xchg al,ah
	mov word[gs:si],ax
	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.op_out@byte@al
	call translate_16bit_reg
	cmp al,2
	jne near .error_opcode

	mov si,word[pointer_write]
	mov byte[gs:si],0eeh
	inc word[pointer_write]
	inc word[act_offset]

	jmp near .end
.op_out@word
	mov si,buffer_bef1
	call format_numbers_8bit
	jc .op_out@word@ax

	mov si,word[pointer_write]
	mov ah,0e7h
	xchg al,ah
	mov word[gs:si],ax
	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.op_out@word@ax
	call translate_16bit_reg
	cmp al,2
	jne near .error_opcode

	mov si,word[pointer_write]
	mov byte[gs:si],0efh
	inc word[pointer_write]
	inc word[act_offset]

	jmp near .end
.op_out@dword
	mov si,buffer_bef1
	call format_numbers_8bit
	jc .op_out@dword@eax

	mov si,word[pointer_write]
	mov word[gs:si],0x0e766
	add si,2
	mov byte[gs:si],al
	add word[pointer_write],3
	add word[act_offset],3

	jmp near .end
.op_out@dword@eax
	call translate_16bit_reg
	cmp al,2
	jne near .error_opcode

	mov si,word[pointer_write]
	mov word[gs:si],0xef66
	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end

.asm_opcodes

.instruc_set0
	mov di,instruction_set0
.loop_set0
	cmp di,instruction_set1
	je .instruc_set1

	call string_cmp

	push si
	mov si,di
	call string_len
	pop si

	add di,cx

	and ax,ax
	jz .asm_set0
.loop_set0@1
	add di,2

	jmp .loop_set0
.asm_set0
	inc di

	push di
	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef1
	call parse_line
	add word[pointer_read],cx
	pop di

	cmp byte[failure],0
	jne near .error_opcode

	push di
	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef2
	call parse_line
	add word[pointer_read],cx
	pop di

	cmp byte[failure],0
	je near .error_opcode

	mov byte[failure],0

	mov si,word[pointer_write]
.asm_set0@loop
	mov al,byte[es:di]

	mov byte[gs:si],al
	inc word[pointer_write]
	inc word[act_offset]

	mov si,buffer_bef1

.instruc_set1
	mov di,instruction_set1
.loop_set1
	cmp di,instruction_set2
	je .instruc_set2

	call string_cmp

	push si
	mov si,di
	call string_len
	pop si

	add di,cx

	and ax,ax
	jz .asm_set1
.loop_set1@1
	mov al,byte[es:di]
	inc di

	and al,al
	jz .loop_set1
	jmp .loop_set1@1
.asm_set1
	inc di
	mov si,word[pointer_write]
.asm_set1@loop
	mov al,byte[es:di]
	inc di

	and al,al
	jz near .end

	mov byte[gs:si],al
	inc si
	inc word[pointer_write]
	inc word[act_offset]

	jmp short .asm_set1@loop

.instruc_set2
	mov di,instruction_set2
.loop_set2
	cmp di,instruction_set3
	je near .instruc_set3

	call string_cmp

	push si
	mov si,di
	call string_len
	pop si

	add di,cx

	and ax,ax
	jz .asm_set2
.loop_set2@1
	mov al,byte[es:di]
	inc di

	and al,al
	jz .loop_set2
	jmp .loop_set2@1
.asm_set2
	inc di
	push di
	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef1
	call parse_line
	add word[pointer_read],cx
	pop di

	cmp byte[failure],0
	jne near .error_opcode

	push di
	mov si,buffer_bef1
	mov di,op_byte
	cmpsd
	pop di

	je near .asm_set2@var_byte

	push di
	mov si,buffer_bef1
	mov di,op_word
	cmpsd
	pop di

	je near .asm_set2@var_word

	push di
	mov si,buffer_bef1
	mov di,op_dword
	mov cx,5
	rep	cmpsb
	pop di

	je near .asm_set2@var_dword

	mov si,buffer_bef1
	call translate_8bit_reg
	cmp al,0xff
	jne .asm_set2@reg8bit

	call translate_16bit_reg
	cmp al,0xff
	jne .asm_set2@reg16bit

	call translate_32bit_reg
	cmp al,0xff
	je near .error_opcode

.asm_set2@reg32bit
	mov si,word[pointer_write]
	push ax

	mov ah,0x66
	mov al,byte[es:di]
	inc di

	inc al
	xchg al,ah
	mov word[gs:si],ax
	add si,2
	add word[pointer_write],2
	add word[act_offset],2

	jmp short .asm_set2@reg_asm
.asm_set2@reg16bit
	mov si,word[pointer_write]
	push ax

	mov al,byte[es:di]
	inc di

	inc al
	mov byte[gs:si],al
	inc si
	inc word[pointer_write]
	inc word[act_offset]

	jmp short .asm_set2@reg_asm
.asm_set2@reg8bit
	mov si,word[pointer_write]
	push ax

	mov al,byte[es:di]
	inc di

	mov byte[gs:si],al
	inc si
	inc word[pointer_write]
	inc word[act_offset]
.asm_set2@reg_asm
	mov bl,byte[es:di]
	inc di
	pop ax

	shl bl,3
	or al,bl
	or al,11000000b

	mov byte[gs:si],al
	inc word[pointer_write]
	inc word[act_offset]

	jmp near .end
.asm_set2@var_byte
	mov si,buffer_bef1
	add si,4

	call test_clips
	and al,al
	jnz near .error_no_clips

	call format_address_16bit
	cmp ax,0xffff
	jne .asm_set2@var_byte@addr

	call look4label
	and al,al
	jne near .error_label

	mov si,word[pointer_write]
	mov al,byte[es:di]
	inc di

	mov byte[gs:si],al
	inc si
	inc word[pointer_write]
	inc word[act_offset]

	jmp near .asm_set2@var_asm
.asm_set2@var_byte@addr
	mov bx,ax

	mov al,byte[es:di]
	inc di
	mov ah,byte[es:di]

	mov si,word[pointer_write]
	mov byte[gs:si],bl
	inc si
	mov byte[gs:si],al
	inc si

	shl ah,3
	or ah,bh
	mov byte[gs:si],ah
	add word[pointer_write],3
	add word[act_offset],3

	jmp near .end
.asm_set2@var_word
	mov si,buffer_bef1

	mov si,buffer_bef1
	add si,4

	call test_clips
	and al,al
	jnz near .error_no_clips

	call format_address_16bit
	cmp ax,0xffff
	jne .asm_set2@var_word@addr

	call look4label
	and al,al
	jne near .error_label

	mov si,word[pointer_write]
	mov al,byte[es:di]
	inc di

	inc al
	mov byte[gs:si],al
	inc si
	inc word[pointer_write]
	inc word[act_offset]

	jmp near .asm_set2@var_asm
.asm_set2@var_word@addr
	mov bx,ax

	mov al,byte[es:di]
	inc di
	mov ah,byte[es:di]

	mov si,word[pointer_write]
	mov byte[gs:si],bl
	inc si
	inc al
	mov byte[gs:si],al
	inc si

	shl ah,3
	or ah,bh
	mov byte[gs:si],ah
	add word[pointer_write],3
	add word[act_offset],3

	jmp near .end
.asm_set2@var_dword
	mov si,buffer_bef1
	add si,5

	call test_clips
	and al,al
	jnz near .error_no_clips

	call format_address_16bit
	cmp ax,0xffff
	jne .asm_set2@var_dword@addr

	call look4label
	and al,al
	jne near .error_label

	mov si,word[pointer_write]

	mov ah,0x66
	mov al,byte[es:di]
	inc di

	inc al
	xchg al,ah
	mov word[gs:si],ax
	add si,2
	add word[pointer_write],2
	add word[act_offset],2

	jmp short .asm_set2@var_asm
.asm_set2@var_dword@addr
	mov bx,ax

	mov al,byte[es:di]
	inc di
	mov ah,byte[es:di]

	mov si,word[pointer_write]
	mov byte[gs:si],bl
	inc si
	mov byte[gs:si],0x66
	inc si
	inc al
	mov byte[gs:si],al
	inc si

	shl ah,3
	or ah,bh
	mov byte[gs:si],ah
	add word[pointer_write],4
	add word[act_offset],4

	jmp near .end
.asm_set2@var_asm
	mov al,byte[es:di]
	inc di

	shl al,3
	or al,00000110b

	mov byte[gs:si],al
	inc si
	inc word[pointer_write]
	inc word[act_offset]

	cmp bx,-1
	je .asm_set2@var@no_offset

	call .asm@offset

	jmp near .end
.asm_set2@var@no_offset
	mov al,1
	call add_offset2offset_table

	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end

.instruc_set3
	mov di,instruction_set3
.loop_set3
	cmp di,instruction_set4
	je near .instruc_set4

	call string_cmp

	push si
	mov si,di
	call string_len
	pop si

	add di,cx

	and ax,ax
	jz .asm_set3
.loop_set3@1
	mov al,byte[es:di]
	inc di

	and al,al
	jz .loop_set3
	jmp .loop_set3@1
.asm_set3
	inc di
	push di
	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef1
	call parse_line
	add word[pointer_read],cx
	pop di

	cmp byte[failure],0
	jne near .error_opcode

	mov si,buffer_bef1
	call translate_8bit_reg
	cmp al,0xff
	jne near .asm_set3@reg

	push di
	mov di,op_byte
	cmpsd
	pop di
	je .asm_set3@var

	jmp near .error_opcode
.asm_set3@var
	call test_clips
	and al,al
	jnz near .error_no_clips

	call format_address_16bit
	cmp ax,0xffff
	jne .asm_set3@addr

	call look4label
	and al,al
	jne near .error_label

	mov si,word[pointer_write]
	mov al,byte[es:di]
	inc di

	mov ah,0x0f
	xchg al,ah
	mov word[gs:si],ax
	add si,2
	mov byte[gs:si],0x06
	inc si
	add word[pointer_write],3
	add word[act_offset],3

	cmp bx,-1
	je .asm_set3@var@no_offset

	call .asm@offset

	jmp near .end
.asm_set3@var@no_offset
	mov al,1
	call add_offset2offset_table

	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.asm_set3@addr
	mov bx,ax

	mov al,byte[es:di]

	mov si,word[pointer_write]
	mov byte[gs:si],bl
	inc si
	mov ah,0x0f
	xchg al,ah
	mov word[gs:si],ax
	add si,2

	mov byte[gs:si],bh
	add word[pointer_write],4
	add word[act_offset],4

	jmp near .end
.asm_set3@reg
	or al,11000000b

	mov si,word[pointer_write]
	mov bl,byte[es:di]
	inc di

	mov bh,0x0f
	xchg bl,bh
	mov word[gs:si],bx
	add si,2
	mov byte[gs:si],al
	add word[pointer_write],3
	add word[act_offset],3

	jmp near .end

.instruc_set4
	mov di,instruction_set4
.loop_set4
	cmp di,instruction_set5
	je near .instruc_set5

	call string_cmp

	push si
	mov si,di
	call string_len
	pop si

	add di,cx

	and ax,ax
	jz .asm_set4
.loop_set4@1
	mov al,byte[es:di]
	inc di

	and al,al
	jz .loop_set4
	jmp .loop_set4@1
.asm_set4
	inc di
	push di
	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef1
	call parse_line
	add word[pointer_read],cx
	pop di

	push di
	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef2
	call parse_line
	add word[pointer_read],cx
	pop di

	mov si,buffer_bef1

	cmp byte[failure],0
	jne near .asm_set4@short

	mov si,buffer_bef2

	push di
	push si
	mov si,buffer_bef1
	mov di,op_short
	call string_cmp
	pop si
	pop di
	and ax,ax
	jz .asm_set4@short

	push di
	push si
	mov si,buffer_bef1
	mov di,op_near
	call string_cmp
	pop si
	pop di
	and ax,ax
	jz .asm_set4@near

	jmp near .error_opcode
.asm_set4@short
	call look4label
	and al,al
	jnz near .error_label

	mov si,word[pointer_write]
	mov al,byte[es:di]

	mov byte[gs:si],al
	inc si
	inc word[pointer_write]
	inc word[act_offset]

	cmp bx,-1
	je .asm_set4@short@no_offset
.asm_set4@short@offset
	mov ax,word[act_offset]
	inc ax

	sub bx,ax

	cmp bx,-127
	jg near .error_short_jmp

	mov byte[gs:si],bl
	inc word[pointer_write]
	inc word[act_offset]

	jmp near .end
.asm_set4@short@no_offset
	mov al,3
	call add_offset2offset_table

	inc word[pointer_write]
	inc word[act_offset]

	jmp near .end
.asm_set4@near
	call look4label
	and al,al
	jnz near .error_label

	mov si,word[pointer_write]
	mov al,byte[es:di]
	add al,10h
	mov ah,0x0f
	xchg al,ah

	mov word[gs:si],ax
	add si,2
	add word[pointer_write],2
	add word[act_offset],2

	cmp bx,-1
	je near .asm@no_offset@jmp
.asm_set4@near@offset
	mov ax,word[act_offset]
	add ax,2

	sub bx,ax

	mov word[gs:si],bx
	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end

.instruc_set5
	mov di,instruction_set5
.loop_set5
	cmp di,instruction_set6
	je near .instruc_set6

	call string_cmp

	push si
	mov si,di
	call string_len
	pop si

	add di,cx

	and ax,ax
	jz .asm_set5
.loop_set5@1
	add di,4

	jmp .loop_set5
.asm_set5
	inc di

	push di
	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef1
	call parse_line
	add word[pointer_read],cx
	pop di

	push di
	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef2
	call parse_line
	add word[pointer_read],cx
	pop di

	cmp byte[failure],0
	jne near .error_opcode

	mov si,buffer_bef1

	call translate_8bit_reg
	cmp al,0xff
	jne near .asm_set5@reg8bit

	call translate_16bit_reg
	cmp al,0xff
	jne near .asm_set5@reg16bit

	call translate_32bit_reg
	cmp al,0xff
	jne near .asm_set5@reg32bit

	push di
	push si
	mov di,op_byte
	cmpsd
	pop si
	pop di
	je near .asm_set5@var_byte

	push di
	push si
	mov di,op_word
	cmpsd
	pop si
	pop di
	je near .asm_set5@var_word

	push di
	push si
	mov di,op_dword
	mov cx,5
	rep cmpsb
	pop si
	pop di
	je near .asm_set5@var_dword

	jmp near .error_opcode
.asm_set5@reg8bit
	mov dl,al

	mov si,buffer_bef2

	call translate_8bit_reg

	cmp al,0xff
	jne near .asm_set5@reg@reg_byte

	mov si,buffer_bef2

	call format_numbers_8bit
	jnc .asm_set5@reg_byte@number

	push di
	mov di,op_byte
	cmpsd
	pop di

	jne near .error_opcode
	jmp near .asm_set5@reg@var_byte
.asm_set5@reg_byte@number
	mov bl,al
	mov si,word[pointer_write]
	mov ah,byte[es:di]
	inc di
	mov bh,byte[es:di]
	inc di

	mov al,dl
	shl bh,3
	or al,bh
	or al,11000000b

	xchg al,ah
	mov word[gs:si],ax
	add si,2
	mov byte[gs:si],bl
	add word[pointer_write],3
	add word[act_offset],3

	jmp near .end
.asm_set5@reg16bit
	mov dl,al

	mov si,buffer_bef2

	call translate_16bit_reg
	cmp al,0xff
	jne near .asm_set5@reg@reg_word

	call format_numbers_16bit
	jnc .asm_set5@reg_word@number

	push di
	push si
	mov di,op_word
	cmpsd
	pop si
	pop di
	je near .asm_set5@reg@var_word

	call look4label
	and al,al
	jz .asm_set5@reg_word@var_num

	jmp near .error_opcode
.asm_set5@reg_word@number
	mov cx,ax
	mov si,word[pointer_write]
	mov ah,byte[es:di]
	inc di
	mov bh,byte[es:di]
	inc di

	inc ah
	mov al,dl
	shl bh,3
	or al,bh
	or al,11000000b

	xchg al,ah
	mov word[gs:si],ax
	add si,2
	mov word[gs:si],cx
	add word[pointer_write],4
	add word[act_offset],4

	jmp near .end
.asm_set5@reg_word@var_num
	mov si,word[pointer_write]
	mov ah,byte[es:di]
	inc di
	mov dh,byte[es:di]
	inc di

	inc ah
	mov al,dl
	shl dh,3
	or al,dh
	or al,11000000b

	xchg al,ah
	mov word[gs:si],ax
	add si,2
	add word[pointer_write],2
	add word[act_offset],2

	cmp bx,-1
	je .asm_set5@reg_word@no_offset

	call .asm@offset

	jmp near .end
.asm_set5@reg_word@no_offset
	mov al,1
	call add_offset2offset_table

	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.asm_set5@reg32bit
	mov dl,al

	mov si,buffer_bef2

	call translate_32bit_reg

	cmp al,0xff
	jne near .asm_set5@reg@reg_dword

	mov si,buffer_bef2

	call format_numbers_32bit
	jnc .asm_set5@reg_dword@number

	push di
	mov di,op_dword
	mov cx,5
	rep cmpsb
	pop di

	je near .asm_set5@reg@var_dword
	jmp near .error_opcode
.asm_set5@reg_dword@number
	mov ecx,eax
	mov si,word[pointer_write]
	mov ah,byte[es:di]
	inc di
	mov bh,byte[es:di]
	inc di

	inc ah
	mov al,dl
	shl bh,3
	or al,bh
	or al,11000000b

	mov byte[gs:si],0x66
	inc si

	xchg al,ah
	mov word[gs:si],ax
	add si,2
	mov dword[gs:si],ecx
	add word[pointer_write],7
	add word[act_offset],7

	jmp near .end
.asm_set5@reg@var_byte
	call test_clips
	and al,al
	jnz near .error_no_clips

	call format_address_16bit
	cmp ax,0xffff
	jne .asm_set5@reg@addr@var_byte

	call look4label
	and al,al
	jnz near .error_label

	mov si,word[pointer_write]
	add di,2
	mov al,byte[es:di]
	add al,2
	mov byte[gs:si],al
	inc si

	shl dl,3
	or dl,00000110b

	mov byte[gs:si],dl
	inc si
	add word[pointer_write],2
	add word[act_offset],2

	cmp bx,-1
	je .asm_set5@reg@var_byte@no_offset

	call .asm@offset

	jmp near .end
.asm_set5@reg@var_byte@no_offset
	mov al,1
	call add_offset2offset_table

	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.asm_set5@reg@addr@var_byte
	mov si,word[pointer_write]
	mov byte[gs:si],al
	inc si
	add di,2
	mov al,byte[es:di]
	add al,2
	mov byte[gs:si],al
	inc si

	shl dl,3
	or dl,ah
	mov byte[gs:si],dl
	add word[pointer_write],3
	add word[act_offset],3

	jmp near .end
.asm_set5@reg@var_word
	add si,4
	call test_clips
	and al,al
	jnz near .error_no_clips

	call format_address_16bit
	cmp ax,0xffff
	jne .asm_set5@reg@addr@var_word

	call look4label
	and al,al
	jnz near .error_label

	mov si,word[pointer_write]
	add di,2
	mov al,byte[es:di]
	add al,3
	mov byte[gs:si],al
	inc si

	shl dl,3
	or dl,00000110b

	mov byte[gs:si],dl
	inc si
	add word[pointer_write],2
	add word[act_offset],2

	cmp bx,-1
	je .asm_set5@reg@var_word@no_offset

	call .asm@offset

	jmp near .end
.asm_set5@reg@var_word@no_offset
	mov al,1
	call add_offset2offset_table

	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.asm_set5@reg@addr@var_word
	mov si,word[pointer_write]
	mov byte[gs:si],al
	inc si
	add di,2
	mov al,byte[es:di]
	add al,3
	mov byte[gs:si],al
	inc si

	shl dl,3
	or dl,ah
	mov byte[gs:si],dl
	add word[pointer_write],3
	add word[act_offset],3

	jmp near .end
.asm_set5@reg@var_dword
	call test_clips
	and al,al
	jnz near .error_no_clips

	call format_address_16bit
	cmp ax,0xffff
	jne .asm_set5@reg@addr@var_dword

	call look4label
	and al,al
	jnz near .error_label

	mov si,word[pointer_write]
	mov byte[gs:si],0x66
	inc si
	add di,2
	mov al,byte[es:di]
	add al,3
	mov byte[gs:si],al
	inc si

	shl dl,3
	or dl,00000110b

	mov byte[gs:si],dl
	inc si
	add word[pointer_write],3
	add word[act_offset],3

	cmp bx,-1
	je .asm_set5@reg@var_dword@no_offset

	call .asm@offset

	jmp near .end
.asm_set5@reg@var_dword@no_offset
	mov al,1
	call add_offset2offset_table

	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.asm_set5@reg@addr@var_dword
	mov si,word[pointer_write]
	mov byte[gs:si],al
	inc si
	mov byte[gs:si],66h
	inc si
	add di,2
	mov al,byte[es:di]
	add al,3
	mov byte[gs:si],al
	inc si

	shl dl,3
	or dl,ah
	mov byte[gs:si],dl
	add word[pointer_write],4
	add word[act_offset],4

	jmp near .end
.asm_set5@reg@reg_byte
	mov si,word[pointer_write]
	add di,2
	mov ah,byte[es:di]
	inc di

	shl al,3
	or al,11000000b
	or al,dl

	xchg al,ah
	mov word[gs:si],ax
	add si,2
	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.asm_set5@reg@reg_word
	mov si,word[pointer_write]
	add di,2
	mov ah,byte[es:di]
	inc di

	inc ah
	shl al,3
	or al,11000000b
	or al,dl

	xchg al,ah
	mov word[gs:si],ax
	add si,2
	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.asm_set5@reg@reg_dword
	mov si,word[pointer_write]
	add di,2
	mov ah,byte[es:di]
	inc di

	inc ah
	shl al,3
	or al,11000000b
	or al,dl

	mov byte[gs:si],0x66
	inc si
	xchg al,ah
	mov word[gs:si],ax
	add si,2
	add word[pointer_write],3
	add word[act_offset],3

	jmp near .end
.asm_set5@var_byte
	add si,4

	call test_clips
	and al,al
	jnz near .error_no_clips

	call format_address_16bit
	cmp ax,0xffff
	jne near .asm_set5@var_byte@addr@reg

	call look4label
	and al,al
	jnz near .error_label

	push si
	mov si,buffer_bef2

	call translate_8bit_reg
	pop si

	cmp al,0xff
	jne near .asm_set5@var_byte@reg

	push si
	mov si,buffer_bef2

	call format_numbers_8bit
	pop si
	jc near .error_opcode
.asm_set5@var_byte@number
	push ax
	mov si,word[pointer_write]
	mov ax,word[es:di]
	add di,2

	shl ah,3
	or ah,00000110b

	mov word[gs:si],ax
	add si,2
	add word[pointer_write],2
	add word[act_offset],2

	cmp bx,-1
	jne .asm_set5@var_byte@offset
.asm_set5@var_byte@no_offset
	add si,2
	pop ax
	mov byte[gs:si],al

	mov al,1
	call add_offset2offset_table

	add word[pointer_write],3
	add word[act_offset],3

	jmp near .end
.asm_set5@var_byte@offset
	mov word[gs:si],bx
	add si,2
	pop ax
	mov byte[gs:si],al

	add word[pointer_write],3
	add word[act_offset],3

	jmp near .end
.asm_set5@var_byte@addr@reg
	mov si,word[pointer_write]
	mov byte[gs:si],al
	inc si
	add di,2
	mov al,byte[es:di]
	mov byte[gs:si],al
	inc si

	shl dl,3
	or dl,ah
	mov byte[gs:si],dl
	add word[pointer_write],3
	add word[act_offset],3

	jmp near .end
.asm_set5@var_byte@reg
	mov si,word[pointer_write]
	add di,2
	mov ah,byte[es:di]
	inc di

	shl al,3
	or al,00000110b

	xchg al,ah
	mov word[gs:si],ax
	add si,2
	add word[pointer_write],2
	add word[act_offset],2

	cmp bx,-1
	je .asm_set5@var_byte@reg@no_offset

	call .asm@offset

	jmp near .end
.asm_set5@var_byte@reg@no_offset
	mov al,1
	call add_offset2offset_table

	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.asm_set5@var_word
	add si,4

	call test_clips
	and al,al
	jnz near .error_no_clips

	call format_address_16bit
	cmp ax,0xffff
	jne near .asm_set5@var_word@addr@reg

	call look4label
	and al,al
	jnz near .error_label

	push si
	mov si,buffer_bef2

	call translate_16bit_reg
	pop si

	cmp al,0xff
	jne near .asm_set5@var_word@reg

	push si
	mov si,buffer_bef2

	call format_numbers_16bit
	pop si
	jc near .error_opcode
.asm_set5@var_word@number
	push ax
	mov si,word[pointer_write]
	mov ax,word[es:di]
	add di,2

	inc al
	shl ah,3
	or ah,00000110b

	mov word[gs:si],ax
	add si,2
	add word[pointer_write],2
	add word[act_offset],2

	cmp bx,-1
	jne .asm_set5@var_word@offset
.asm_set5@var_word@no_offset
	add si,2
;	pop ax
;	mov word[gs:si],ax
	pop word[gs:si]

	mov al,1
	call add_offset2offset_table

	add word[pointer_write],4
	add word[act_offset],4

	jmp near .end
.asm_set5@var_word@offset
	mov word[gs:si],bx
	add si,2
;	pop ax
;	mov word[gs:si],ax
	pop word[gs:si]

	add word[pointer_write],4
	add word[act_offset],4

	jmp near .end
.asm_set5@var_word@addr@reg
	mov si,word[pointer_write]
	mov byte[gs:si],al
	inc si
	add di,2
	mov al,byte[es:di]
	inc al
	mov byte[gs:si],al
	inc si

	shl dl,3
	or dl,ah
	mov byte[gs:si],dl
	add word[pointer_write],3
	add word[act_offset],3

	jmp near .end
.asm_set5@var_word@reg
	mov si,word[pointer_write]
	add di,2
	mov ah,byte[es:di]
	inc di

	inc ah
	shl al,3
	or al,00000110b

	xchg al,ah
	mov word[gs:si],ax
	add si,2
	add word[pointer_write],2
	add word[act_offset],2

	cmp bx,-1
	je .asm_set5@var_word@reg@no_offset

	call .asm@offset

	jmp near .end
.asm_set5@var_word@reg@no_offset
	mov al,1
	call add_offset2offset_table

	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.asm_set5@var_dword
	add si,5

	call test_clips
	and al,al
	jnz near .error_no_clips

	call format_address_16bit
	cmp ax,0xffff
	jne near .asm_set5@var_dword@addr@reg

	call look4label
	and al,al
	jnz near .error_label

	mov si,buffer_bef2
	call translate_32bit_reg
	cmp al,0xff
	jne near .asm_set5@var_dword@reg

	call format_numbers_32bit

	jc near .error_opcode
.asm_set5@var_dword@number
	push eax
	mov si,word[pointer_write]
	mov ax,word[es:di]
;	add di,2

	inc al
	shl ah,3
	or ah,00000110b

	mov byte[gs:si],0x66
	inc si
	mov word[gs:si],ax
	add si,2
	add word[pointer_write],3
	add word[act_offset],3

	cmp bx,-1
	jne .asm_set5@var_dword@offset
.asm_set5@var_dword@no_offset
	add si,2
;	pop eax
;	mov dword[gs:si],eax
	pop dword[gs:si]

	mov al,1
	call add_offset2offset_table

	add word[pointer_write],6
	add word[act_offset],6

	jmp near .end
.asm_set5@var_dword@offset
	mov word[gs:si],bx
	add si,2
;	pop eax
;	mov dword[gs:si],eax
	pop dword[gs:si]

	add word[pointer_write],6
	add word[act_offset],6

	jmp near .end
.asm_set5@var_dword@addr@reg
	mov si,word[pointer_write]
	mov byte[gs:si],al
	inc si
	mov byte[gs:si],66h
	inc si
	add di,2
	mov al,byte[es:di]
	inc al
	mov byte[gs:si],al
	inc si

	shl dl,3
	or dl,ah
	mov byte[gs:si],dl
	add word[pointer_write],4
	add word[act_offset],4

	jmp near .end
.asm_set5@var_dword@reg
	mov si,word[pointer_write]
	add di,2
	mov ah,byte[es:di]
	inc di

	inc ah
	shl al,3
	or al,00000110b

	mov byte[gs:si],0x66
	inc si
	xchg al,ah
	mov word[gs:si],ax
	add si,2

	add word[pointer_write],3
	add word[act_offset],3

	cmp bx,-1
	je .asm_set5@var_dword@reg@no_offset

	call .asm@offset

	jmp near .end
.asm_set5@var_dword@reg@no_offset
	mov al,1
	call add_offset2offset_table

	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.asm@no_offset@jmp
	mov al,2
	call add_offset2offset_table

	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.asm@offset
	mov word[gs:si],bx

	add word[pointer_write],2
	add word[act_offset],2

	ret

.instruc_set6
	mov di,instruction_set6
.loop_set6
	cmp di,instruction_set7
	je near .instruc_set7

	call string_cmp

	push si
	mov si,di
	call string_len
	pop si

	add di,cx

	and ax,ax
	jz .asm_set6
.loop_set6@1
	add di,3

	jmp .loop_set6
.asm_set6
	inc di
	push di

	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef1
	call parse_line
	add word[pointer_read],cx

	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef2
	call parse_line
	add word[pointer_read],cx

	pop di

	cmp byte[failure],0
	jne near .error_opcode

	mov si,buffer_bef1
	call translate_16bit_reg
	cmp al,0xff
	jne .asm_set6@reg16bit

	call translate_32bit_reg
	cmp al,0xff
	jne near .asm_set6@reg32bit

	push si
	push di
	mov di,op_word
	cmpsd
	pop di
	pop si
	je near .asm_set6@var_word

	push si
	push di
	mov di,op_dword
	mov cx,5
	rep cmpsb
	pop di
	pop si
	je near .asm_set6@var_dword

	jmp near .error_opcode

.asm_set6@reg16bit
	mov dl,al
	mov si,buffer_bef2

	call format_numbers_8bit
	jnc .asm_set6@reg16bit@num

	call translate_16bit_reg
	cmp al,0xff
	je near .error_opcode

	mov si,word[pointer_write]
	mov bl,byte[es:di]

	mov bh,0x0f
	xchg bl,bh
	mov word[gs:si],bx
	add si,2

	shl al,3
	or al,dl
	or al,11000000b
	mov byte[gs:si],al
	add word[pointer_write],3
	add word[act_offset],3

	jmp near .end
.asm_set6@reg16bit@num
	mov si,word[pointer_write]
	inc di
	mov bl,byte[es:di]
	mov word[gs:si],0xba0f
	add si,2

	shl bl,3
	or dl,bl
	or dl,11000000b
	mov byte[gs:si],dl
	inc si
	mov byte[gs:si],al
	add word[pointer_write],4
	add word[act_offset],4

	jmp near .end
.asm_set6@reg32bit
	mov dl,al
	mov si,buffer_bef2

	call format_numbers_8bit
	jnc .asm_set6@reg32bit@num

	call translate_32bit_reg
	cmp al,0xff
	je near .error_opcode

	mov si,word[pointer_write]
	mov bl,byte[es:di]

	mov byte[gs:si],0x66
	inc si
	mov bh,0x0f
	xchg bl,bh
	mov word[gs:si],bx
	add si,2

	shl al,3
	or al,dl
	or al,11000000b
	mov byte[gs:si],al
	add word[pointer_write],4
	add word[act_offset],4

	jmp near .end
.asm_set6@reg32bit@num
	mov si,word[pointer_write]
	inc di
	mov bl,byte[es:di]
	mov byte[gs:si],0x66
	inc si
	mov word[gs:si],0xba0f
	add si,2

	shl bl,3
	or dl,bl
	or dl,11000000b
	mov byte[gs:si],dl
	inc si
	mov byte[gs:si],al
	add word[pointer_write],5
	add word[act_offset],5

	jmp near .end
.asm_set6@var_word
	add si,4
	call test_clips
	and al,al
	jnz near .error_no_clips

	call format_address_16bit
	cmp ax,0xffff
	jne .asm_set6@var_word@addr

	call look4label
	and al,al
	jnz near .error_label

	mov si,buffer_bef2

	call format_numbers_8bit
	jnc near .asm_set6@var_word@num

	call translate_16bit_reg
	cmp al,0xff
	je near .error_opcode

	mov si,word[pointer_write]
	mov dl,byte[es:di]

	mov dh,0x0f
	xchg dl,dh
	mov word[gs:si],dx
	add si,2

	shl al,3
	or al,00000110b
	mov byte[gs:si],al
	inc si
	add word[pointer_write],3
	add word[act_offset],3

	cmp bx,-1
	je .asm_set6@var_word@no_offset

	call .asm@offset

	jmp near .end
.asm_set6@var_word@no_offset
	mov al,1
	call add_offset2offset_table

	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.asm_set6@var_word@addr
	mov bx,ax

	mov si,buffer_bef2
	call format_numbers_8bit
	jnc .asm_set6@var_word@addr@num

	call translate_16bit_reg
	cmp al,0xff
	je near .error_opcode

	mov ah,byte[es:di]

	push ax
	mov si,word[pointer_write]
	mov byte[gs:si],bl
	inc si
	mov al,0x0f
	mov word[gs:si],ax
	add si,2
	pop ax

	shl al,3
	or al,bh
	mov byte[gs:si],al
	add word[pointer_write],4
	add word[act_offset],4

	jmp near .end
.asm_set6@var_word@addr@num
	push ax
	mov si,word[pointer_write]
	mov byte[gs:si],bl
	inc si
	mov word[gs:si],0xba0f
	add si,2
	inc di
	mov al,byte[es:di]

	shl al,3
	or al,bh
	mov byte[gs:si],al
	inc si
	pop ax
	mov byte[gs:si],al
	add word[pointer_write],5
	add word[act_offset],5

	jmp near .end
.asm_set6@var_word@num
	mov si,word[pointer_write]
	inc di
	mov bl,byte[es:di]
	mov word[gs:si],0xba0f
	add si,2

	shl bl,3
	or dl,bl
	or dl,00000110b
	mov byte[gs:si],dl
	inc si
	add word[pointer_write],3
	add word[act_offset],3
	push ax

	cmp bx,-1
	je near .asm_set5@var_byte@no_offset
	jmp near .asm_set5@var_byte@offset
.asm_set6@var_dword
	add si,5
	call test_clips
	and al,al
	jnz near .error_no_clips

	call format_address_16bit
	cmp ax,0xffff
	jne .asm_set6@var_dword@addr

	call look4label
	and al,al
	jnz near .error_label

	mov si,buffer_bef2

	call format_numbers_8bit
	jnc near .asm_set6@var_dword@num

	call translate_32bit_reg
	cmp al,0xff
	je near .error_opcode

	mov si,word[pointer_write]
	mov dl,byte[es:di]
	mov byte[gs:si],0x66
	inc si

	mov dh,0x0f
	xchg dl,dh
	mov word[gs:si],dx
	add si,2

	shl al,3
	or al,00000110b
	mov byte[gs:si],al
	inc si
	add word[pointer_write],4
	add word[act_offset],4

	cmp bx,-1
	je .asm_set6@var_dword@no_offset

	call .asm@offset

	jmp near .end
.asm_set6@var_dword@no_offset
	mov al,1
	call add_offset2offset_table

	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.asm_set6@var_dword@addr
	mov bx,ax

	mov si,buffer_bef2
	call format_numbers_8bit
	jnc .asm_set6@var_dword@addr@num

	call translate_32bit_reg
	cmp al,0xff
	je near .error_opcode

	push ax
	mov al,byte[es:di]
	mov si,word[pointer_write]
	mov byte[gs:si],bl
	inc si
	mov word[gs:si],0x0f66
	add si,2
	mov byte[gs:si],al
	inc si
	pop ax

	shl al,3
	or al,bh
	mov byte[gs:si],al
	add word[pointer_write],5
	add word[act_offset],5

	jmp near .end
.asm_set6@var_dword@addr@num
	push ax
	mov si,word[pointer_write]
	mov byte[gs:si],bl
	inc si
	mov byte[gs:si],0x66
	inc si
	mov word[gs:si],0xba0f
	add si,2
	inc di
	mov al,byte[es:di]

	shl al,3
	or al,bh
	mov byte[gs:si],al
	inc si
	pop ax
	mov byte[gs:si],al
	add word[pointer_write],6
	add word[act_offset],6

	jmp near .end
.asm_set6@var_dword@num
	mov si,word[pointer_write]
	inc di
	mov bl,byte[es:di]
	mov byte[gs:si],0x66
	inc si
	mov word[gs:si],0xba0f
	add si,2

	shl bl,3
	or dl,bl
	or dl,00000110b
	mov byte[gs:si],dl
	inc si
	add word[pointer_write],4
	add word[act_offset],4
	push ax

	cmp bx,-1
	je near .asm_set5@var_byte@no_offset
	jmp near .asm_set5@var_byte@offset

.instruc_set7
	mov di,instruction_set7
.loop_set7
	cmp di,instruction_set8
	je near .instruc_set8

	call string_cmp

	push si
	mov si,di
	call string_len
	pop si

	add di,cx

	and ax,ax
	jz .asm_set7
.loop_set7@1
	add di,2

	jmp .loop_set7
.asm_set7
	inc di
	push di

	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef1
	call parse_line
	add word[pointer_read],cx

	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef2
	call parse_line
	add word[pointer_read],cx

	pop di

	cmp byte[failure],0
	jne near .error_opcode

	mov si,buffer_bef1
	call translate_8bit_reg
	cmp al,0xff
	jne near .asm_set7@reg_byte

	call translate_16bit_reg
	cmp al,0xff
	jne near .asm_set7@reg_word

	call translate_32bit_reg
	cmp al,0xff
	jne near .asm_set7@reg_dword

	push si
	push di
	mov di,op_byte
	cmpsd
	pop di
	pop si
	je near .asm_set7@var_byte

	push si
	push di
	mov di,op_word
	cmpsd
	pop di
	pop si
	je near .asm_set7@var_word

	push si
	push di
	mov di,op_dword
	mov cx,5
	rep cmpsb
	pop di
	pop si
	je near .asm_set7@var_dword

	jmp near .error_opcode
.asm_set7@reg_byte
	mov dl,al

	mov si,buffer_bef2
	call format_numbers_8bit
	jc .asm_set7@reg_byte@cl

	mov ah,byte[es:di]
	shl ah,3
	or ah,dl
	or ah,11000000b
	mov si,word[pointer_write]
	mov byte[gs:si],0xc0
	inc si
	xchg al,ah
	mov word[gs:si],ax
	add word[pointer_write],3
	add word[act_offset],3

	jmp near .end
.asm_set7@reg_byte@cl
	call translate_8bit_reg
	cmp al,1
	jne near .error_opcode

	mov al,byte[es:di]

	shl al,3
	or al,dl
	or al,11000000b
	mov ah,0xd2
	xchg al,ah
	mov si,word[pointer_write]
	mov word[gs:si],ax
	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.asm_set7@reg_word
	mov dl,al

	mov si,buffer_bef2
	call format_numbers_8bit
	jc .asm_set7@reg_word@cl

	mov ah,byte[es:di]
	shl ah,3
	or ah,dl
	or ah,11000000b
	mov si,word[pointer_write]
	mov byte[gs:si],0xc1
	inc si
	xchg al,ah
	mov word[gs:si],ax
	add word[pointer_write],3
	add word[act_offset],3

	jmp near .end
.asm_set7@reg_word@cl
	call translate_8bit_reg
	cmp al,1
	jne near .error_opcode

	mov al,byte[es:di]

	shl al,3
	or al,dl
	or al,11000000b
	mov ah,0xd3
	xchg al,ah
	mov si,word[pointer_write]
	mov word[gs:si],ax
	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.asm_set7@reg_dword
	mov dl,al

	mov si,buffer_bef2
	call format_numbers_8bit
	jc .asm_set7@reg_dword@cl

	mov ah,byte[es:di]
	shl ah,3
	or ah,dl
	or ah,11000000b
	mov si,word[pointer_write]
	mov word[gs:si],0xc166
	add si,2
	xchg al,ah
	mov word[gs:si],ax
	add word[pointer_write],4
	add word[act_offset],4

	jmp near .end
.asm_set7@reg_dword@cl
	call translate_8bit_reg
	cmp al,1
	jne near .error_opcode

	mov al,byte[es:di]

	shl al,3
	or al,dl
	or al,11000000b
	mov ah,0xd3
	xchg al,ah
	mov si,word[pointer_write]
	mov word[gs:si],0x66
	inc si
	mov word[gs:si],ax
	add word[pointer_write],3
	add word[act_offset],3

	jmp near .end
.asm_set7@var_byte
	add si,4
	call test_clips
	and al,al
	jnz near .error_no_clips

	call format_address_16bit
	cmp ax,0xffff
	jne near .asm_set7@var_byte@addr

	call look4label
	and al,al
	jnz near .error_label

	mov si,buffer_bef2
	call format_numbers_8bit
	jnc .asm_set7@var_byte@num

	call translate_8bit_reg
	cmp al,1
	jne near .error_opcode

	mov al,byte[es:di]
	shl al,3
	or al,6
	mov ah,0xd2
	xchg al,ah
	mov si,word[pointer_write]
	mov word[gs:si],ax
	add si,2
	add word[pointer_write],2
	add word[act_offset],2

	cmp bx,-1
	je .asm_set7@var_byte@no_offset

	call .asm@offset

	jmp near .end
.asm_set7@var_byte@no_offset
	mov al,1
	call add_offset2offset_table

	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.asm_set7@var_byte@num
	mov ah,byte[es:di]
	shl ah,3
	or ah,6
	mov si,word[pointer_write]
	mov byte[gs:si],0xc0
	inc si
	mov byte[gs:si],ah
	inc si
	add word[pointer_write],2
	add word[act_offset],2
	push ax

	cmp bx,-1
	je near .asm_set5@var_byte@no_offset
	jmp near .asm_set5@var_byte@offset
.asm_set7@var_byte@addr
	mov bx,ax
	mov si,buffer_bef2
	call format_numbers_8bit
	jnc .asm_set7@var_byte@addr@num

	call translate_8bit_reg
	cmp al,1
	jne near .error_opcode

	mov si,word[pointer_write]
	mov byte[gs:si],bl
	inc si
	mov byte[gs:si],0xd2
	inc si

	mov cl,byte[es:di]
	shl cl,3
	or cl,bh
	mov byte[gs:si],cl
	add word[pointer_write],3
	add word[act_offset],3

	jmp near .end
.asm_set7@var_byte@addr@num
	mov si,word[pointer_write]
	mov byte[gs:si],bl
	inc si
	mov byte[gs:si],0xc0
	inc si

	mov cl,byte[es:di]
	shl cl,3
	or cl,bh
	mov byte[gs:si],cl
	inc si
	mov byte[gs:si],al
	add word[pointer_write],4
	add word[act_offset],4

	jmp near .end
.asm_set7@var_word
	add si,4
	call test_clips
	and al,al
	jnz near .error_no_clips

	call format_address_16bit
	cmp ax,0xffff
	jne near .asm_set7@var_word@addr

	call look4label
	and al,al
	jnz near .error_label

	mov si,buffer_bef2
	call format_numbers_8bit
	jnc .asm_set7@var_word@num

	call translate_8bit_reg
	cmp al,1
	jne near .error_opcode

	mov al,byte[es:di]
	shl al,3
	or al,6
	mov ah,0xd3
	xchg al,ah
	mov si,word[pointer_write]
	mov word[gs:si],ax
	add si,2
	add word[pointer_write],2
	add word[act_offset],2

	cmp bx,-1
	je .asm_set7@var_word@no_offset

	call .asm@offset

	jmp near .end
.asm_set7@var_word@no_offset
	mov al,1
	call add_offset2offset_table

	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.asm_set7@var_word@num
	mov ah,byte[es:di]
	shl ah,3
	or ah,6
	mov si,word[pointer_write]
	mov byte[gs:si],0xc1
	inc si
	mov byte[gs:si],ah
	inc si
	add word[pointer_write],2
	add word[act_offset],2
	push ax

	cmp bx,-1
	je near .asm_set5@var_byte@no_offset
	jmp near .asm_set5@var_byte@offset
.asm_set7@var_word@addr
	mov bx,ax
	mov si,buffer_bef2
	call format_numbers_8bit
	jnc .asm_set7@var_word@addr@num

	call translate_8bit_reg
	cmp al,1
	jne near .error_opcode

	mov si,word[pointer_write]
	mov byte[gs:si],bl
	inc si
	mov byte[gs:si],0xd3
	inc si

	mov cl,byte[es:di]
	shl cl,3
	or cl,bh
	mov byte[gs:si],cl
	add word[pointer_write],3
	add word[act_offset],3

	jmp near .end
.asm_set7@var_word@addr@num
	mov si,word[pointer_write]
	mov byte[gs:si],bl
	inc si
	mov byte[gs:si],0xc1
	inc si

	mov cl,byte[es:di]
	shl cl,3
	or cl,bh
	mov byte[gs:si],cl
	inc si
	mov byte[gs:si],al
	add word[pointer_write],4
	add word[act_offset],4

	jmp near .end
.asm_set7@var_dword
	add si,5
	call test_clips
	and al,al
	jnz near .error_no_clips

	call format_address_16bit
	cmp ax,0xffff
	jne near .asm_set7@var_dword@addr

	call look4label
	and al,al
	jnz near .error_label

	mov si,buffer_bef2
	call format_numbers_8bit
	jnc .asm_set7@var_dword@num

	call translate_8bit_reg
	cmp al,1
	jne near .error_opcode

	mov al,byte[es:di]
	shl al,3
	or al,6
	mov ah,0xd3
	xchg al,ah
	mov si,word[pointer_write]
	mov byte[gs:si],0x66
	inc si
	mov word[gs:si],ax
	add si,2
	add word[pointer_write],3
	add word[act_offset],3

	cmp bx,-1
	je .asm_set7@var_dword@no_offset

	call .asm@offset

	jmp near .end
.asm_set7@var_dword@no_offset
	mov al,1
	call add_offset2offset_table

	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.asm_set7@var_dword@num
	mov ah,byte[es:di]
	shl ah,3
	or ah,6
	mov si,word[pointer_write]
	mov word[gs:si],0xc166
	add si,2
	mov byte[gs:si],ah
	inc si
	add word[pointer_write],3
	add word[act_offset],3
	push ax

	cmp bx,-1
	je near .asm_set5@var_byte@no_offset
	jmp near .asm_set5@var_byte@offset
.asm_set7@var_dword@addr
	mov bx,ax
	mov si,buffer_bef2
	call format_numbers_8bit
	jnc .asm_set7@var_dword@addr@num

	call translate_8bit_reg
	cmp al,1
	jne near .error_opcode

	mov si,word[pointer_write]
	mov byte[gs:si],bl
	inc si
	mov word[gs:si],0xd366
	add si,2

	mov cl,byte[es:di]
	shl cl,3
	or cl,bh
	mov byte[gs:si],cl
	add word[pointer_write],4
	add word[act_offset],4

	jmp near .end
.asm_set7@var_dword@addr@num
	mov si,word[pointer_write]
	mov byte[gs:si],bl
	inc si
	mov word[gs:si],0xc166
	add si,2

	mov cl,byte[es:di]
	shl cl,3
	or cl,bh
	mov byte[gs:si],cl
	inc si
	mov byte[gs:si],al
	add word[pointer_write],5
	add word[act_offset],5

	jmp near .end

.instruc_set8
	mov di,instruction_set8
.loop_set8
	cmp di,instruction_set9
	je near .instruc_set9

	call string_cmp

	push si
	mov si,di
	call string_len
	pop si

	add di,cx

	and ax,ax
	jz .asm_set8
.loop_set8@1
	add di,2

	jmp .loop_set8
.asm_set8
	inc di
	push di

	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef1
	call parse_line
	add word[pointer_read],cx

	pop di

	cmp byte[failure],0
	jne near .error_opcode

	mov si,buffer_bef1
	call look4label
	and al,al
	jnz near .error_label

	mov si,word[pointer_write]
	mov al,byte[es:di]
	mov byte[gs:si],al
	inc si
	inc word[pointer_write]
	inc word[act_offset]

	cmp bx,-1
	je .asm_set8@no_offset

	mov ax,word[act_offset]
	add ax,1
	sub bx,ax

	cmp bx,-127
	jl near .error_short_jmp

	mov byte[gs:si],bl
	inc word[pointer_write]
	inc word[act_offset]

	jmp near .end
.asm_set8@no_offset
	mov al,3
	call add_offset2offset_table

	inc word[pointer_write]
	inc word[act_offset]

	jmp near .end

.instruc_set9
	mov di,instruction_set9
.loop_set9
	cmp di,instruction_set10
	je near .instruc_set10

	call string_cmp

	push si
	mov si,di
	call string_len
	pop si

	add di,cx

	and ax,ax
	jz .asm_set9
.loop_set9@1
	add di,2

	jmp .loop_set9
.asm_set9
	inc di
	push di

	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef1
	call parse_line
	add word[pointer_read],cx

	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef2
	call parse_line
	add word[pointer_read],cx

	pop di

	cmp byte[failure],0
	jne near .error_opcode

	mov si,buffer_bef1
	call translate_16bit_reg
	cmp al,0xff
	jne .asm_set9@reg_word

	call translate_32bit_reg
	cmp al,0xff
	jne near .asm_set9@reg_dword

	jmp near .error_opcode
.asm_set9@reg_word
	mov dl,al

	mov si,buffer_bef2
	call translate_16bit_reg
	cmp al,0xff
	jne .asm_set9@reg_word@reg

	push di
	mov di,op_word
	cmpsd
	pop di
	jne near .error_opcode

	call test_clips
	and al,al
	jnz near .error_no_clips

	call format_address_16bit
	cmp ax,0xffff
	jne .asm_set9@reg_word@addr

	call look4label
	and al,al
	jnz near .error_label

	mov ah,byte[es:di]
	mov si,word[pointer_write]
	mov al,0x0f
	mov word[gs:si],ax
	add si,2

	shl dl,3
	or dl,6
	mov byte[gs:si],dl
	inc si
	add word[pointer_write],3
	add word[act_offset],3

	cmp bx,-1
	je .asm_set9@reg_word@no_offset

	call .asm@offset

	jmp near .end
.asm_set9@reg_word@no_offset
	mov al,1
	call add_offset2offset_table

	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.asm_set9@reg_word@reg
	mov bl,al
	mov ah,byte[es:di]
	mov al,0x0f
	mov si,word[pointer_write]
	mov word[gs:si],ax
	add si,2

	shl dl,3
	or bl,dl
	or bl,11000000b
	mov byte[gs:si],bl
	add word[pointer_write],3
	add word[act_offset],3

	jmp near .end
.asm_set9@reg_word@addr
	mov bx,ax
	mov si,word[pointer_write]
	mov byte[gs:si],bl
	inc si
	mov ah,byte[es:di]
	mov al,0x0f
	mov word[gs:si],ax
	add si,2

	shl dl,3
	or dl,bh
	mov byte[gs:si],dl
	add word[pointer_write],4
	add word[act_offset],4

	jmp near .end
.asm_set9@reg_dword
	mov dl,al

	mov si,buffer_bef2
	call translate_32bit_reg
	cmp al,0xff
	jne .asm_set9@reg_dword@reg

	push di
	mov di,op_dword
	mov cx,5
	rep cmpsb
	pop di
	jne near .error_opcode

	call test_clips
	and al,al
	jnz near .error_no_clips

	call format_address_16bit
	cmp ax,0xffff
	jne near .asm_set9@reg_dword@addr

	call look4label
	and al,al
	jnz near .error_label

	mov al,byte[es:di]
	mov si,word[pointer_write]
	mov byte[gs:si],0x66
	inc si
	mov ah,0x0f
	xchg al,ah
	mov word[gs:si],ax
	add si,2

	shl dl,3
	or dl,6
	mov byte[gs:si],dl
	inc si
	add word[pointer_write],4
	add word[act_offset],4

	cmp bx,-1
	je .asm_set9@reg_dword@no_offset

	call .asm@offset

	jmp near .end
.asm_set9@reg_dword@no_offset
	mov al,1
	call add_offset2offset_table

	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.asm_set9@reg_dword@reg
	mov bl,al
	mov ah,byte[es:di]
	mov al,0x0f
	mov si,word[pointer_write]
	mov byte[gs:si],0x66
	inc si
	mov word[gs:si],ax
	add si,2

	shl dl,3
	or bl,dl
	or bl,11000000b
	mov byte[gs:si],bl
	add word[pointer_write],4
	add word[act_offset],4

	jmp near .end
.asm_set9@reg_dword@addr
	mov bx,ax
	mov si,word[pointer_write]
	mov byte[gs:si],bl
	inc si
	mov ah,byte[es:di]
	mov al,0x0f
	mov byte[gs:si],0x66
	inc si
	mov word[gs:si],ax
	add si,2

	shl dl,3
	or dl,bh
	mov byte[gs:si],dl
	add word[pointer_write],5
	add word[act_offset],5

	jmp near .end

.instruc_set10
	mov di,instruction_set10
.loop_set10
	cmp di,instruction_set11
	je near .instruc_set11

	call string_cmp

	push si
	mov si,di
	call string_len
	pop si

	add di,cx

	and ax,ax
	jz .asm_set10
.loop_set10@1
	mov al,byte[es:di]
	inc di

	and al,al
	jz .loop_set10
	jmp .loop_set10@1
.asm_set10
	inc di
	push di

	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef1
	call parse_line
	add word[pointer_read],cx

	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef2
	call parse_line
	add word[pointer_read],cx

	pop di

	cmp byte[failure],0
	jne near .error_opcode

	mov si,buffer_bef1
	call translate_16bit_reg
	cmp al,0xff
	jne .asm_set10@reg_word

	call translate_32bit_reg
	cmp al,0xff
	jne near .asm_set10@reg_dword

	jmp near .error_opcode
.asm_set10@reg_word
	mov dl,al

	mov si,buffer_bef2
	call test_clips
	and al,al
	jnz near .error_no_clips

	call format_address_16bit
	cmp ax,0xffff
	jne .asm_set10@reg_word@addr

	call look4label
	and al,al
	jnz near .error_label

	mov si,word[pointer_write]
.asm_set10@reg_word@loop
	mov al,byte[es:di]
	inc di

	and al,al
	jz .asm_set10@reg_word@asm

	mov byte[gs:si],al
	inc si
	inc word[pointer_write]
	inc word[act_offset]

	jmp .asm_set10@reg_word@loop
.asm_set10@reg_word@asm
	shl dl,3
	or dl,6
	mov byte[gs:si],dl
	inc si
	inc word[pointer_write]
	inc word[act_offset]

	cmp bx,-1
	je .asm_set10@reg_word@asm@no_offset

	call .asm@offset

	jmp near .end
.asm_set10@reg_word@asm@no_offset
	mov al,1
	call add_offset2offset_table

	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.asm_set10@reg_word@addr
	mov bx,ax
	mov si,word[pointer_write]
	mov byte[gs:si],bl
	inc si
.asm_set10@reg_word@addr@loop
	mov al,byte[es:di]
	inc di

	and al,al
	jz .asm_set10@reg_word@addr@asm

	mov byte[gs:si],al
	inc si
	inc word[pointer_write]
	inc word[act_offset]

	jmp .asm_set10@reg_word@addr@loop
.asm_set10@reg_word@addr@asm
	shl dl,3
	or dl,bh
	mov byte[gs:si],dl
	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.asm_set10@reg_dword
	mov dl,al

	mov si,buffer_bef2
	call test_clips
	and al,al
	jnz near .error_no_clips

	call format_address_16bit
	cmp ax,0xffff
	jne .asm_set10@reg_dword@addr

	call look4label
	and al,al
	jnz near .error_label

	mov si,word[pointer_write]
	mov byte[gs:si],0x66
	inc si
.asm_set10@reg_dword@loop
	mov al,byte[es:di]
	inc di

	and al,al
	jz .asm_set10@reg_dword@asm

	mov byte[gs:si],al
	inc si
	inc word[pointer_write]
	inc word[act_offset]

	jmp .asm_set10@reg_dword@loop
.asm_set10@reg_dword@asm
	shl dl,3
	or dl,6
	mov byte[gs:si],dl
	inc si
	add word[pointer_write],2
	add word[act_offset],2

	cmp bx,-1
	je .asm_set10@reg_dword@asm@no_offset

	call .asm@offset

	jmp near .end
.asm_set10@reg_dword@asm@no_offset
	mov al,1
	call add_offset2offset_table

	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.asm_set10@reg_dword@addr
	mov bx,ax
	mov si,word[pointer_write]
	mov byte[gs:si],bl
	inc si
	mov byte[gs:si],0x66
	inc si
.asm_set10@reg_dword@addr@loop
	mov al,byte[es:di]
	inc di

	and al,al
	jz .asm_set10@reg_dword@addr@asm

	mov byte[gs:si],al
	inc si
	inc word[pointer_write]
	inc word[act_offset]

	jmp .asm_set10@reg_dword@addr@loop
.asm_set10@reg_dword@addr@asm
	shl dl,3
	or dl,bh
	mov byte[gs:si],dl
	add word[pointer_write],3
	add word[act_offset],3

	jmp near .end

.instruc_set11
	mov di,instruction_set11
.loop_set11
	cmp di,instruction_set12
	je near .instruc_set12

	call string_cmp

	push si
	mov si,di
	call string_len
	pop si

	add di,cx

	and ax,ax
	jz .asm_set11
.loop_set11@1
	add di,3

	jmp .loop_set11
.asm_set11
	inc di
	push di

	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef1
	call parse_line
	add word[pointer_read],cx

	pop di

	mov si,buffer_bef1
	call translate_16bit_reg
	cmp al,0xff
	jne .asm_set11@reg

	push di
	mov di,op_word
	cmpsd
	pop di
	je .asm_set11@var

	jmp near .error_opcode
.asm_set11@reg
	mov dl,al
	mov ah,byte[es:di]
	inc di
	mov al,0x0f
	mov si,word[pointer_write]
	mov word[gs:si],ax
	add si,2

	mov al,byte[es:di]
	shl al,3
	or al,dl
	or al,11000000b
	mov byte[gs:si],al
	add word[pointer_write],3
	add word[act_offset],3

	jmp near .end
.asm_set11@var
	call test_clips
	and al,al
	jnz near .error_no_clips

	call format_address_16bit
	cmp ax,0xffff
	jne .asm_set11@addr

	call look4label
	and al,al
	jnz near .error_label

	mov al,0x0f
	mov ah,byte[es:di]
	inc di
	mov si,word[pointer_write]
	mov word[gs:si],ax
	add si,2

	mov al,byte[es:di]
	shl al,3
	or al,6
	mov byte[gs:si],al
	inc si
	add word[pointer_write],3
	add word[act_offset],3

	cmp bx,-1
	je .asm_set11@var@no_offset

	call .asm@offset

	jmp near .end
.asm_set11@var@no_offset
	mov al,1
	call add_offset2offset_table

	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.asm_set11@addr
	mov bx,ax
	mov al,0x0f
	mov ah,byte[es:di]
	inc di
	mov si,word[pointer_write]
	mov byte[gs:si],bl
	inc si
	mov word[gs:si],ax
	add si,2

	mov al,byte[es:di]
	shl al,3
	or al,bh
	mov byte[gs:si],al
	add word[pointer_write],4
	add word[act_offset],4

	jmp near .end

.instruc_set12
	mov di,instruction_set12
.loop_set12
	cmp di,instruction_set13
	je near .instruc_set13

	call string_cmp

	push si
	mov si,di
	call string_len
	pop si

	add di,cx

	and ax,ax
	jz .asm_set12
.loop_set12@1
	add di,2

	jmp .loop_set12
.asm_set12
	inc di
	push di

	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef1
	call parse_line
	add word[pointer_read],cx

	pop di

	cmp byte[failure],0
	jne near .error_opcode

	mov si,buffer_bef1
	call test_clips
	and al,al
	jnz near .error_no_clips

	call format_address_16bit
	cmp ax,0xffff
	jne .asm_set12@addr

	call look4label
	and al,al
	jnz near .error_label

	mov si,word[pointer_write]
	mov al,byte[es:di]
	mov word[gs:si],0x010f
	add si,2

	shl al,3
	or al,6
	mov byte[gs:si],al
	inc si
	add word[pointer_write],3
	add word[act_offset],3

	cmp bx,-1
	je .asm_set12@no_offset

	call .asm@offset

	jmp near .end
.asm_set12@no_offset
	mov al,1
	call add_offset2offset_table

	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.asm_set12@addr
	mov si,word[pointer_write]
	mov byte[gs:si],al
	inc si
	mov word[gs:si],0x010f
	add si,2
	mov al,byte[es:di]

	shl al,3
	or al,ah
	mov byte[gs:si],al
	add word[pointer_write],4
	add word[act_offset],4

	jmp near .end

.instruc_set13

.instruc_set14
	mov di,instruction_set14
.loop_set14
	cmp di,end_instructions
	je near .error_opcode

	call string_cmp

	push si
	mov si,di
	call string_len
	pop si

	add di,cx

	and ax,ax
	jz .asm_set14
.loop_set14@1
	add di,2

	jmp .loop_set14
.asm_set14
	inc di
	push di

	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef1
	call parse_line
	add word[pointer_read],cx

	mov cx,word[pointer_read]
	mov si,line_buf
	mov di,buffer_bef2
	call parse_line
	add word[pointer_read],cx

	pop di

	cmp byte[failure],0
	jne near .error_opcode

	mov si,buffer_bef1
	call translate_16bit_reg
	cmp al,0xff
	jne .asm_set14@reg_word

	call translate_32bit_reg
	cmp al,0xff
	jne near .asm_set14@reg_dword

	jmp near .error_opcode
.asm_set14@reg_word
	mov dl,al

	mov si,buffer_bef2
	call test_clips
	and al,al
	jnz near .error_no_clips

	call format_address_16bit
	cmp ax,0xffff
	jne .asm_set14@reg_word@addr

	call look4label
	and al,al
	jnz near .error_label

	mov al,byte[es:di]
	mov si,word[pointer_write]
	mov byte[gs:si],al
	inc si

	shl dl,3
	or dl,6
	mov byte[gs:si],dl
	inc si
	add word[pointer_write],2
	add word[act_offset],2

	cmp bx,-1
	je .asm_set14@reg_word@no_offset

	call .asm@offset

	jmp near .end
.asm_set14@reg_word@no_offset
	mov al,1
	call add_offset2offset_table

	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.asm_set14@reg_word@addr
	mov bx,ax

	mov al,byte[es:di]
	mov si,word[pointer_write]
	mov byte[gs:si],bl
	inc si
	mov byte[gs:si],al
	inc si

	shl dl,3
	or dl,bh
	mov byte[gs:si],dl
	add word[pointer_write],3
	add word[act_offset],3

	jmp near .end
.asm_set14@reg_dword
	mov dl,al

	mov si,buffer_bef2
	call test_clips
	and al,al
	jnz near .error_no_clips

	call format_address_16bit
	cmp ax,0xffff
	jne .asm_set14@reg_dword@addr

	call look4label
	and al,al
	jnz near .error_label

	mov ah,byte[es:di]
	mov si,word[pointer_write]
	mov al,0x66
	mov word[gs:si],ax
	add si,2

	shl dl,3
	or dl,6
	mov byte[gs:si],dl
	inc si
	add word[pointer_write],3
	add word[act_offset],3

	cmp bx,-1
	je .asm_set14@reg_dword@no_offset

	call .asm@offset

	jmp near .end
.asm_set14@reg_dword@no_offset
	mov al,1
	call add_offset2offset_table

	add word[pointer_write],2
	add word[act_offset],2

	jmp near .end
.asm_set14@reg_dword@addr
	mov bx,ax

	mov ah,byte[es:di]
	mov si,word[pointer_write]
	mov byte[gs:si],bl
	inc si
	mov al,0x66
	mov word[gs:si],ax
	add si,2

	shl dl,3
	or dl,bh
	mov byte[gs:si],dl
	add word[pointer_write],4
	add word[act_offset],4

	jmp near .end

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.error_short_jmp
	mov eax,dword[line]
	mov si,msg_short_jmp_range
	call print_error

	mov byte[ffailure],0xff

	jmp short .end
.error_unknown
	mov eax,dword[line]
	mov si,msg_unknown_opcode
	call print_error

	mov byte[ffailure],0xff

	jmp short .end
.error_opcode
	mov eax,dword[line]
	mov si,msg_invalid_opcode
	call print_error

	mov byte[ffailure],0xff

	jmp short .end
.error_label
	mov eax,dword[line]
	mov si,msg_unknown_label
	call print_error

	mov byte[ffailure],0xff

	jmp short .end
.error_no_size_operand
	mov eax,dword[line]
	mov si,msg_no_size_operand
	call print_error

	mov byte[ffailure],0xff

	jmp short .end
.error_no_clips
	mov eax,dword[line]
	mov si,msg_no_clips
	call print_error

	mov byte[ffailure],0xff

;	jmp short .end
.end
	popad
	ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
msg_startup				db 'ANASM v',VERSION,' (C)Copyright 2002',13,10
						db 'All Rights Reserved',13,10,13,10,0
msg_info				db 'Usage : ANASM filein.asm [options]',13,10
						db 13,10,'options:',13,10
						db 13,10,9,'-o',9,'fileout.com'
						db 13,10,9,'-lb',9,'size of line buffer(standard 512byte and max. 2048byte)'
						db 13,10,9,'-h',9,'help'
						db 13,10,9,'-d',9,'debug modus'

						db 13,10,0
msg_unknown_para		db 'unknown parameter',13,10,0
msg_incomplete_para		db 'parameters are incomplete',13,10,0
msg_no_in				db 'no file to read',13,10,0
msg_lines_asm			db ' lines assembled',13,10,0
msg_error				db ' error: ',0
msg_invalid_opcode		db 'invalid combination of opcode and operands',13,10,0
msg_unknown_label		db 'unknown label',13,10,0
msg_no_local_label		db 'no local label defined',13,10,0
msg_unknown_opcode		db 'unknown opcode/instruction',13,10,0
msg_label_is_there		db 'label is already present',13,10,0
msg_no_size_operand		db 'no size operand',13,10,0
msg_no_clips			db '[] are missing',13,10,0
msg_short_jmp_range		db 'short jump is out of range',13,10,0

msg_newline				db 13,10,0

msg_label_table			db 13,10,'label table :',13,10,0
msg_offset_table		db 13,10,'offset table :',13,10,0

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
reg_dr					db 'dr',0
reg_cr					db 'cr',0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
op_byte					db 'byte',0
op_word					db 'word',0
op_dword				db 'dword',0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
op_short				db 'short',0
op_near					db 'near',0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
op_org					db 'org',0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
op_db					db 'db',0
op_dw					db 'dw',0
op_dd					db 'dd',0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
op_int					db 'int',0
op_pop					db 'pop',0
op_push					db 'push',0
op_mov					db 'mov',0
op_jmp					db 'jmp',0
op_call					db 'call',0
op_arpl					db 'arpl',0
op_enter				db 'enter',0
op_imul					db 'imul',0
op_in					db 'in',0
op_out					db 'out',0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
instructions:

instruction_set0:
db 'lock',0,0xf0
db 'rep',0,0xf3
db 'repe',0,0xf3
db 'repz',0,0xf3
db 'repne',0,0xf2
db 'repnz',0,0xf2

instruction_set1:
db 'aaa',0,0x37,0
db 'aad',0,0xd5,0x0a,0
db 'aam',0,0xd4,0x0a,0
db 'aas',0,0x3f,0
db 'cbw',0,0x98,0
db 'cdq',0,0x99,0
db 'clc',0,0xf8,0
db 'cld',0,0xfc,0
db 'cli',0,0xfa,0
db 'clts',0,0x0f,0x06,0
db 'cmc',0,0xf5,0
db 'cmpsb',0,0xa6,0
db 'cmpsw',0,0xa7,0
db 'cmpsd',0,0x66,0xa7,0
db 'cwd',0,0x99,0
db 'cwde',0,0x98,0
db 'daa',0,0x27,0
db 'das',0,0x2f,0
db 'hlt',0,0xf4,0
db 'insb',0,0x6c,0
db 'insw',0,0x6d,0
db 'insd',0,0x66,0x6d,0
db 'into',0,0xce,0
db 'iret',0,0xcf,0
db 'iretd',0,0x66,0xcf,0
db 'lahf',0,0x9f,0
db 'leave',0,0xc9,0
db 'lodsb',0,0xac,0
db 'lodsw',0,0xad,0
db 'lodsd',0,0x66,0xad,0
db 'movsb',0,0xa4,0
db 'movsw',0,0xa5,0
db 'movsd',0,0x66,0xa5,0
db 'nop',0,0x90,0
db 'outsb',0,0x6e,0
db 'outsw',0,0x6f,0
db 'outsd',0,0x66,0x6f,0
db 'popa',0,0x61,0
db 'popad',0,0x66,0x61,0
db 'popf',0,0x9d,0
db 'popfd',0,0x66,0x9d,0
db 'pusha',0,0x60,0
db 'pushad',0,0x66,0x60,0
db 'pushf',0,0x9c,0
db 'pushfd',0,0x66,0x9c,0
db 'ret',0,0xc3,0
db 'sahf',0,0x9e,0
db 'scasb',0,0xae,0
db 'scasw',0,0xaf,0
db 'scasd',0,0x66,0xaf,0
db 'stc',0,0xf9,0
db 'std',0,0xfd,0
db 'sti',0,0xfb,0
db 'stosb',0,0xaa,0
db 'stosw',0,0xab,0
db 'stosd',0,0x66,0xab,0
db 'wait',0,0x9b,0
db 'xlatb',0,0xd7,0

instruction_set2:
db 'dec',0,0xfe,1,0
db 'div',0,0xf6,6,0
db 'idiv',0,0xf6,7,0
db 'inc',0,0xfe,0,0
db 'neg',0,0xf6,3,0
db 'not',0,0xf6,2,0
db 'mul',0,0xf6,4,0

instruction_set3:
db 'seta',0,0x97,0
db 'setae',0,0x93,0
db 'setb',0,0x92,0
db 'setbe',0,0x96,0
db 'setc',0,0x92,0
db 'sete',0,0x94,0
db 'setg',0,0x9f,0
db 'setge',0,0x9d,0
db 'setl',0,0x9c,0
db 'setle',0,0x9e,0
db 'setna',0,0x96,0
db 'setnae',0,0x92,0
db 'setnb',0,0x93,0
db 'setnbe',0,0x97,0
db 'setnc',0,0x93,0
db 'setne',0,0x95,0
db 'setng',0,0x9e,0
db 'setnge',0,0x9c,0
db 'setnl',0,0x9d,0
db 'setnle',0,0x9f,0
db 'setno',0,0x91,0
db 'setnp',0,0x9b,0
db 'setns',0,0x99,0
db 'setnz',0,0x95,0
db 'seto',0,0x90,0
db 'setp',0,0x9a,0
db 'setpe',0,0x9a,0
db 'setpo',0,0x9b,0
db 'sets',0,0x98,0
db 'setz',0,0x94,0

instruction_set4:
db 'ja',0,0x77,0
db 'jae',0,0x73,0
db 'jb',0,0x72,0
db 'jbe',0,0x76,0
db 'jc',0,0x72,0
db 'je',0,0x74,0
db 'jg',0,0x7f,0
db 'jge',0,0x7d,0
db 'jl',0,0x7c,0
db 'jle',0,0x7e,0
db 'jna',0,0x76,0
db 'jnae',0,0x72,0
db 'jnb',0,0x73,0
db 'jnbe',0,0x77,0
db 'jnc',0,0x73,0
db 'jne',0,0x75,0
db 'jng',0,0x7e,0
db 'jnge',0,0x7c,0
db 'jnl',0,0x7d,0
db 'jnle',0,0x7f,0
db 'jno',0,0x71,0
db 'jnp',0,0x7b,0
db 'jns',0,0x79,0
db 'jnz',0,0x75,0
db 'jo',0,0x70,0
db 'jp',0,0x7a,0
db 'jpe',0,0x7a,0
db 'jpo',0,0x7b,0
db 'js',0,0x78,0
db 'jz',0,0x74,0

instruction_set5:
db 'adc',0,0x80,2,0x10
db 'add',0,0x80,0,0x00
db 'and',0,0x80,4,0x20
db 'cmp',0,0x80,7,0x38
db 'or',0,0x80,1,0x08
db 'sbb',0,0x80,3,0x18
db 'sub',0,0x80,5,0x28
db 'xor',0,0x80,6,0x30

instruction_set6:
db 'bt',0,0xa3,4
db 'btc',0,0xbb,7
db 'btr',0,0xb3,6
db 'bts',0,0xab,5

instruction_set7:
db 'rcl',0,2
db 'rcr',0,3
db 'rol',0,0
db 'ror',0,1
db 'sal',0,4
db 'sar',0,7
db 'shl',0,4
db 'shr',0,5

instruction_set8:
db 'loop',0,0xe2
db 'loope',0,0xe1
db 'loopne',0,0xe0
db 'loopnz',0,0xe0
db 'loopz',0,0xe1

instruction_set9:
db 'bsf',0,0xbc
db 'bsr',0,0xbd
db 'lar',0,0x02
db 'lsl',0,0x03

instruction_set10:
db 'lds',0,0xc5,0
db 'les',0,0xc4,0
db 'lfs',0,0x0f,0xb4,0
db 'lgs',0,0x0f,0xb5,0
db 'lss',0,0x0f,0xb2,0

instruction_set11:
db 'lldt',0,0,2
db 'lmsw',0,1,6
db 'ltr',0,0,3
db 'sldt',0,0,0
db 'smsw',0,1,4
db 'verr',0,0,4
db 'verw',0,0,5

instruction_set12:
db 'lidt',0,3
db 'lgdt',0,2
db 'sgdt',0,0
db 'sidt',0,1

instruction_set13:
db 'shld',0,0xa4
db 'shrd',0,0xac

instruction_set14:
db 'bound',0,0x62
db 'lea',0,0x8d

end_instructions:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
options					db 0
ffailure				db 0
failure					db 0
act_offset				dw 0
act_org					dw 0
pointer_read			dw 0
pointer_write			dw 0
line_buf_len			dw 512
line					dd 0
lines					dd 0
lines_str				dw 0,0,0,0,0
						db 0

mem_fileout				dw 0
mem_label				dw 0
mem_offset				dw 0

label_free				dw 0
act_label				dw -1

file_in_handle			dw 0
file_out_handle			dw 0
file_in					dw 0
file_out				dw 0

buffer_opcode			resb 128 ;times 128 db 0
buffer_bef1				resb 128 ;times 128 db 0
buffer_bef2				resb 128 ;times 128 db 0
line_buf				resb 2048 ;times 1024 db 0
buffer_cmdline			resb 128 ;times 81h db 0

end_progg: