	model	large compiler_text,pascal
	include	compiler.inc

	.code	compiler_text

	public	LoadSegDI
	public	PushFloat
	public	PutFwait
	public	PutEmulInt
	public	Need8087
	public	PushReal
	public	LoadReal
	public	ConvertOrdinal
	public	Increment
	public	PushValue
	public	PutPush
	public	FindEmptyReg
	public	PopValue
	public	Scale
	public	BackScale
	public	MakePtr
	public	FreeRegs
	public	LoadValue
	public	StoreValue
	public	SwapSegOfs
	public	AllocStack
	public	CreateLocalVar
	public	SetBaseAndSize
	public	PushSetAddr
	public	PushWord
	public	LoadReg
	public	LoadWord
	public	StoreReg
	public	PutMovRMImm
	public	PutArOpAX
	public	PutArOp
	public	PutLogOp
	public	PutArOpImm
	public	PutArOpRMImm
	public	FloatAddOffset
	public	AddOffset
	public	PutFloatRM
	public	PutRM
	public	AddReg
	public	PutPrefix

LoadSegDI	proc	near
	call	LoadDI
	jmp	GetSegment
LoadSegDI	endp

LoadDI	proc	near
	test	[di].exMisc,efBP
	jz	@@1
	mov	dx,388dh		; lea	di,...
	jmp	AddReg
@@1:	test	[di].exMisc,efDI
	jz	@@3
	test	[di].exMisc,efDS+efCS+efConst
	jnz	@@2
	cmp	[di].exOffset,0
	je	@@5
@@2:	mov	ax,0c781h		; add	di,...
	Invoke	PutWord
	jmp	short @@4
@@3:	mov	al,0bfh			; mov	di,...
	Invoke	PutByte
@@4:	jmp	PutOffset
@@5:	ret
LoadDI	endp

PushFloat	proc	near
	cmp	[di].exLocation,elImmediate
	jne	@@2
	les	bx,[si].exType
	mov	al,es:[bx].tdModifier
	lea	bx,[di].exValue
	push	ax
	Invoke	Extended2Float
	pop	ax
	mov	bx,10
	cmp	al,emExtended
	je	@@1
	mov	bl,8
	cmp	al,emSingle
	jne	@@1
	mov	bl,4
@@1:	dec	bx
	dec	bx
	mov	ax,word ptr [di+bx].exValue
	push	bx
	call	PushWord
	pop	bx
	or	bx,bx
	jnz	@@1
	Chain	DoneExpr
@@2:	cmp	[di].exLocation,elMemory
	jne	@@4
	mov	al,[di].exModifier
	les	bx,[si].exType
	cmp	al,es:[bx].tdModifier
	jne	@@3
	mov	cx,es:[bx].tdSizeOf
	Invoke	UseExpr
	call	PushMemory
	Chain	DoneExpr
@@3:	Invoke	PushExt
@@4:	Invoke	UseExpr
	les	bx,[si].exType
	mov	ax,es:[bx].tdSizeOf
	mov	dl,0ech			; sub	sp,...
	call	PutArOpImm
	mov	ax,0e389h		; mov	bx,sp
	Invoke	PutWord
	call	PutEmulInt
	mov	al,3ch
	Invoke	PutByte
	mov	ax,1f59h		; fstp	ss:[bx]
	les	bx,[si].exType
	or	al,es:[bx].tdModifier
	test	al,2
	jz	@@5
	mov	ah,3fh
@@5:	Invoke	PutWord
	call	PutFwait
	Chain	DoneExpr
PushFloat	endp

PutFwait	proc	near
	mov	ax,3dcdh		; fwait
	Chain	PutWord
PutFwait	endp

PutEmulInt	proc	near
	call	Need8087
	mov	al,0cdh			; int
	Chain	PutByte
PutEmulInt	endp

Need8087	proc	near
	test	CompilerOptions,co8087
	jz	@@1
	push	ds
	mov	ds,Dictionary.Segm
	or	ds:uhFlags,uf8087
	pop	ds
	ret
