Assembly Program for Display back the list of numbers sorted from largest to smallest.


 PAGE 58,132
;----------------------------------------------
; DISPLAY
;
; Purpose:
;    Display back the list of numbers sorted from    
;    largest to smallest.
;----------------------------------------------

; set title and instruction set
    TITLE    DESCEND - prototype    
    .MODEL    SMALL
    .286

; set up the stack
    .STACK

;---------------------------------------------- DATA segment
    .DATA
 DESCEND db 13,10,"The numbers sorted from largest to smallest are: "
 L_DESCEND equ $-DESCEND

 MESSAGE db 13,10,"Enter up to 10 positive decimal numbers : "
 L_MESSAGE equ $-MESSAGE

 INPUT db 30 dup(?)        ;Input
 L_INPUT equ $-INPUT

;---------------------------------------------- CODE segment
    .CODE

    PAGE
;----------------------------------------------
; MAIN (main program)
;
; Purpose:
;    to descend the order of 10 digits
;
; Input:
;    10 digits
;
; Output:
;    the message is displayed on the screen
;
; Procedures:
;    -- none --
;----------------------------------------------

; Procedure: MAIN
 MAIN    PROC    FAR

; start the main program
    .STARTUP

; display the message
    MOV    BX,0001H
    LEA    DX,MESSAGE
    MOV    CX,L_MESSAGE
    MOV    AH,40H
    INT    21H

; enter 10 digits
    MOV    BX,0000H
    LEA    DX,INPUT
    MOV    CX,L_INPUT
    MOV    AH,3FH
    INT     21H
   
; display the output
    MOV    BX,0001H
    LEA    DX,DESCEND
    MOV    CX,L_DESCEND
    MOV    AH,40H
    INT    21H

; procedures
;--------------------------------------
 MOV CX,L_INPUT
 MOV SI,0h

L1:     MOV DL,INPUT[SI]
        cmp DL,39H
      JNZ L2
   
    MOV DL,INPUT[SI]
     MOV AH,2
     INT 21H

    MOV DL,20H
    MOV AH,2
     INT 21H
   

L2:     INC SI
    LOOP L1

;--------------------------------------
 mov cx,L_INPUT
 mov si,0h

L3:     mov dl,INPUT[si]
        cmp dl,38h
      jnz L4
   
    mov dl,INPUT[si]
     mov ah,2
     int 21h

    mov dl,20h
    mov ah,2
     int 21h
   

L4:     inc si
    loop L3

;--------------------------------------
 mov cx,L_INPUT
 mov si,0h

L5:     mov dl,INPUT[si]
        cmp dl,37h
      jnz L6
   
    mov dl,INPUT[si]
     mov ah,2
     int 21h

    mov dl,20h
    mov ah,2
     int 21h
   

L6:     inc si
    loop L5

;--------------------------------------
 mov cx,L_INPUT
 mov si,0h

L7:     mov dl,INPUT[si]
        cmp dl,36h
      jnz L8
   
    mov dl,INPUT[si]
     mov ah,2
     int 21h

    mov dl,20h
    mov ah,2
     int 21h
   

L8:     inc si
    loop L7

;--------------------------------------
 mov cx,L_INPUT
 mov si,0h

L9:     mov dl,INPUT[si]
        cmp dl,35h
      jnz L10
   
    mov dl,INPUT[si]
     mov ah,2
     int 21h

    mov dl,20h
    mov ah,2
     int 21h
   

L10:     inc si
    loop L9

;--------------------------------------
 mov cx,L_INPUT
 mov si,0h

L11:     mov dl,INPUT[si]
        cmp dl,34h
      jnz L12
   
    mov dl,INPUT[si]
     mov ah,2
     int 21h

    mov dl,20h
    mov ah,2
     int 21h
   

L12:     inc si
    loop L11

;--------------------------------------
 mov cx,L_INPUT
 mov si,0h

L13:     mov dl,INPUT[si]
        cmp dl,33h
      jnz L14
   
    mov dl,INPUT[si]
     mov ah,2
     int 21h

    mov dl,20h
    mov ah,2
     int 21h
   

L14:     inc si
    loop L13

;--------------------------------------
 mov cx,L_INPUT
 mov si,0h

L15:     mov dl,INPUT[si]
        cmp dl,32h
      jnz L16
   
    mov dl,INPUT[si]
     mov ah,2
     int 21h

    mov dl,20h
    mov ah,2
     int 21h
   

L16:     inc si
    loop L15

;--------------------------------------
 mov cx,L_INPUT
 mov si,0h

L17:     mov dl,INPUT[si]
        cmp dl,31h
      jnz L18
   
    mov dl,INPUT[si]
     mov ah,2
     int 21h

    mov dl,20h
    mov ah,2
     int 21h
   

L18:     inc si
    loop L17

;--------------------------------------
 mov cx,L_INPUT
 mov si,0h

L19:     mov dl,INPUT[si]
        cmp dl,0
      jnz L20
   
    mov dl,INPUT[si]
     mov ah,2
     int 21h

    mov dl,20h
    mov ah,2
     int 21h
   

L20:     inc si
    loop L19




; return to DOS
    .EXIT

; End of Procedure: MAIN
    MAIN    ENDP



;---------------------------------------------- End of program
    END
Share:

No comments:

Post a Comment

Thanks for Suggestion / Comment!

God Bless!

Our Sponsor

Popular Post

Blog Archive