SE Comp Sem-II MIL Prac-6 (Array Sorting)

;sorting

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


input macro
   mov bl,0AH
   mov ah,01h
   int 21h
   sub al,30h
   mov ah,00h
   mul bl
   mov dl,al
  
   mov ah,01h
   int 21h
   sub al,30h
   add dl,al
endm

.model small
.stack
.data
    arr   db 10 dup(0)
    count db 00h
    msg0  db 10,13,'------MENU------$'
    msg1  db 10,13,'1.INPUT $'
    msg2  db 10,13,'2.ASCENDING $'
    msg3  db 10,13,'3.DESCENDING $'
    msg4  db 10,13,'4.EXIT $'
    msg5  db 10,13,'ENTER HOW MANY NUMBERS: $'
    msgn  db 10,13,'$'
    msg6  db 10,13,'no: $'
    msg7  db 10,13,'ASCENDING SEQUENCE :$'

.code
      main proc
         mov ax,@data
         mov ds,ax

m:       disp msg0
         disp msg1
         disp msg2
         disp msg3
         disp msg4

         disp msgn
         mov ah,01h         ;enter choice
         int 21h

         cmp al,'1'
         je inp
         cmp al,'2'
         je asc
;         cmp al,'3'
;         je des
         cmp al,'4'
         je ex

ex:      mov ax,4c00h
         int 21h

inp:     disp msg5           ;how many numbers
         mov ah,01h
         int 21h
         sub al,30h
         mov cl,al
         mov count,cl

         lea si,arr
  ip:    disp msg6            ;no
         input
         mov [si],dl
         inc si
         dec cl
         jnz ip
         jmp m

asc:     disp msg7              ;sorting ( ascending )
         mov cl,count
         dec cl
        
   a:    mov ch,count
         dec ch
         lea bx,arr

   a1:   mov al,[bx]
         inc bx
         mov dl,[bx]
         cmp al,dl
         jle a2
         mov [bx],al
         dec bx
         mov [bx],dl
         inc bx

  a2:    dec ch               ;inner loop
         jnz a1

         dec cl               ;outer loop
         jnz a

          mov cl,count
          lea si,arr
 h:
          disp msgn
          mov ax,[si]
          mov ah,00h
          call hex
          inc si
          dec cl
          jnz h
        jmp m

endp main

;hex to deci conv
hex proc near
push cx
          mov cx,0000h
          mov bx,000AH
    d1:
          mov dx,0000h
          div bx
          push dx
          inc cx
          cmp ax,00h
          jnz d1
    d2:
          pop dx
          add dl,30h
          mov ah,02h
          int 21h
          dec cx
          jnz d2
pop cx

ret
endp

end

No comments:

Post a Comment