@@1:	mov	ax,116
	Chain	CompileError
Need8087	endp

PushReal	proc	near
	Invoke	UseExpr
	call	_PushReal
	Chain	DoneExpr
PushReal	endp

_PushReal	proc	near
	cmp	[di].exLocation,elMemory
	jne	@@1
	mov	cx,6
	jmp	PushMemory
@@1:	mov	al,lrR1
	call	LoadReal
	mov	ax,5352h		; push	dx	push	bx
	Invoke	PutWord
	mov	al,50h			; push	ax
	Chain	PutByte
_PushReal	endp

LoadReal	proc	near
	cmp	[di].exLocation,elRegister
	je	@@1
	mov	cl,al
	mov	ax,lvAX+lvCX*256
	call	ShiftReal
	mov	ax,lvBX+lvSI*256
	call	ShiftReal
	mov	ax,lvDX+lvDI*256
	call	ShiftReal
	mov	[di].exLocation,elRegister
@@1:	mov	[di].exRegsUsed,erAll
	ret
LoadReal	endp

ShiftReal	proc	near
	or	cl,cl
	jz	@@1
	mov	al,ah
@@1:	call	LoadReg
	cmp	[di].exLocation,elMemory
	jne	@@2
	add	[di].exOffset,2
	ret
@@2:	mov	ax,[di].exValue.W2
	mov	[di].exValue.W0,ax
	mov	ax,[di].exValue.W4
	mov	[di].exValue.W2,ax
	ret
ShiftReal	endp

ConvertOrdinal	proc	near
	mov	cl,[di].exModifier
	mov	ch,al
	cmp	[di].exLocation,elImmediate
	jne	@@3
	mov	ax,[di].exValue.W0
	mov	dx,[di].exValue.W2
	test	ch,emX
	jnz	@@1
	cbw
	test	ch,emUnsigned
	jz	@@1
	xor	ah,ah
@@1:	test	ch,emXX
	jnz	@@2
	cwd
	test	ch,emUnsigned
	jz	@@2
	xor	dx,dx
@@2:	mov	[di].exValue.W0,ax
	mov	[di].exValue.W2,dx
	jmp	short @@7
@@3:	xor	ax,ax
	xor	dx,dx
	test	ch,emX
	jz	@@4
	test	cl,emX
	jnz	@@4
	mov	al,98h			; cbw
	test	cl,emUnsigned
	jz	@@4
	mov	ax,0e430h		; xor	ah,ah
@@4:	test	ch,emXX
	jz	@@5
	test	cl,emXX
	jnz	@@5
	or	[di].exRegsUsed,erDX
	mov	dl,99h			; cwd
	test	cl,emUnsigned
	jz	@@5
	mov	dx,0d231h		; xor	dx,dx
@@5:	mov	bx,ax
	or	bx,dx
	jnz	@@6
	cmp	[di].exLocation,elAddress
	jne	@@7
	test	ch,emX
	jnz	@@7
@@6:	push	cx dx ax
	Invoke	UseExpr
	mov	al,lvAX
	call	LoadValue
	pop	ax
	call	PutBytes
	pop	ax
	call	PutBytes
	Invoke	DoneExpr
	pop	cx
@@7:	mov	[di].exModifier,ch
	ret
ConvertOrdinal	endp

PutBytes	proc	near
	or	ax,ax
	jz	@@2
	or	ah,ah
	jz	@@1
	Chain	PutWord
@@1:	Chain	PutByte
@@2:	ret
PutBytes	endp

Increment	proc	near
	cmp	[si].exLocation,elImmediate
	jne	@@3
	Invoke	UseExpr
	test	[di].exModifier,emXX
	jnz	@@1
	cmp	[si].exValue.W0,1
	jne	@@1
	cmp	[si].exValue.W2,0
	jne	@@1
	mov	dl,0feh			; inc
	call	PutRM
	Chain	DoneExpr
