Thursday, 19 December 2013

Find Largest of an Array Element Assembly Language Program


PROGRAM
display macro msg
                lea dx,msg
                mov ah,09h
                int 21h
endm
read macro
                mov ah,01h
                int 21h
                sub al,30h
endm                   
stack segment stack
                db 10 dup(?)
stack ends
data segment
                msg1 db "Enter the limit: $"
                msg2 db 0ah,0dh,"Enter the numbers: $"
                msg3 db 0ah,0dh,"largest:$"
                msg4 db 0ah,0dh,"$"
                num db 10 dup("$")
data ends
code segment
                assume ss:stack,cs:code,ds:data
                start:     mov ax,data
                                mov ds,ax
                                display msg1
                                read
                                mov cl,al
                                mov si,00h
                                mov bl,al
                                display msg2
                label1:  display msg4
                                read
                                mov num[si],al
                                inc si
                                loop label1
                                mov di,00h
                                mov cl,bl
                                mov bl,00h
                label2:  cmp bl,num[di]
                                ja label3
                                mov bl,num[di]
                label3:  inc di
                                loop label2
                                display msg3
                                add bl,30h
                                mov dl,bl
                                mov ah,02h
                                int 21h
                stop:      mov ah,4ch
                                int 21h
code ends
end start
OUTPUT
Enter the limit: 6
Enter the numbers:
9
8
7
6
5
0
Largest: 9

No comments:

Post a Comment