User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Assembly section within the Software Development category of DaniWeb, a massive community of 422,829 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,348 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Assembly advertiser: Programming Forums
Views: 3846 | Replies: 12 | Solved
Reply
Join Date: Dec 2006
Posts: 10
Reputation: Rooro is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Rooro Rooro is offline Offline
Newbie Poster

display the number of capitals letters in the sentence

  #1  
Dec 12th, 2006
Hello everyone : )

i'm working on :



Write a program that takes an input sentence from the user and on next line display the number of capitals letters in the sentence.

Note:
ยท User is not allowed to enter a sentence with more than 9 Capital letters.



what i did is :




 .MODEL SMALL
.STACK 100H
.DATA
 
MSG1 DB 'PLEASE ENTER YOUR SENTENCE:  $'
 
MSG2 DB 0DH,0AH,'THE NUMBER OF CAPITAL LETTERS IN SENTENCE :$'
 
MSG3 DB 0DH,0AH,'You have entered more than 9 capital liter $'
 
 
.CODE
 
MAIN PROC
 
 
MOV AX,@DATA ;initialize DS
MOV DS,AX
 
 
;DISPLAY MSG1
 
LEA DX,MSG1  ;GET MSG1
MOV AH,9  ;DISPLAY STRING
INT 21H  ;DISPLAY MSG1
 
 
;READ  CHARCHTER
 
;if the user has entered more than 9 capital liter exit ...
 
MOV bx,0
mov cx,9
 
MOV AH,1  ;READ sentenc
 
 
 
 
TOP:
 
INT 21h
 
Mov bl,al
 
cmp bl,'A'
 
JGE Count
 
CMP bl,'Z'
JLE Count
 
 
Count:
 
INC bx
LOOP TOP
 
 
LEA DX,MSG2  ;GET MSG2
MOV AH,9  ;DISPLAY STRING
INT 21H  ;DISPLAY MSG1
 
mov ah,2
mov DX,BX
INT 21H
 
 
 
MOV AH,4CH ; return control to DOS
INT 21H
 
MAIN ENDP
 
 END MAIN
 
END

My problem is on counting the number of capital letters .

Can anyone help please ?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,116
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 38
Solved Threads: 929
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Most Valuable Poster

Re: display the number of capitals letters in the sentence

  #2  
Dec 12th, 2006
That loop needs to check for al = 13H ( <Enter> key) to stop the loop. As coded now the loop will never stop.

>> Mov bl,al
Why do that? just use al for tests


cmp bl,'A'
 
JGE Count
 
CMP bl,'Z'
JLE Count
 
I think you have the comparisons backwards. If the character < 'A' or > 'Z' then it is not a capital letter.

cmp al,'A'
 
JL Count
 
CMP al,'Z'
JG Count
 

>>My problem is on counting the number of capital letters .
You have to select a register to do the counting. cx is normally used for that purpose, but bx and dx will do as well. Just initialize it to zero before the loop and increment it after the checks

xor cx,cx ; clear the register
TOP:
 
INT 21h
 
cmp al,'A'
JL Count
CMP al,'Z'
JG Count
inc cx ; count number of capital letters

Count:
LOOP TOP
Last edited by Ancient Dragon : Dec 12th, 2006 at 11:40 am.
I think it's about time we voted for senators with breasts. After all, we've been voting for boobs long enough. ~Clarie Sargent, Arizona senatorial candidate
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
Reply With Quote  
Join Date: Dec 2006
Posts: 10
Reputation: Rooro is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Rooro Rooro is offline Offline
Newbie Poster

Re: display the number of capitals letters in the sentence

  #3  
Dec 12th, 2006
Thanks a lot Ancient Dragon


.MODEL SMALL
.STACK 100H
.DATA
MSG1 DB 'PLEASE ENTER YOUR SENTENCE: $'
MSG2 DB 0DH,0AH,'THE NUMBER OF CAPITAL LETTERS IN
SENTENCE '
MSG3 DB 0DH,0AH,'You have entered more than 9 capital
LETTERS $'