@@1:	mov	ax,[si].exValue.W0
	push	dx
	call	PutArOpRMImm
	pop	dx
	test	[di].exModifier,emXX
	jz	@@2
	add	[di].exOffset,2
	mov	ax,[si].exValue.W2
	mov	dl,dh
	or	dl,10h			; adc
	call	PutArOpRMImm
	sub	[di].exOffset,2
@@2:	Chain	DoneExpr
@@3:	push	dx
	xchg	si,di
	Invoke	UseExpr
	mov	al,[si].exRegsUsed
	call	FindEmptyReg
	xchg	si,di
	Invoke	UseExpr
	xchg	si,di
	xor	al,al
	call	PopValue
	xchg	si,di
	pop	dx
	mov	cl,dh
	mov	dh,[si].exMisc
	shl	dh,1
	shl	dh,1
	shl	dh,1
	mov	ch,dh
	call	PutRM
	test	[di].exModifier,emXX
	jz	@@4
	add	[di].exOffset,2
	mov	dx,cx
	or	dx,1010h		; adc
	call	PutRM
	sub	[di].exOffset,2
@@4:	Chain	DoneExpr
Increment	endp

PushValue	proc	near
	Invoke	UseExpr
	call	PutPush
	Chain	DoneExpr
PushValue	endp

PutPush	proc	near
	cmp	[di].exLocation,elMemory
	jne	@@2
	test	[di].exModifier,emX
	jz	@@5
	test	[di].exModifier,emXX
	jz	@@1
	add	[di].exOffset,2
	mov	dx,30ffh		; push
	call	AddReg
	sub	[di].exOffset,2
@@1:	mov	dx,30ffh		; push
	call	AddReg
	jmp	short @@13
@@2:	cmp	[di].exLocation,elRegister
	je	@@6
	cmp	[di].exLocation,elAddress
	je	@@8
	test	CompilerOptions,co286Code
	jz	@@5
	test	[di].exModifier,emXX
	jz	@@3
	mov	ax,[di].exValue.W2
	call	PushWord286
@@3:	mov	ax,[di].exValue.W0
	test	[di].exModifier,emX
	jnz	@@4
	cbw
@@4:	call	PushWord286
	jmp	short @@13
@@5:	mov	al,lvAX
	call	LoadValue
@@6:	test	[di].exModifier,emXX
	jz	@@7
	mov	al,52h			; push	dx
	Invoke	PutByte
@@7:	mov	al,50h			; push	ax
	Invoke	PutByte
	jmp	short @@13
@@8:	test	[di].exMisc,efSeg
	jnz	@@9
	call	LoadDI
	test	[di].exModifier,emXX
	jz	@@12
@@9:	test	[di].exMisc,efDS+efSS+efCS+efES
	jnz	@@10
	mov	al,0b8h			; mov	ax,
	call	LoadSegment
	mov	al,50h			; push	ax
	jmp	short @@11
@@10:	call	GetPrefix
	or	al,6			; push
@@11:	Invoke	PutByte
	test	[di].exModifier,emXX
	jz	@@13
@@12:	mov	al,57h			; push	di
	Invoke	PutByte
@@13:	mov	[di].exLocation,elPushed
	ret
PutPush	endp

FindEmptyReg	proc	near
	test	[di].exModifier,emXX
	jnz	@@1
	test	al,erAX
	jz	@@2
	test	al,erDX
	jz	@@3
	test	al,erCX
	jz	@@4
	test	al,erBX
	jz	@@5
	jmp	PutPush
@@1:	test	al,erAX+erDX
	jz	@@2
	test	al,erCX+erBX
	jz	@@4
	jmp	PutPush
@@2:	mov	al,lvAX
	jmp	LoadValue
@@3:	mov	al,lvDX
	jmp	LoadValue
@@4:	mov	al,lvCX
	jmp	LoadValue
@@5:	mov	al,lvBX
	jmp	LoadValue
FindEmptyReg	endp

