;BUBBLE_1--G5_15

;**********************************************************
datarea segment			;define data segment
  a	dw	78,56,92,34,21,87,63,15,49,98
datarea ends
;**********************************************************
prognam segment			;define code segment
;----------------------------------------------------------
main	proc	far		;main part of program

	assume cs:prognam,ds:datarea

start:				;starting execution address

;set up stack for return
	push	ds		;save old data segment
	sub	ax,ax		;put zero in AX	
	push	ax		;save it on stack

;set DS register to current data segment
	mov	ax,datarea	;datarea segment addr
	mov	ds,ax	  	;  into DS register
  
;MAIN PART OF PROGRAM GOES HERE
	mov	cx,10		;set count1
	dec	cx		;  to n-1
loop1:	mov	di,cx		;save count1 in DI
	mov	bx,0		;clear	BX
loop2:	mov	ax,a[bx]	;load a(i) into AX and
	cmp	ax,a[bx+2]	;  compare with a(i+1)
	jge	cotinue		;swap if
	xchg	ax,a[bx+2]	;  a(i) < a(i+1) and
	mov	a[bx],ax	;store greater number	
cotinue:add	bx,2		;increment index
	loop	loop2		;if not the end of a pass,
				;repeat
	mov	cx,di		;restore count1
				;  for the either loop
	loop	loop1		;if not the final pass
				;repeat
	ret			;return to DOS

main	endp			;end of main part of program
;----------------------------------------------------------
prognam ends			;end of code segment
;**********************************************************

	end	start		;end assembly