.CODE
MAIN PROC

MOV AX,@DATA ;initialize DS
MOV DS,AX

;DISPLAY MSG1
LEA DX,MSG1 ;GET MSG1
MOV AH,9 ;DISPLAY STRING
INT 21H ;DISPLAY MSG1

;READ CHARCHTER

TOP:

INT 21h

cmp al,'A'
JL Count
CMP al,'Z'
JG Count
inc cx ; count number of capital letters
Count:
LOOP TOP
LEA DX,MSG2 ;GET MSG2
MOV AH,9 ;DISPLAY STRING
INT 21H ;DISPLAY MSG1
mov ah,2
mov DX,CX
INT 21H

MOV AH,4CH ; return control to DOS
INT 21H
MAIN ENDP
END MAIN
END




i did another code , but still having problem which is when i want to read a sentenc from the user the program takes only one character !


.MODEL SMALL
.STACK 100H
.DATA

MSG1 DB 'PLEASE ENTER YOUR SENTENCE:  $'

MSG2 DB 0DH,0AH,'THE NUMBER OF CAPITAL LETTERS IN 

SENTENCE :$'

MSG3 DB 0DH,0AH,'You have entered more than 9 capital 

LETTERS $'


.CODE

MAIN PROC


MOV AX,@DATA ;initialize DS
MOV DS,AX

mov bX,0
;DISPLAY MSG1

LEA DX,MSG1 ;GET MSG1
MOV AH,9 ;DISPLAY STRING
INT 21H ;DISPLAY MSG1


MOV AH,1 ;READ sentenc

TOP:
INT 21h


WHILE_:


cmp al,0dh

je END_WHILE


cmp al,'A'
CMP al,'Z'
JMP Count

LOOP TOP

Count:

INC bx

cmp bx,9
JLE Display1
JG Display2



END_WHILE:


Display1:

LEA DX,MSG2 ;GET MSG1
MOV AH,9 ;DISPLAY STRING
INT 21H ;DISPLAY MSG1

mov ah,2
mov DX,BX
INT 21H


Display2:

LEA DX,MSG3 ;GET MSG1
MOV AH,9 ;DISPLAY STRING
INT 21H ;DISPLAY MSG1


MOV AH,4CH ; return control to DOS
INT 21H



MAIN ENDP

END MAIN

END
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,116
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 38
Solved Threads: 929
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Most Valuable Poster

Re: display the number of capitals letters in the sentence

  #4  
Dec 12th, 2006
cmp al,'A'
CMP al,'Z'
JMP Count
you have to put a jump after every comparison -- see my previous code for example.

>>LOOP TOP
you can not use that construct in this program because you have to set cx to the number of times you want it to loop. use a jmp instead of loop.

>>MOV AH,1 ;READ sentenc
move that line down a bit so that it is inside the loop and befor the call to int 21. I think you have to reset ah every time.

>>mov bX,0
move that down a bit just before the beginning of the loop so that int 21 functions does not destroy its value. It may not, but you don't know for sure.
Last edited by Ancient Dragon : Dec 12th, 2006 at 2:06 pm.
I think it's about time we voted for senators with breasts. After all, we've been voting for boobs long enough. ~Clarie Sargent, Arizona senatorial candidate
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
Reply With Quote  
Join Date: Dec 2006
Posts: 10
Reputation: Rooro is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Rooro Rooro is offline Offline
Newbie Poster

Re: display the number of capitals letters in the sentence

  #5  
Dec 12th, 2006
also after I chaned the program i'm still having problem which is when i want to read a sentenc from the user the program takes only one character !


.MODEL SMALL
.STACK 100H
.DATA
MSG1 DB 'PLEASE ENTER YOUR SENTENCE:  $'
MSG2 DB 0DH,0AH,'THE NUMBER OF CAPITAL LETTERS IN 
SENTENCE :$'
MSG3 DB 0DH,0AH,'You have entered more than 9 capital 
LETTERS $'

