Hi, I have to write a program that counts all the uppercase letters in a string
ID: 3660139 • Letter: H
Question
Hi, I have to write a program that counts all the uppercase letters in a string and displays the count. The program is written using subroutines. Here is what I have so far... I am having troubles with counter in subroutine Help? ;A program that counts the occurances of uppercase ;alphabetic characters in a string stored in memory. ;The beginning address of the string will be passed ;by the main program to the subroutine in the regiter R1. ;(assume that total count <=9) .ORIG x3000 ;************************main********************** LEA R0,STRING ;display the string PUTS LD R0,CRLF ;display crlf (new line) OUT LEA R1,STRING ;load base address of string JSR COUNTER ;call subroutine COUNTER ST R0,COUNT ;safekeep uppercase letter count LEA R0,MSG ;display message PUTS LD R0,COUNT ;load count back in R0 LD R2,POS48 ;load 48 in R2 (ASCII conversion) ADD R0,R0,R2 ;display uppercase letter count OUT HALT ;stop program STRING .STRINGZ "AbcDefGHj" MSG .STRINGZ "Total count = " COUNT .BLKW 1 POS48 .FILL #48 CRLF .FILL #10 ;************************subroutine**************** ;A subroutine that founds the total number of uppercase ;letters in a string and returns it in the register R0 ;************************************************** COUNTER ST R1,SaveR1 ;save R1 ST R2,SaveR2 ;save R2 AND R0,R0,#0 ;clear R0 (counter) AND R3,R3,#0 ;clear R3 AND R4,R4,#0 ;clear R4 LOOP LDR R2,R1,#0 ;load char from string LD R3,NEG90 ;load -90 in R3 ADD R2,R2,R3 ;add R3 to R2 and store in R2 ADD R1,R1,#1 ;update address BRp LOOP ADD R0,R0,#1 ;increment counter BRnz LOOP LD R2,SaveR2 ;restore R2 LD R1,SaveR1 ;restore R1 RET ;register storage area for subroutine SaveR1 .BLKW 1 SaveR2 .BLKW 1 NEG90 .FILL #-90 ;************************************************** .END ;end of assemblyExplanation / Answer
DIS MACRO STR MOV AH,09H LEA DX,STR INT 21H ENDM DATA SEGMENT MSG1 DB "ENTER YOUR STRING : $" MSG2 DB "CONVERTED STRING IS : $" STR1 DB 20 DUP('$') LINE DB 10,13,'$' DATA ENDS CODE SEGMENT ASSUME DS:DATA,CS:CODE START: MOV AX,DATA MOV DS,AX DIS MSG1 MOV AH,0AH LEA DX,STR1 INT 21H DIS LINE MOV CH,00 MOV CL,BYTE PTR[STR1+1] LEA SI,STR1+2 L1: MOV AH,BYTE PTR[SI] CMP AH,'A' JL L4 CMP AH,'Z' JG L2 ADD BYTE PTR[SI],32 JMP L3 L2:CMP AH,'a' JL L4 CMP AH,'z' JG L4 SUB BYTE PTR[SI],32 L3:INC SI LOOP L1 DIS MSG2 DIS STR1+2 L4:MOV AH,4CH INT 21H CODE ENDS END START
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.