	.386p
	ifndef	??version
?debug	macro
	endm
publicdll macro	name
	public	name
	endm
	endif
	?debug	V 300h
	?debug	S "HEAP.CPP"
	?debug	C E988B2F11C08484541502E435050
HEAP_TEXT	segment byte public use16 'CODE'
HEAP_TEXT	ends
DGROUP	group	_DATA,_BSS
	assume	cs:HEAP_TEXT,ds:DGROUP
_DATA	segment word public use16 'DATA'
d@	label	byte
d@w	label	word
_DATA	ends
_BSS	segment word public use16 'BSS'
b@	label	byte
b@w	label	word
_BSS	ends
HEAP_TEXT	segment byte public use16 'CODE'
	?debug	C E80108484541502E43505088B2F11C
   ;	
   ;	void Heap::put(int e) {
   ;	
	?debug	L 18
	assume	cs:HEAP_TEXT
@Heap@put$qi	proc	far
	?debug	B
	push	bp
	mov	bp,sp
	?debug	C F80C404865617040707574247169
	?debug	C E318000400161900
	?debug	C E60165040A0A000004746869731802060000
	?debug	B
	cmp	word ptr __stklen,sp
	ja	short @1@86
	call	far ptr F_OVERFLOW@
@1@86:
   ;	
   ;		elems++;
   ;	
	?debug	L 19
	les	bx,dword ptr [bp+6]
	inc	word ptr es:[bx+400]
   ;	
   ;		h[elems]=e;
   ;	
	?debug	L 20
	mov	ax,word ptr es:[bx+400]
	shl	ax,1
	add	bx,ax
	mov	ax,word ptr [bp+10]
	mov	word ptr es:[bx],ax
   ;	
   ;		up(elems);
   ;	
	?debug	L 21
	mov	bx,word ptr [bp+6]
	push	word ptr es:[bx+400]
	push	word ptr [bp+8]
	push	bx
	call	far ptr @Heap@up$qui
	add	sp,6
   ;	
   ;	}
   ;	
	?debug	L 22
	pop	bp
	ret	
	?debug	C E6047468697318020600000165040A0A0000
	?debug	E
	?debug	E
@Heap@put$qi	endp
   ;	
   ;	int Heap::getmin() {
   ;	
	?debug	L 24
	assume	cs:HEAP_TEXT
@Heap@getmin$qv	proc	far
	?debug	B
	push	bp
	mov	bp,sp
	sub	sp,2
	?debug	C F80F4048656170406765746D696E247176
	?debug	C E604746869731802060000
	?debug	B
	cmp	word ptr __stklen,sp
	ja	short @2@86
	call	far ptr F_OVERFLOW@
@2@86:
   ;	
   ;		int m=h[1];
   ;	
	?debug	L 25
	les	bx,dword ptr [bp+6]
	mov	ax,word ptr es:[bx+2]
	mov	word ptr [bp-2],ax
   ;	
   ;		if(elems>1) {
   ;	
	?debug	L 26
	cmp	word ptr es:[bx+400],1
	jbe	short @2@142
   ;	
   ;			h[1]=h[elems];
   ;	
	?debug	L 27
	mov	ax,word ptr es:[bx+400]
	shl	ax,1
	add	bx,ax
	mov	ax,word ptr es:[bx]
	mov	bx,word ptr [bp+6]
	mov	word ptr es:[bx+2],ax
   ;	
   ;			elems--;
   ;	
	?debug	L 28
	dec	word ptr es:[bx+400]
   ;	
   ;			down(1);
   ;	
	?debug	L 29
	push	1
	push	word ptr [bp+8]
	push	bx
	call	far ptr @Heap@down$qui
	add	sp,6
@2@142:
   ;	
   ;		}
   ;		return m;
   ;	
	?debug	L 31
	mov	ax,word ptr [bp-2]
   ;	
   ;	}
   ;	
	?debug	L 32
	leave	
	ret	
	?debug	C E6016D0402FEFF0004746869731802060000
	?debug	E
	?debug	E