.CODE
MAIN PROC

MOV AX,@DATA ;initialize DS
MOV DS,AX

;DISPLAY MSG1
LEA DX,MSG1  ;GET MSG1
MOV AH,9  ;DISPLAY STRING
INT 21H  ;DISPLAY MSG1

MOV AH,1  ;READ sentenc
mov bX,0
TOP:
MOV AH,1  ;READ sentenc
INT 21h

WHILE_:

cmp al,0dh
je END_WHILE

cmp al,'A'
JMP Count
CMP al,'Z'
JMP Count
LOOP TOP
Count:
INC bx
cmp bx,9
JLE Display1
JG Display2
 
END_WHILE:

Display1:
LEA DX,MSG2  ;GET MSG1
MOV AH,9  ;DISPLAY STRING
INT 21H  ;DISPLAY MSG1
mov ah,2
mov DX,BX
INT 21H

Display2:
LEA DX,MSG3  ;GET MSG1
MOV AH,9  ;DISPLAY STRING
INT 21H  ;DISPLAY MSG1

MOV AH,4CH ; return control to DOS
INT 21H
 
MAIN ENDP
 END MAIN
END
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,116
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 38
Solved Threads: 929
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Most Valuable Poster

Re: display the number of capitals letters in the sentence

  #6  
Dec 12th, 2006
JMP Count
CMP al,'Z'
JMP Count
LOOP TOP
The jumps are incorrect -- please see my previous post. jmp instruction is an unconditional jump meaning that the program will go regardless of any previous comparisons. you need to use the JL and JG jumps are in my example.

Also you failed to remove the LOOP. See my previous post for explaination why you can not use that in your program.

Out of curiosity, what other programming languages do you know? loops in assembly are very much the same in all other languages.
Last edited by Ancient Dragon : Dec 12th, 2006 at 2:22 pm.
I think it's about time we voted for senators with breasts. After all, we've been voting for boobs long enough. ~Clarie Sargent, Arizona senatorial candidate
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
Reply With Quote  
Join Date: Dec 2006
Posts: 10
Reputation: Rooro is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Rooro Rooro is offline Offline
Newbie Poster

Re: display the number of capitals letters in the sentence

  #7  
Dec 12th, 2006
.MODEL SMALL
.STACK 100H
.DATA
MSG1 DB 'PLEASE ENTER YOUR SENTENCE:  $'
MSG2 DB 0DH,0AH,'THE NUMBER OF CAPITAL LETTERS IN 
SENTENCE :$'
MSG3 DB 0DH,0AH,'You have entered more than 9 capital 
LETTERS $'
 
.CODE
MAIN PROC
 
MOV AX,@DATA ;initialize DS
MOV DS,AX
 
;DISPLAY MSG1
LEA DX,MSG1  ;GET MSG1
MOV AH,9  ;DISPLAY STRING
INT 21H  ;DISPLAY MSG1
 
 
MOV AH,1  ;READ sentenc
INT 21h
mov bX,0
cmp al,0dh
cmp al,'A'
JL Count
CMP al,'Z'
JG Count
 
Count:
INC bx
cmp bx,9
JLE Display1
JG Display2
 
 
Display1:
LEA DX,MSG2  ;GET MSG1
MOV AH,9  ;DISPLAY STRING
INT 21H  ;DISPLAY MSG1
mov ah,2
mov DX,BX
INT 21H
 
Display2:
LEA DX,MSG3  ;GET MSG1
MOV AH,9  ;DISPLAY STRING
INT 21H  ;DISPLAY MSG1
 
MOV AH,4CH ; return control to DOS
INT 21H
 
MAIN ENDP
 END MAIN
END

i can not do my work clearly , realy i'm littlel tired


i want to know :

i should have something repeted many times to check every charactar but i can not use for loop right ? insted of that can I use WHILE loop ? if yes how can I do it ?

also how the program knows that the user fenish entring the sentenc ? , i have to compare the al with what exactly ? whith 0dH or 13h ?
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,116
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 38
Solved Threads: 929
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Most Valuable Poster

