Thursday, January 21, 2010

8086 OR MASM PROGRAM TO Count and display the number of occurrances of (i) vowels (ii) a given word from a given string

assume ds:data1,cs:code1
data1 segment
msg db 0ah,0dh,'enter the word in small letters',0ah,'$'
msg1 db 0ah,0dh,'the number of vowels in the given string is=$'
msg2 db 0ah,0dh,'the number of occurance of the word in the given string is=$'
vowel db 'a','e','i','o','u'
enter db 'is is is$'
get db 20,0,20 dup('$')
data1 ends
code1 segment
start:mov ax,seg data1
mov ds,ax
lea dx,msg1
mov ah,09h
int 21h
lea bx,enter
mov si,bx
mov bl,00h
check:
lea dx,vowel
mov di,dx
mov dx,0005h
mov al,[si]
repeat1:cmp al,[di]
jz down
inc di
dec dl
jnz repeat1
jmp have
down:inc bl
have:inc si
mov dh,'$'
cmp [si],dh
jnz check
mov dl,bl
add dl,30h
mov ah,02h
int 21h

lea dx,msg
mov ah,09h
int 21h

lea dx,get
mov ah,0ah
int 21h

lea dx,msg2
mov ah,09h
int 21h

lea dx,enter
mov si,dx
mov dx,0000h
again:
lea bx,get+1
mov cl,[bx]
inc bx
mov di,bx
again1:
mov al,[si]
cmp al,[di]
jnz under
inc si
inc di
loop again1
mov bl,20h
cmp [si],bl;ASCII OF SPACE
jz found
mov bl,24h
cmp [si],bl;ASCII of $
jz found
under:inc si
mov bl,20h
cmp [si],bl
jz do
mov bl,24h
cmp [si],bl
jz over
jmp under
found:
inc dl
do:inc si
mov bl,24h
cmp [si],bl
jz over
jmp again
over:add dl,30h
mov ah,02h
int 21h
mov ah,4ch
int 21h
code1 ends

No comments:

Post a Comment