@Heap@getmin$qv	endp
   ;	
   ;	void Heap::up(unsigned _c) {
   ;	
	?debug	L 36
	assume	cs:HEAP_TEXT
@Heap@up$qui	proc	far
	?debug	B
	push	bp
	mov	bp,sp
	sub	sp,2
	push	si
	push	di
	?debug	C F80C404865617040757024717569
	?debug	C E6025F630A0A0A000004746869731802060000
	?debug	B
	cmp	word ptr __stklen,sp
	ja	short @3@86
	call	far ptr F_OVERFLOW@
@3@86:
   ;	
   ;		unsigned c=_c;
   ;	
	?debug	L 37
	mov	cx,word ptr [bp+10]
	jmp	short @3@142
@3@114:
   ;	
   ;		unsigned p;
   ;		while((p=parent(c))!=0 && h[p]>h[c]) {
   ;			swab(c,p);
   ;	
	?debug	L 40
	mov	di,si
	mov	ax,cx
	shl	ax,1
	les	bx,dword ptr [bp+6]
	add	bx,ax
	mov	ax,word ptr es:[bx]
	mov	word ptr [bp-2],ax
	mov	ax,si
	shl	ax,1
	mov	bx,word ptr [bp+6]
	add	bx,ax
	mov	ax,word ptr es:[bx]
	mov	dx,cx
	shl	dx,1
	mov	bx,word ptr [bp+6]
	add	bx,dx
	mov	word ptr es:[bx],ax
	mov	ax,di
	shl	ax,1
	mov	bx,word ptr [bp+6]
	add	bx,ax
	mov	ax,word ptr [bp-2]
	mov	word ptr es:[bx],ax
   ;	
   ;			c=p;
   ;	
	?debug	L 41
	mov	cx,si
@3@142:
	?debug	L 39
	mov	si,cx
	shr	si,1
	mov	ax,si
	or	ax,ax
	je	short @3@198
	mov	ax,si
	shl	ax,1
	les	bx,dword ptr [bp+6]
	add	bx,ax
	mov	ax,word ptr es:[bx]
	mov	dx,cx
	shl	dx,1
	mov	bx,word ptr [bp+6]
	add	bx,dx
	cmp	ax,word ptr es:[bx]
	jg	short @3@114
@3@198:
   ;	
   ;		}
   ;	}
   ;	
	?debug	L 43
	pop	di
	pop	si
	leave	
	ret	
	?debug	C E601700A08011E006F0004060001630A08011900+
	?debug	C 7D0004010004746869731802060000025F630A0A+
	?debug	C 0A0000
	?debug	E
	?debug	E