PopValue	proc	near
	cmp	[di].exLocation,elPushed
	jne	@@4
	mov	[di].exLocation,elRegister
	test	[di].exModifier,emXX
	jnz	@@2
	mov	ah,58h			; pop	ax
	mov	cx,erAX+lvAX*256
	test	al,cl
	jz	@@1
	mov	ah,5ah			; pop	dx
	mov	cx,erDX+lvDX*256
	test	al,cl
	jz	@@1
	mov	ah,59h			; pop	cx
	mov	cx,erCX+lvCX*256
	test	al,cl
	jz	@@1
	mov	ah,5bh			; pop	bx
	mov	cx,erBX+lvBX*256
@@1:	or	[di].exRegsUsed,cl
	mov	[di].exMisc,ch
	mov	al,ah
	Chain	PutByte
@@2:	mov	cx,erAX+erDX+lvAX*256
	test	al,cl
	mov	ax,5a58h		; pop	ax	pop	dx
	jz	@@3
	mov	cx,erCX+erBX+lvCX*256
	mov	ax,5b59h		; pop	cx	pop	bx
@@3:	or	[di].exRegsUsed,cl
	mov	[di].exMisc,ch
	Chain	PutWord
@@4:	ret
PopValue	endp

Scale	proc	near
	cmp	cx,1
	jb	@@10
	je	@@7
	mov	bx,cx
	mov	dx,-1
@@1:	inc	dx
	shr	bx,1
	jnc	@@1
	jz	@@8
	cmp	cx,7
	jae	@@10
	mov	ch,al
	push	cx
	call	LoadValue
	pop	cx
	cmp	cl,6
	jne	@@2
	call	@@5
@@2:	mov	ax,0f08bh		; mov	si,
	call	@@6
	call	@@5
	cmp	cl,5
	jne	@@3
	call	@@5
@@3:	mov	ax,0f001h		; add	,si
	jmp	short @@6
@@4:	call	@@5
@@5:	mov	ax,0e0d1h		; shl	,1
@@6:	or	ah,ch
	Chain	PutWord
@@7:	ret
@@8:	mov	cl,dl
	mov	ch,al
	push	cx
	call	LoadValue
	pop	cx
	cmp	cl,1
	je	@@5
	test	CompilerOptions,co286Code
	jnz	@@9
	cmp	cl,2
	je	@@4
	or	[di].exRegsUsed,erCX
	mov	al,0b1h			; mov	cl,
	mov	ah,cl
	Invoke	PutWord
	mov	ax,0e0d3h		; shl	ax,cl
	jmp	@@6
@@9:	mov	ax,0e0c1h		; shl	ax,
	call	@@6
	mov	al,cl
	Chain	PutByte
@@10:	test	CompilerOptions,co286Code
	jnz	@@12
	or	[di].exRegsUsed,erDX
	cmp	[di].exLocation,elRegister
	jne	@@11
	cmp	[di].exMisc,lvAX
	jne	@@11
	mov	al,0bah			; mov	dx,
	Invoke	PutByte
	mov	ax,cx
	Invoke	PutWord
	mov	ax,0e2f7h		; mul	dx
	Chain	PutWord
@@11:	mov	al,0b8h			; mov	ax,
	Invoke	PutByte
	mov	ax,cx
	Invoke	PutWord
	mov	dx,20f7h		; mul
	call	AddReg
	mov	cl,lvAX
	jmp	short @@15
@@12:	push	ax
	shl	al,1
	shl	al,1
	shl	al,1
	mov	dh,al
	mov	ax,cx
	cbw
	cmp	ax,cx
	jz	@@13
	mov	dl,69h			; imul
	call	AddReg
	mov	ax,cx
	Invoke	PutWord
	jmp	short @@14
@@13:	mov	dl,6bh			; imul
	call	AddReg
	mov	al,cl
	Invoke	PutByte
@@14:	pop	cx
@@15:	mov	al,1
	shl	al,cl
	mov	[di].exLocation,elRegister
	mov	[di].exMisc,cl
	or	[di].exRegsUsed,al
	ret
Scale	endp

