.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 19 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
; start of loop reading the input
; one character at a time
mov bX,0 ; initialize CAPITAL LETTERS 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 to the end of the loop
CMP al,'Z'
JG loop_end ; if char > 'Z' then go to the end of the loop
INC bx ; increment capital letter counter
cmp bx,19
JG Display2 ; more than 19 capital letters
loop_end:
jmp loop_top
Display1:
LEA DX,MSG2 ;GET MSG1
MOV AH,9 ;DISPLAY STRING
INT 21H ;DISPLAY MSG1
CMP bx,9
JLE Display3
mov ah,2
mov dl,'1'
int 21h
mov dl,bl ; print the number of characters
add dl,'0' ;To convert the number of characters from ASCII to decimal number
SUB dl,10
MOV AH,2 ;display the number of character that is in dl
INT 21H
jmp exit_program
Display3:
mov dl,bl ; print the number of characters
add dl,'0' ;To convert the number of characters from ASCII to decimal number
MOV AH,2 ;display the number of character that is in dl
INT 21H
jmp exit_program ; all done
Display2:
LEA DX,MSG3 ;GET MSG3
MOV AH,9 ;DISPLAY STRING
INT 21H ;DISPLAY MSG3
exit_program:
MOV AH,4CH ; return control to DOS
INT 21H
MAIN ENDP
END MAIN
ENDF