@Heap@up$qui	endp
   ;	
   ;	void Heap::down(unsigned p) {
   ;	
	?debug	L 46
	assume	cs:HEAP_TEXT
@Heap@down$qui	proc	far
	?debug	B
	push	bp
	mov	bp,sp
	sub	sp,8
	push	si
	push	di
	?debug	C F80E404865617040646F776E24717569
	?debug	C E601700A0A0A000004746869731802060000
	mov	cx,word ptr [bp+10]
	?debug	B
	cmp	word ptr __stklen,sp
	ja	short @4@86
	call	far ptr F_OVERFLOW@
@4@86:
   ;	
   ;		//shadow variable to help the compiler optimizing
   ;		unsigned fastelems=elems;
   ;	
	?debug	L 48
	les	bx,dword ptr [bp+6]
	mov	ax,word ptr es:[bx+400]
	mov	word ptr [bp-2],ax
	jmp	@4@338
@4@114:
	?debug	B
   ;	
   ;		unsigned l;
   ;		while((l=leftchild(p))<=fastelems) {
   ;			unsigned r=rightchild(p);
   ;	
	?debug	L 51
	mov	di,cx
	shl	di,1
	inc	di
   ;	
   ;	
   ;			if(r>fastelems) {
   ;	
	?debug	L 53
	cmp	di,word ptr [bp-2]
	jbe	short @4@198
   ;	
   ;				//r does not exist
   ;				if(h[p]>h[l]) {
   ;	
	?debug	L 55
	mov	ax,cx
	shl	ax,1
	les	bx,dword ptr [bp+6]
	add	bx,ax
	mov	ax,word ptr es:[bx]
	mov	dx,si
	shl	dx,1
	mov	bx,word ptr [bp+6]
	add	bx,dx
	cmp	ax,word ptr es:[bx]
	jg short	@@10
	jmp	@4@366
@@10:
   ;	
   ;					swab(p,l);
   ;	
	?debug	L 56
	mov	di,si
	mov	ax,cx
	shl	ax,1
	mov	bx,word ptr [bp+6]
	add	bx,ax
	mov	ax,word ptr es:[bx]
	mov	word ptr [bp-4],ax
	mov	ax,si
	shl	ax,1
	mov	bx,word ptr [bp+6]
	add	bx,ax
	mov	ax,word ptr es:[bx]
	mov	dx,cx
	shl	dx,1
	mov	bx,word ptr [bp+6]
	add	bx,dx
	mov	word ptr es:[bx],ax
	mov	ax,di
	shl	ax,1
	mov	bx,word ptr [bp+6]
	add	bx,ax
	mov	ax,word ptr [bp-4]
	mov	word ptr es:[bx],ax
   ;	
   ;					p=l;
   ;	
	?debug	L 57
	mov	cx,si
   ;	
   ;				} else
   ;	
	?debug	L 58
	jmp	@4@338
@4@198:
   ;	
   ;					break;
   ;			} else {
   ;				//both l and r exist
   ;				if(h[l]<h[r]) {
   ;	
	?debug	L 62
	mov	ax,si
	shl	ax,1
	les	bx,dword ptr [bp+6]
	add	bx,ax
	mov	ax,word ptr es:[bx]
	mov	dx,di
	shl	dx,1
	mov	bx,word ptr [bp+6]
	add	bx,dx
	cmp	ax,word ptr es:[bx]
	jge	short @4@282
   ;	
   ;					if(h[p]>h[l]) {
   ;	
	?debug	L 63
	mov	ax,cx
	shl	ax,1
	mov	bx,word ptr [bp+6]
	add	bx,ax
	mov	ax,word ptr es:[bx]
	mov	dx,si
	shl	dx,1
	mov	bx,word ptr [bp+6]
	add	bx,dx
	cmp	ax,word ptr es:[bx]
	jg short	@@11
	jmp	@4@366
@@11:
   ;	
   ;						swab(p,l);
   ;	
	?debug	L 64
	mov	di,si
	mov	ax,cx
	shl	ax,1
	mov	bx,word ptr [bp+6]
	add	bx,ax
	mov	ax,word ptr es:[bx]
	mov	word ptr [bp-6],ax
	mov	ax,si
	shl	ax,1
	mov	bx,word ptr [bp+6]
	add	bx,ax
	mov	ax,word ptr es:[bx]
	mov	dx,cx
	shl	dx,1
	mov	bx,word ptr [bp+6]
	add	bx,dx
	mov	word ptr es:[bx],ax
	mov	ax,di
	shl	ax,1
	mov	bx,word ptr [bp+6]
	add	bx,ax
	mov	ax,word ptr [bp-6]
	mov	word ptr es:[bx],ax
   ;	
   ;						p=l;
   ;	
	?debug	L 65
	mov	cx,si
   ;	
   ;					} else
   ;	
	?debug	L 66
	jmp	short @4@338
@4@282:
   ;	
   ;						break;
   ;				} else {
   ;					if(h[p]>h[r]) {
   ;	
	?debug	L 69
	mov	ax,cx
	shl	ax,1
	les	bx,dword ptr [bp+6]
	add	bx,ax
	mov	ax,word ptr es:[bx]
	mov	dx,di
	shl	dx,1
	mov	bx,word ptr [bp+6]
	add	bx,dx
	cmp	ax,word ptr es:[bx]
	jle	short @4@366
   ;	
   ;						swab(p,r);
   ;	
	?debug	L 70
	mov	si,di
	mov	ax,cx
	shl	ax,1
	mov	bx,word ptr [bp+6]
	add	bx,ax
	mov	ax,word ptr es:[bx]
	mov	word ptr [bp-8],ax
	mov	ax,di
	shl	ax,1
	mov	bx,word ptr [bp+6]
	add	bx,ax
	mov	ax,word ptr es:[bx]
	mov	dx,cx
	shl	dx,1
	mov	bx,word ptr [bp+6]
	add	bx,dx
	mov	word ptr es:[bx],ax
	mov	ax,si
	shl	ax,1
	mov	bx,word ptr [bp+6]
	add	bx,ax
	mov	ax,word ptr [bp-8]
	mov	word ptr es:[bx],ax
   ;	
   ;						p=r;
   ;	
	?debug	L 71
	mov	cx,di
   ;	
   ;					} else
   ;	
	?debug	L 72
@4@338:
	?debug	C E601720A08012E007901040700
	?debug	E
	?debug	L 50
	mov	si,cx
	shl	si,1
	mov	ax,si
	cmp	ax,word ptr [bp-2]
	ja short	@@12
	jmp	@4@114
@@12:
@4@366:
   ;	
   ;						break;
   ;				}
   ;			}
   ;		}
   ;	}
   ;	
	?debug	L 77
	pop	di
	pop	si
	leave	
	ret	
	?debug	C E6016C0A0801490081010406000966617374656C+
	?debug	C 656D730A02FEFF00047468697318020600000170+
	?debug	C 0A08010B007F010C0100
	?debug	E
	?debug	E