BackScale	proc	near
	cmp	cx,1
	je	@@9
	mov	dx,0f9f7h		; idiv	cx
	test	[di].exModifier,emSigned
	jnz	@@6
	mov	bx,cx
	mov	dx,-1
@@1:	inc	dx
	shr	bx,1
	jnc	@@1
	jnz	@@5
	cmp	dl,1
	je	@@3
	test	CompilerOptions,co286Code
	jnz	@@4
	cmp	dl,2
	je	@@2
	or	[di].exRegsUsed,erCX
	mov	al,0b1h			; mov	cl,
	mov	ah,dl
	Invoke	PutWord
	mov	ax,0e8d3h		; shr	ax,cl
	Chain	PutWord
@@2:	call	@@3
@@3:	mov	ax,0e8d1h		; shr	ax,1
	Chain	PutWord
@@4:	mov	ax,0e8c1h		; shr	ax,
	Invoke	PutWord
	mov	al,dl
	Chain	PutByte
@@5:	mov	dx,0f1f7h		; div	cx
	test	[di].exModifier,emUnsigned
	jnz	@@7
@@6:	mov	al,99h			; cwd
	Invoke	PutByte
	jmp	short @@8
@@7:	mov	ax,0d231h		; xor	dx,dx
	Invoke	PutWord
@@8:	mov	al,0b9h			; mov	cx,
	Invoke	PutByte
	mov	ax,cx
	Invoke	PutWord
	mov	ax,dx
	Invoke	PutWord
	or	[di].exRegsUsed,erCX+erDX
@@9:	ret
BackScale	endp

MakePtr	proc	near
	mov	al,erAX
	call	FreeRegs
	xchg	si,di
	mov	al,lvDX
	call	LoadValue
	xchg	si,di
	ret
MakePtr	endp

FreeRegs	proc	near
	test	[si].exRegsUsed,al
	jnz	@@1
	Invoke	UseExpr
	mov	al,lvAX
	call	LoadValue
	xchg	si,di
	Invoke	UseExpr
	xchg	si,di
	ret
@@1:	push	ax
	or	al,[di].exRegsUsed
	push	ax
	xchg	si,di
	Invoke	UseExpr
	pop	ax
	call	FindEmptyReg
	xchg	si,di
	Invoke	UseExpr
	mov	al,lvAX
	call	LoadValue
	xchg	si,di
	pop	ax
	call	PopValue
	xchg	si,di
	ret
FreeRegs	endp

LoadValue	proc	near
	mov	cl,al
	test	[di].exModifier,emXX
	jz	@@1
	call	LoadReg
	mov	ax,2
	call	SwapSegOfs
	mov	al,cl
	add	al,2
	call	LoadReg
	mov	al,erAX+erDX
	jmp	short @@2
@@1:	call	LoadReg
	mov	al,erAX
@@2:	shl	al,cl
	mov	[di].exLocation,elRegister
	or	[di].exRegsUsed,al
	mov	[di].exMisc,cl
	ret
LoadValue	endp

StoreValue	proc	near
	mov	cl,al
	call	StoreReg
	test	[di].exModifier,emXX
	jz	@@1
	add	[di].exOffset,2
	mov	al,cl
	add	al,2
	call	StoreReg
	sub	[di].exOffset,2
@@1:	ret
StoreValue	endp

SwapSegOfs	proc	near
	cmp	[di].exLocation,elMemory
	jne	@@1
	add	[di].exOffset,ax
	ret
@@1:	cmp	[di].exLocation,elRegister
	jne	@@2
	add	[di].exMisc,al
	ret
@@2:	cmp	[di].exLocation,elImmediate
	jne	@@3
	mov	ax,[di].exValue.Offs
	xchg	ax,[di].exValue.Segm
	mov	[di].exValue.Offs,ax
	ret
@@3:	xor	[di].exMisc,efSeg
	ret
SwapSegOfs	endp

