0 Replies - 1897 Views - Last Post: 11 August 2010 - 05:51 AM

#1 polens   User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 155
  • Joined: 09-November 09

Count how many words and character in a string

Posted 11 August 2010 - 05:51 AM

hello there!!!
can you guys check whats wrong with my code...
the output must be:
String entered: The quick brown fox jump over the lazy dog
number of words:9
number of characters:36

my output is: a smile and some characters :whistling:
i cant really understand this language yet..
How to count the words and characters in a string?


.model small

	str1 db "Enter a sentence>>","$"
	str2 db 0AH,0Dh,"Number of words>>","$"
	str3 db 0AH,0Dh,"Number of letters>>","$"
	var1 db ?,"$"
	var2 db ?,"$"


	mov ax,@data
	mov ds,ax

	mov ah,9
	lea dx,str1
	int 21h

startloop:		;loop for .

	mov ah,01h
	int 21h

	cmp al,"."	;compare .
	je jump1	;jump1

	cmp al,20h	;compare space
	add var2,1
	je jump2	;jump2

loop startloop		;loop for .

jump1:			;jump1

	mov ah,9
	lea dx,str2
	int 21h

	add var1,1

	mov ah,9
	lea dx,var1
	int 21h


jump2:			;jump2

	mov ah,9
	lea dx,var1
	int 21h
	mov ah,9
	lea dx,str3
	int 21h

	mov var2,ch
	mov ah,9
	lea dx,var2
	int 21h

	mov dl,bl
	add dl,01h
	mov ah,2
	int 21h

jmp exit

	mov ah,4ch
	int 21h


Is This A Good Question/Topic? 0
  • +

Page 1 of 1