Thursday, February 10, 2011

Comparing in array


%OUT---------------------------------------------------------------------------
%OUT- Determines how many values are more than 20 & less than 40 in an array
%out- output: No. of values in each case
%out – author: Ayon and Ariyam
%OUT---------------------------------------------------------------------------

if1
include macrolib.lby ;contains common macros
endif

.model small
.stack
.data
array db 11 dup(?) ;array length in decimal,can store 1 less
count dw 1 dup(?) ;array length
msg db " Enter No. ","$"
i_msg db "How many elements? ","$"
lbound equ 14h ;14H=>20D
ubound equ 28h ;28H=>40D
less db "No. of values less than 20: ","$"
more db "No. of values more than 40: ","$"
i_p db " Original Array: ","$"

.code

main proc

mov ax,@data
mov ds,ax ;initialize the data segment
showmsg i_msg
input
lea bx,count
mov [bx],al
input_array array,count,msg
showmsg i_p
mov cx,count
mov si,0000h
lp1:
mov bh,array[si]
output
space
inc si
loop lp1
mov cx,count
mov si,00h
mov bx,0000h ;counter for storing values
mov dl,lbound
mov dh,ubound

lp: mov al,array[si]
cmp al,dl
jb update_l

up: cmp al,dh
ja update_u

xx: inc si
loop lp
push bx
showmsg less
mov bh,bl
output
space
showmsg more
pop bx
output
exit

update_l: ;updates the counters
inc bl
jmp xx

update_u:
inc bh
jmp xx

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.