AllocStack	proc	near
	mov	bx,ax
	mov	ax,TempLocalsSize
	sub	ax,bx
	test	CompilerOptions,coWordAlign
	jz	@@1
	cmp	bx,1
	je	@@1
	and	ax,0fffeh
@@1:	mov	TempLocalsSize,ax
	mov	bx,LocalsSize
	or	bx,bx
	jz	@@2
	cmp	ax,bx
	jae	@@3
@@2:	mov	LocalsSize,ax
@@3:	ret
AllocStack	endp

CreateLocalVar	proc	near
	call	AllocStack
	mov	dx,3e8dh		; lea	di,
	call	AddOffset
	mov	ax,5716h		; push	ss	push	di
	Invoke	PutWord
	mov	[di].exLocation,elStack
	ret
CreateLocalVar	endp

SetBaseAndSize	proc	near
	mov	al,es:[bx].tdSizeOf.B0
	mov	cx,es:[bx].stBase.Offs
	mov	bx,es:[bx].stBase.Segm
	mov	es,es:[bx]
	mov	bx,cx
	mov	ah,es:[bx].itLowerBound.B0
	mov	cl,3
	shr	ah,cl
	ret
SetBaseAndSize	endp

PushSetAddr	proc	near
	call	SetBaseAndSize
PushWord	label	near
	test	CompilerOptions,co286Code
	jnz	PushWord286
	mov	dx,ax
	mov	al,lvAX
	call	LoadWord
	mov	al,50h			; push	ax
	Chain	PutByte
PushSetAddr	endp

PushWord286	proc	near
	mov	dx,ax
	cbw
	cmp	ax,dx
	jne	@@1
	mov	ah,al
	mov	al,6ah			; push
	Chain	PutWord
@@1:	mov	al,68h			; push
	Invoke	PutByte
	mov	ax,dx
	Chain	PutWord
PushWord286	endp

PushMemory	proc	near
	add	[di].exOffset,cx
	shr	cx,1
@@1:	sub	[di].exOffset,2
	mov	dx,30ffh		; push
	call	AddReg
	loop	@@1
	ret
PushMemory	endp

LoadReg	proc	near
	cmp	[di].exLocation,elMemory
	jne	@@2
	cmp	al,lvAX
	jne	@@3
	test	[di].exMisc,efBP+efDI
	jnz	@@3
	call	PutPrefix
	mov	al,0a1h			; mov	ax,
	test	[di].exModifier,emX
	jnz	@@1
	mov	al,0a0h			; mov	al,
@@1:	Invoke	PutByte
	jmp	PutOffset
@@2:	cmp	[di].exLocation,elRegister
	jne	@@4
	cmp	al,[di].exMisc
	jne	@@3
	ret
@@3:	mov	dl,8ah			; mov
	shl	al,1
	shl	al,1
	shl	al,1
	mov	dh,al
	jmp	PutRM
@@4:	cmp	[di].exLocation,elAddress
	jne	@@9
	test	[di].exMisc,efSeg
	jnz	@@7
	test	[di].exMisc,efBP
	jnz	@@6
	test	[di].exMisc,efDI
	jnz	@@5
	test	[di].exMisc,efDS+efCS+efConst
	jz	@@10
	or	al,0b8h			; mov
	Invoke	PutByte
	jmp	PutOffset
@@5:	test	[di].exMisc,efDS+efCS+efConst
	jnz	@@6
	cmp	[di].exOffset,0
	jne	@@6
	mov	dl,al
	mov	ax,0f889h		; mov	,di
	or	ah,dl
	Chain	PutWord
@@6:	mov	dl,8dh			; lea
	shl	al,1
	shl	al,1
	shl	al,1
	mov	dh,al
	jmp	AddReg
@@7:	test	[di].exMisc,efDS+efSS+efCS+efES
	jz	@@8
	mov	dl,al
	call	GetPrefix
	or	dl,al
	mov	ax,0c08ch		; mov	ax,
	or	ah,dl
	Chain	PutWord
@@8:	or	al,0b8h			; mov	ax,
	jmp	LoadSegment
