Hi,
Capital letters ascii value: 65 to 90
Small letters ascii value: 97 to 122
Digits ascii value : 48 to 57
Space ascii value : 32
Null ascii value : 0
Special Characters : 33–47, 58–64, 91–96, 123–126
Others: 1-31, 127 (Non printable characters) but newline is also included
.data
buffer : .space 100
prompt1: .asciiz "Enter a string upto 100 chars...\n"
upcase: .asciiz "The no. of Upper case Letters are :"
lwcase: .asciiz "\nThe no. of Lower case Letters are :"
digits: .asciiz "\nThe no. of Digit Characters are :"
SpecChars: .asciiz "\nThe no. of Special Characters are:"
SpcChars: .asciiz "\nThe no. of Spaces are :"
OtherChars: .asciiz "\nThe no. of Other Characters are :"
TotalChars: .asciiz "\nThe total no. of Characters are :"
.text
.globl main
main:
#Printing Prompt to Useer
li $v0, 4
la $a0, prompt1
syscall
#Reading input from user
li $v0, 8
la $a0, buffer
li $a1, 100
syscall
#Storing array starting address into $t0 register
la $t0, buffer
Repeat:
#taking one character and loading into $t1 register
lb $t1, ($t0)
#Comparing with NULL Character
beq $t1, 0, END
addi $t8, $t8, 1
#Finding the capital letter
blt $t1, 65, Next1
bgt $t1, 90, Next2
addi $t2, $t2, 1
b Again
#Finding the Digit
Next1:
blt $t1, 48, Special
bgt $t1, 57, Special
addi $t3, $t3, 1
b Again
#Finding the Small Letter
Next2:
blt $t1, 97, Special
bgt $t1, 122, Special
addi $t4, $t4, 1
b Again
Special:
#Finding Space Character
beq $t1, 32, Space
#Finding Special Characters
beq $t1, 127, Others
blt $t1, 33, Others
addi $t5, $t5, 1
b Again
#Incrementing if Space is found
Space:
addi $t6, $t6, 1
b Again
#Incrementing if any of these characters found
Others:
addi $t7, $t7, 1
Again:
#Repeating the loop till NULL found
addi $t0, $t0, 1
b Repeat
END:
#Printing the No. of Uppercase letters
li $v0, 4
la $a0, upcase
syscall
li $v0, 1
move $a0, $t2
syscall
#Printing the No. of Lowercase letters
li $v0, 4
la $a0, lwcase
syscall
li $v0, 1
move $a0, $t4
syscall
#Printing the No. of digit characters
li $v0, 4
la $a0, digits
syscall
li $v0, 1
move $a0, $t3
syscall
#Printing the No. of special characters
li $v0, 4
la $a0, SpecChars
syscall
li $v0, 1
move $a0, $t5
syscall
#printing the No. of Spaces
li $v0, 4
la $a0, SpcChars
syscall
li $v0, 1
move $a0, $t6
syscall
#printing the No. of Other Chars
li $v0, 4
la $a0, OtherChars
syscall
li $v0, 1
move $a0, $t7
syscall
#printing the total No. of Chars
li $v0, 4
la $a0, TotalChars
syscall
li $v0, 1
move $a0, $t8
syscall
#Control to O
li $v0, 10
syscall
Output:
Enter a string upto 100 chars...
AaBb 1@34fgF.c Zz
The no. of Upper case Letters are :4
The no. of Lower case Letters are :6
The no. of Digit Characters are :3
The no. of Special Characters are:2
The no. of Spaces are :2
The no. of Other Characters are :1
The total no. of Characters are :18
If you have any queries drop a comment...
Thanks...
Code, Thot CREATE A NPS Progfem using ASClI Code, Thet ccets striny up to loo chwokos...