%OUT-------------------------------------------------------------
%OUT- Input: Array accepted from user
%out- Output: Max element & Min element
%out – author: Ayon and Ariyam
%OUT-------------------------------------------------------------
if1
include macrolib.lby ;contains common macros
endif
.model small
.stack
.data
array db 11 dup(?) ;array length to be specified in decimal
count dw 1 dup(?) ;array length
msg db " Enter No. ","$"
i_msg db "How many elements? ","$"
max_str db "Max element: ","$"
min_str db "Min element: ","$"
i_p db " Original array: ","$"
.code
main proc
mov ax,@data
mov ds,ax
showmsg i_msg
input
lea bx,count
mov [bx],al
input_array array,count,msg
showmsg i_p
mov cx,count
mov si,0000h
lp:
mov bh,array[si]
output
space
inc si
loop lp
;actual method starts
mov si,00h
mov cx,count
mov al,array[si]
mov dl,al ;dl will contain max
mov dh,al ;dh will contain min
lp1:
mov al,array[si] ;get the next array element
cmp al,dl
ja update_max
label1:
cmp al,dh
jb update_min
label2:
inc si
loop lp1
jmp label3
update_max: ;update previous max & min elements
mov dl,al
jmp label1
update_min:
mov dh,al
jmp label2
label3:
push dx
showmsg max_str ;displays the results
pop dx
mov bh,dl
push dx
output
space
showmsg min_str
pop dx
mov bh,dh
output
exit
main endp
end main
%OUT- Input: Array accepted from user
%out- Output: Max element & Min element
%out – author: Ayon and Ariyam
%OUT-------------------------------------------------------------
if1
include macrolib.lby ;contains common macros
endif
.model small
.stack
.data
array db 11 dup(?) ;array length to be specified in decimal
count dw 1 dup(?) ;array length
msg db " Enter No. ","$"
i_msg db "How many elements? ","$"
max_str db "Max element: ","$"
min_str db "Min element: ","$"
i_p db " Original array: ","$"
.code
main proc
mov ax,@data
mov ds,ax
showmsg i_msg
input
lea bx,count
mov [bx],al
input_array array,count,msg
showmsg i_p
mov cx,count
mov si,0000h
lp:
mov bh,array[si]
output
space
inc si
loop lp
;actual method starts
mov si,00h
mov cx,count
mov al,array[si]
mov dl,al ;dl will contain max
mov dh,al ;dh will contain min
lp1:
mov al,array[si] ;get the next array element
cmp al,dl
ja update_max
label1:
cmp al,dh
jb update_min
label2:
inc si
loop lp1
jmp label3
update_max: ;update previous max & min elements
mov dl,al
jmp label1
update_min:
mov dh,al
jmp label2
label3:
push dx
showmsg max_str ;displays the results
pop dx
mov bh,dl
push dx
output
space
showmsg min_str
pop dx
mov bh,dh
output
exit
main endp
end main
No comments:
Post a Comment
Do you think this information useful or was not up to the mark? Comment if you have any advices or suggestions about the post.