@@9:	test	[di].exModifier,emX
	jnz	@@10
	or	al,0b0h			; mov	al,
	mov	ah,[di].exValue.B0
	Chain	PutWord
@@10:	mov	dx,[di].exValue.W0
LoadWord	label	near
	or	dx,dx
	jz	@@11
	or	al,0b8h			; mov	ax,
	Invoke	PutByte
	mov	ax,dx
	Chain	PutWord
@@11:	mov	ah,0c0h
	or	ah,al
	shl	al,1
	shl	al,1
	shl	al,1
	or	ah,al
	mov	al,31h			; xor
	Chain	PutWord
LoadReg	endp

StoreReg	proc	near
	cmp	al,lvAX
	jne	@@2
	test	[di].exMisc,efBP+efDI
	jnz	@@2
	call	PutPrefix
	mov	al,0a3h			; mov	,ax
	test	[di].exModifier,emX
	jnz	@@1
	mov	al,0a2h			; mov	,al
@@1:	Invoke	PutByte
	jmp	PutOffset
@@2:	mov	dl,88h			; mov
	shl	al,1
	shl	al,1
	shl	al,1
	mov	dh,al
	jmp	PutRM
StoreReg	endp

PutMovRMImm	proc	near
	mov	cx,ax
	mov	dx,0c6h			; mov
	call	PutRM
	mov	ax,cx
	test	[di].exModifier,emX
	jz	@@1
	Chain	PutWord
@@1:	Chain	PutByte
PutMovRMImm	endp

PutArOpAX	proc	near
	cmp	[di].exLocation,elImmediate
	jne	@@2
	mov	al,dl
	test	[di].exModifier,emX
	jz	@@1
	or	al,5
	Invoke	PutByte
	mov	ax,[di].exValue.W0
	Chain	PutWord
@@1:	or	al,4
	mov	ah,[di].exValue.B0
	Chain	PutWord
@@2:	or	dl,2
	xor	dh,dh
	jmp	PutRM
PutArOpAX	endp

PutArOp	proc	near
	cmp	[di].exLocation,elImmediate
	jne	@@1
	mov	ax,[di].exValue.W0
	or	dl,0c2h
	jmp	PutArOpImm
@@1:	or	dl,3
	mov	dh,10h
	jmp	AddReg
PutArOp	endp

PutLogOp	proc	near
	cmp	[di].exLocation,elImmediate
	jne	@@1
	or	dl,0c2h
	mov	ah,dl
	mov	al,81h
	Invoke	PutWord
	mov	ax,[di].exValue.W0
	Chain	PutWord
@@1:	or	dl,3
	mov	dh,10h
	jmp	AddReg
PutLogOp	endp

PutArOpImm	proc	near
	mov	cx,ax
	cbw
	cmp	ax,cx
	jne	@@1
	mov	ah,dl
	mov	al,83h
	Invoke	PutWord
	mov	al,cl
	Chain	PutByte
@@1:	mov	ah,dl
	mov	al,81h
	Invoke	PutWord
	mov	ax,cx
	Chain	PutWord
PutArOpImm	endp

PutArOpRMImm	proc	near
	mov	cx,ax
	mov	dh,dl
	mov	dl,80h
	test	[di].exModifier,emX
	jz	@@1
	mov	dl,83h
	cbw
	cmp	cx,ax
	je	@@1
	mov	dl,81h
	call	AddReg
	mov	ax,cx
	Chain	PutWord
@@1:	call	AddReg
	mov	al,cl
	Chain	PutByte
PutArOpRMImm	endp

FloatAddOffset	proc	near
	push	ax
	call	PutEmulInt
	pop	ax
	sub	dl,0a4h
AddOffset	label	near
	mov	cl,dh
	and	cl,7
	cmp	cl,6
	je	@@1
	or	ax,ax
	jnz	@@1
	mov	ax,dx
	Chain	PutWord
@@1:	mov	cx,ax
	cbw
	cmp	ax,cx
	jne	@@2
	or	dh,40h
	mov	ax,dx
	Invoke	PutWord
	mov	al,cl
	Chain	PutByte