@Heap@down$qui	endp
	?debug	C E94019CA1817453A5C424333315C494E434C5544455C535444494F+
	?debug	C 2E48
	?debug	C E94019CA1817453A5C424333315C494E434C5544455C5F44454653+
	?debug	C 2E48
	?debug	C E94019CA1818453A5C424333315C494E434C5544455C5F4E46494C+
	?debug	C 452E48
	?debug	C E94019CA1817453A5C424333315C494E434C5544455C5F4E554C4C+
	?debug	C 2E48
	?debug	C E94019CA1818453A5C424333315C494E434C5544455C5354444C49+
	?debug	C 422E48
	?debug	C E801
   ;	
   ;	void main(void) {
   ;	
	?debug	L 114
	assume	cs:HEAP_TEXT
_main	proc	far
	?debug	B
	push	bp
	mov	bp,sp
	sub	sp,402
	push	si
	?debug	B
	cmp	word ptr __stklen,sp
	ja	short @5@86
	call	far ptr F_OVERFLOW@
@5@86:
   ;	
   ;		Heap h;
   ;	
	?debug	L 115
	mov	word ptr [bp-2],0
   ;	
   ;		int i;
   ;	
   ;		for(i=0; i<100; i++) {
   ;	
	?debug	L 118
	xor	si,si
@5@114:
	?debug	B
   ;	
   ;			int e=random(200);
   ;	
	?debug	L 119
	call	far ptr _rand
	movsx	eax,ax
	imul	eax,large 200
	mov	ebx,large 000008000h
	cdq	
	idiv	ebx
	mov	dx,ax
   ;	
   ;			h.put(e);
   ;	
	?debug	L 120
	push	ax
	push	ss
	lea	ax,word ptr [bp-402]
	push	ax
	push	cs
	call	near ptr @Heap@put$qi
	add	sp,6
	?debug	C E601650408013B000000040200
	?debug	E
	?debug	L 118
	inc	si
	cmp	si,100
	jl	short @5@114
   ;	
   ;		}
   ;	
   ;		for(i=0; i<100; i++)
   ;	
	?debug	L 123
	xor	si,si
@5@226:
   ;	
   ;			h.getmin();
   ;	
	?debug	L 124
	push	ss
	lea	ax,word ptr [bp-402]
	push	ax
	push	cs
	call	near ptr @Heap@getmin$qv
	add	sp,4
	?debug	L 123
	inc	si
	cmp	si,100
	jl	short @5@226
   ;	
   ;	}
   ;	
	?debug	L 125
	pop	si
	leave	
	ret	
	?debug	C E601690408011D006700040600016819026EFE00
	?debug	E
	?debug	E
_main	endp
	?debug	C E9
	?debug	C FA10030000
HEAP_TEXT	ends
_DATA	segment word public use16 'DATA'
s@	label	byte
_DATA	ends
HEAP_TEXT	segment byte public use16 'CODE'
HEAP_TEXT	ends
	?debug	C E319044865617092012E01
	?debug	C ED00010000010C00
	?debug	C E31A0090011A04
	?debug	C E31B0000002D1804091900
	?debug	C E31D0000002D01040119000C4048656170407075+
	?debug	C 74247169
	?debug	C E31F0000002D04040119000F4048656170406765+
	?debug	C 746D696E247176
	?debug	C E3210000002D01040119000C4048656170407570+
	?debug	C 24717569
	?debug	C E3230000002D01040119000E404865617040646F+
	?debug	C 776E24717569
	?debug	C E3250000002D0104091900
	?debug	C E3270000002D0A04091900
	?debug	C E3290000002D0A04091900
	?debug	C E32B0000002D0A04091900
	public	_main
	extrn	_rand:far
_atoi	equ	atoi
_abs	equ	abs
	extrn	F_OVERFLOW@:far
	extrn	__stklen:word
	public	@Heap@down$qui
	public	@Heap@up$qui
	public	@Heap@getmin$qv
	public	@Heap@put$qi
_s@	equ	s@
	?debug	C EA050C
	?debug	C E32D00000023010400
	?debug	C EC055F6D61696E2D1800
	?debug	C E32E00000023010400
	?debug	C E32F00000023040400
	?debug	C E33000000023040400
	?debug	C EB055F72616E643000
	?debug	C E33100000023040400
	?debug	C E33200000023040400
	?debug	C E33300000023040500
	?debug	C EB0B465F4F564552464C4F57403300
	?debug	C EB085F5F73746B6C656E0A00
	?debug	C E60777636861725F740806000666706F735F7406+
	?debug	C 06000673697A655F740A06000448656170190700
	?debug	F @randomize$qv 46 24 0
	?debug	F @random$qi 47 24 0
	?debug	F atoi 49 24 0
	?debug	F abs 50 24 0
	?debug	C E20001681A0005656C656D730A4A0E4048656170+
	?debug	C 4024626374722471761B480C4048656170407075+
	?debug	C 742471691D480F4048656170406765746D696E24+
	?debug	C 71761F480C40486561704075702471756921480E+
	?debug	C 404865617040646F776E24717569234810404865+
	?debug	C 6170407377616224717569756925481040486561+
	?debug	C 7040706172656E74247175692748134048656170+
	?debug	C 406C6566746368696C6424717569294814404865+
	?debug	C 61704072696768746368696C64247175692BC092+
	?debug	C 010000
	end
