SẮP XẾP CHUỖI TĂNG DẦN THEO THUẬT TOÁN BUBBLE SORT


Mã:
.Model small
.stack
.Data
	s1 db 'Nhap vao 1 chuoi: $'
	s2 db 10,13,'Chuoi sap xep tang dan:',10,13,'$'
	s db 100,?,101 dup('$')
	n dw ?
.Code
Begin:
	Mov ax, @data
	Mov ds,ax

	Mov ah,09h		;xuat chuoi s1
	Lea dx,s1
	Int 21h
	
	Mov ah,0Ah		;nhap chuoi s
	Lea dx,s
	Int 21h
	
	xor cx,cx		;thuat toan Bubble Sort
	Lea si,s+1
	Mov cl,[si]
	inc si
	mov di,si
	add di,cx
	mov n,di
	dec cx
	L:	
		mov di,n
		mov bx,si
		inc bx
		L1:
			Mov dl,[di]
			cmp dl,[di-1]
			ja	L2
				Mov dh,[di-1]
				Mov [di-1],dl
				Mov [di],dh
			L2:	dec di
				cmp di,bx
				jne L1
			inc si
		Loop L
	
	Mov ah,09h		;xuat chuoi s2
	Lea dx,s2
	Int 21h
	
	Mov ah,09h		;xuat chuoi s
	Lea dx,s+2
	Int 21h
	
	Mov ah,4ch
	Int 21h
End Begin