Monday 6 February 2012

Count number of words in a sentence-Masm program


printmsg macro msg
mov ah,09h
lea dx,msg
int 21h
endm

printnum macro reg
mov dl,reg
add dl,30h
mov ah,02h
int 21h
endm

data segment

str db 40 dup(0)

cr equ 0dh
lf equ 0ah
msg1 db "Enter a string:$"
msg4 db 0ah,0dh,"$"
msg5 db 0ah,0dh,"No: of words$"
data ends

code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
lea si,str
mov cl,00

printmsg msg1
printmsg msg4
mov ch,'$'
mov [si],ch
l1:
mov ah,01h
int 21h
cmp al,32
je v1
jmp v2
v1:inc cl
jmp v2
v2:cmp al,cr
je p3
sub al,30h
mov [si],al
inc si
mov [si],ch
jmp l1

p3:
mov si,offset str
mov ch,[si]
cmp ch,'$'
je d1
inc cl
jmp d2
d1:mov cl,00



d2:printmsg msg4
printmsg msg5
printmsg msg4
printnum cl




mov ah,4ch
int 21h
code ends
end start



0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More