ALP for sorting element in ascending order

print macro msg
mov ah,09h
lea dx,msg
int 21h
endm

data segment
msg1 db 10,13,'Enter No. of elements: $'
msg2 db 10,13,'Enter Array$'
msg_e db 10,13,'Element: $'
msg_r db 10,13,'Sorted Array: $'
n db 5 dup(?)
i db 0
j db 0
c db 0
t db 0
data ends

code segment
assume cs:code, ds:data
start:
mov ax,data
mov ds,ax

print msg1
mov ah,01h
int 21h
sub al,48
mov c,al

print msg2
lea si,n

mov al,c
mov t,al

loop1:
print msg_e
call input
mov [si],dl

inc si
dec t
jnz loop1


mov al,c
mov i,al

mov j,al
sub j,1

lea si,n

loop3:
mov al,[si]
mov bl,[si+1]
cmp al,bl
jl loop2
mov [si],bl
mov [si+1],al

loop2:
inc si
dec j
jnz loop3

mov al,c
mov j,al
sub j,1
lea si,n
dec i
jnz loop3

mov al,c
mov t,al

lea si,n
print msg_r
loop4:

print msg_e
mov ax,0
mov al,[si]
call disp
inc si
dec t
jnz loop4

mov ax,4c00h
int 21h

input proc
mov cx,10
mov dx,0
mov bx,0

loop_b:
mov bh,0
mov ah,01h
int 21h
cmp al,13
je loop_e
mov bl,al
sub bl,48
mov ax,dx
mul cx
mov dx,ax
add dx,bx
jmp loop_b
loop_e:
ret
endp

disp proc
mov bx,10
mov cx,1

loop_11:

mov dx,0
div bx
add dx,48
push dx
inc cx
cmp ax,10
jge loop_11
add ax,48
push ax
mov ah,02h

loop_111:
pop dx
int 21h
loop loop_111
ret
endp


code ends
end start
Previous
Next Post »