@@2:	or	dh,80h
	mov	ax,dx
	Invoke	PutWord
	mov	ax,cx
	Chain	PutWord
FloatAddOffset	endp

PutFloatRM	proc	near
	test	[di].exMisc,efDS+efBP
	jz	@@1
	call	PutEmulInt
	sub	dl,0a4h
	jmp	short @@3
@@1:	call	GetSegment
	push	ax
	call	PutEmulInt
	mov	al,3ch
	Invoke	PutByte
	pop	ax
	shl	al,1
	shl	al,1
	shl	al,1
	xor	dl,al
	jmp	short @@3
PutRM	label	near
	test	[di].exModifier,emX
	jz	AddReg
	or	dl,1
AddReg	label	near
	cmp	[di].exLocation,elRegister
	jne	@@2
	or	dh,[di].exMisc
	or	dh,0c0h
	mov	ax,dx
	Chain	PutWord
@@2:	call	PutPrefix
@@3:	mov	al,[di].exMisc
	test	al,efBP
	jnz	@@4
	or	dh,6
	test	al,efDI
	jz	@@7
	xor	dh,3
	test	al,efDS+efCS+efConst
	jnz	@@6
	cmp	[di].exOffset,0
	jne	@@5
	mov	ax,dx
	Chain	PutWord
@@4:	or	dh,6
	test	al,efDI
	jz	@@5
	xor	dh,5
@@5:	mov	ax,[di].exOffset
	cbw
	cmp	ax,[di].exOffset
	jne	@@6
	or	dh,40h
	mov	ax,dx
	Invoke	PutWord
	mov	ax,[di].exOffset
	Chain	PutByte
@@6:	or	dh,80h
@@7:	mov	ax,dx
	Invoke	PutWord
PutOffset	label	near
	test	[di].exMisc,efDS+efCS+efConst
	jnz	@@8
	mov	ax,[di].exOffset
	Chain	PutWord
@@8:	push	cx
	mov	ax,[di].exSegment
	mov	bx,[di].exMap
	mov	dx,[di].exOffset
	test	[di].exMisc,efDS
	jnz	@@9
	mov	cx,ffCode+ffOffs
	test	[di].exMisc,efCS
	jnz	@@10
	mov	cx,ffProc+ffOffs
	jmp	short @@10
@@9:	mov	cx,ffConst+ffOffs
	test	[di].exMisc,efConst
	jnz	@@10
	mov	cx,ffData+ffOffs
@@10:	Invoke	PutFixup
	pop	cx
	ret
PutFloatRM	endp

PutPrefix	proc	near
	test	[di].exMisc,efDS+efBP
	jnz	@@1
	call	GetSegment
	or	al,26h
	Chain	PutByte
@@1:	ret
PutPrefix	endp

GetSegment	proc	near
	test	[di].exMisc,efDS+efSS+efCS+efES
	jnz	GetPrefix
	mov	al,0beh			; mov	si,
	call	LoadSegment
	mov	ax,0c68eh		; mov	,si
	Invoke	PutWord
	mov	al,0
	ret
GetSegment	endp

GetPrefix	proc	near
	mov	al,[di].exMisc
	mov	ah,18h
	test	al,efDS
	jnz	@@1
	mov	ah,10h
	test	al,efSS
	jnz	@@1
	mov	ah,08h
	test	al,efCS
	jnz	@@1
	mov	ah,0
@@1:	mov	al,ah
	ret
GetPrefix	endp

LoadSegment	proc	near
	Invoke	PutByte
	test	[di].exMisc,efConst
	jz	@@1
	push	cx dx
	mov	ax,[di].exSegment
	mov	bx,[di].exMap
	mov	cx,ffSegm
	xor	dx,dx
	Invoke	PutFixup
	pop	dx cx
	ret
@@1:	mov	ax,[di].exMap
	Chain	PutWord
LoadSegment	endp

	end
