•
•
•
•
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
![]() |
•
•
Join Date: Dec 2006
Posts: 10
Reputation:
Rep Power: 2
Solved Threads: 0
Hello everyone : )
i'm working on :
what i did is :
My problem is on counting the number of capital letters .
Can anyone help please ?
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 ?
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,116
Reputation:
Rep Power: 38
Solved Threads: 929
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
I think you have the comparisons backwards. If the character < 'A' or > 'Z' then it is not a capital letter.
>>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
>> Mov bl,al
Why do that? just use al for tests
cmp bl,'A' JGE Count CMP bl,'Z' JLE Count
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
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
•
•
Join Date: Dec 2006
Posts: 10
Reputation:
Rep Power: 2
Solved Threads: 0
Thanks a lot Ancient Dragon
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
;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
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,116
Reputation:
Rep Power: 38
Solved Threads: 929
cmp al,'A' CMP al,'Z' JMP Count
>>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
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
•
•
Join Date: Dec 2006
Posts: 10
Reputation:
Rep Power: 2
Solved Threads: 0
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
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,116
Reputation:
Rep Power: 38
Solved Threads: 929
JMP Count CMP al,'Z' JMP Count LOOP TOP
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
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
•
•
Join Date: Dec 2006
Posts: 10
Reputation:
Rep Power: 2
Solved Threads: 0
.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 ?
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,116
Reputation:
Rep Power: 38
Solved Threads: 929
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
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
•
•
Join Date: Dec 2006
Posts: 10
Reputation:
Rep Power: 2
Solved Threads: 0
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 :
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 ?
if <9
Display1
if >9
display3
first we have to display number 1
like :
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 ?
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 ?
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,116
Reputation:
Rep Power: 38
Solved Threads: 929
>>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).
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.
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>
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
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
![]() |
•
•
•
•
•
•
•
•
DaniWeb Assembly Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Other Threads in the Assembly Forum
- Previous Thread: help
- Next Thread: Serial port in assembly



'
Linear Mode