Re: display the number of capitals letters in the sentence

  #8  
Dec 12th, 2006
Well I think you are making things worse, not better. Here is one way to do what you want. I have not assembled or tested this.
;----
; ---- start of loop reading the keyboard
; ---- one character at a time
;----
mov bX,0 -- initialize capital character counter
loop_top:
MOV AH,1  ;READ A CHARACTDR
INT 21h
cmp al,0dh ; end of line?
je Display1 ; yes, then stop
; test for capital letters
cmp al,'A'
JL loop_end ; if char < 'A' then go
CMP al,'Z'
JG loop_end ; if char > 'Z' then go

INC bx  ; increment capital letter counter
cmp bx,9
JG Display2 ; too many capital letters

loop_end:
jmp loop_top


 
Display1:
LEA DX,MSG2  ;GET MSG1
MOV AH,9  ;DISPLAY STRING
INT 21H  ;DISPLAY MSG1

mov dl,bl ; print the number of characters
add dl,'0' ; make it readable
MOV AH,2  ;display the character that is in dl
INT 21H
jmp exit_program ; all done
 
Display2:
LEA DX,MSG3  ;GET MSG1
MOV AH,9  ;DISPLAY STRING
INT 21H  ;DISPLAY MSG1

exit_program:
MOV AH,4CH ; return control to DOS
INT 21H
 
MAIN ENDP
 END MAIN
END
Last edited by Ancient Dragon : Dec 12th, 2006 at 3:37 pm.
I think it's about time we voted for senators with breasts. After all, we've been voting for boobs long enough. ~Clarie Sargent, Arizona senatorial candidate
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
Reply With Quote  
Join Date: Dec 2006
Posts: 10
Reputation: Rooro is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Rooro Rooro is offline Offline
Newbie Poster

Re: display the number of capitals letters in the sentence

  #9  
Dec 12th, 2006
Ancient Dragon

I do not konw what can I say to you :o

Thanks A lot ....


i have understand all the code unless this point :

 
 
mov dl,bl ; print the number of characters
add dl,'0' ; make it readable

may you explain it plaese ?

I want to learn why you have chose the dl register + 0 ?

to convert from ASCII code to decimal, to display it in the right way ?



-----------------------

if the user is allowed to enter a sentence with maximum 19 capital letters , How the display3 will be ?

 
 
cmp bx,19
JG Display2  ; more than 19 capital letters
 


if <9

Display1

if >9

display3

first we have to display number 1

like :

 
mov ah,2
mov dl,'1'
int 21h

then,we will do subtract with 10 with that number which is > 9
then, display it , but how can I display this number in decimal ?
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,116
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 38
Solved Threads: 929
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Most Valuable Poster

Re: display the number of capitals letters in the sentence

  #10  
Dec 12th, 2006
>>may you explain it plaese ?
If you look at a standard ascii chart you will see that the letter '0' has a decimal value of 48. So, to convert a binary value all you have to do is add 48 to it. For example, assume there was just one capital letter in the string, that makes dl = 1. add 48 to that gives you dl value of 49. Then look at the ascii chart and see that the decimal value of 49 is the letter '1'. Note that the letter '1' and the decimal value 1 are not the same thing.

>>f the user is allowed to enter a sentence with maximum 19 capital letters , How the display3 will be ?
don't you mean 9 capital characters? Display2 shows MSG3. There is no Display3 (or at least you did not write one).

display3

first we have to display number 1

like :
<snip>
I don't see any requirement for you to display two digits. There is not limit to the string length you can enter, only a limit of 9 capital letters. You can enter 255 characters if you want to.
Last edited by Ancient Dragon : Dec 12th, 2006 at 6:35 pm.
I think it's about time we voted for senators with breasts. After all, we've been voting for boobs long enough. ~Clarie Sargent, Arizona senatorial candidate
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Assembly Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the Assembly Forum

All times are GMT -4. The time now is 10:40 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC