i am writing a assembly code to count the number of words in a sentence.
below is my coding:
.model small
.stack 200h
.386
.data
message1 db 10,13, 'Word counter : Enter the sentence to be calculated$'
result db 10,13, 'Number of words : $'
counter db 5,6 dup(0)
sentence db 10,13, 'hello world and me. $'
.code
Start:
mov ax,seg message1
mov ds,ax
mov dx,offset message1
mov ah,09h
int 21h
mov ax,seg sentence
mov ds,ax
mov bx,offset sentence
mov ax,0
mov cx,0
mov di,2
check1:
mov al,[bx+di]
cmp al,'.'
je check2
cmp al,','
je check2
cmp al,' '
je count
cmp al,'$'
je done
jmp skip
check2:
inc cx
inc di
mov al,[bx+di]
cmp al,' '
je skip
jmp check1
skip:
inc di
jmp check1
count:
inc cx
inc di
jmp check1
done:
mov ax,cx
aaa
add ax,3030h
cmp ah,30h
je singleNumber
jmp doubleNumber
singleNumber:
mov bx,offset counter
mov [bx+2],al
mov al,'$'
mov [bx+3],al
jmp print
doubleNumber:
mov bx,offset counter
mov [bx+2],ah
mov [bx+3],al
mov al,'$'
mov [bx+4],al
print:
mov dx,offset result
mov ah,09h
int 21h
mov dx,offset counter
mov ah,09h
int 21h
.exit
end start
when i run it, there is a ascii symbol infront of the number of word.
isit something wrong with my coding?
please help.
thank you