Using MIPS assembly program language, write a program that will read from memory
ID: 441470 • Letter: U
Question
Using MIPS assembly program language, write a program that will read from memory contents from an array that holds random number of characters that ends with a "." Make sure it counts total number of characters as well as the "." as well as the alphabetical characters (can be lower or upper case letters) and number of decimal digits in the array. Then the program writes the 3 totals to memory as TOTAL, DIGITS, LETTERS, The String will be "gYtAEWc!>?1234." The program if working properly will set total to 15, digits to 4, and letters to 7. I am using Textpad.Comments in code will help me a ton to understand thank you.Explanation / Answer
strlen:
li $t0, 0 # initialize the total count to zero
li $t1, 0# initialize the numeric count to zero
li $t2, 0# initialize the alphabet count to zero
li $t3, 0# initialize the to zero
li $t4, 9# initialize the to nine
.data
a1: .byte '.'# initialize variable a1 to '.'
a2: .byte 'a.'# initialize variable a1 to '.'
a3: .byte 'A'# initialize variable a1 to '.'
a4: .byte 'z'# initialize variable a1 to '.'
a5: .byte 'Z'# initialize variable a1 to '.'
totals: .asciiz "Total Characters "
number: .asciiz "Total Numbers "
alphas: .asciiz "Total Alphabets "
loop:
lbu $t5, 0($a0)# load the next character into t5
beq $t5, a1, exit# check for the '.' character
addi $a0, $a0, 1# increment the string pointer
addi $t0, $t0, 1# increment the count
bgt $t5, $t4, non# check for greather than 9
blt $t5, $t3, non# check for greather than 9
addi $t1, $t1, 1# increment the numeric count
non:
bgt $t5, a4, alp1# check for greather than 'z'
blt $t5, a2, alp1# check for greather than 'a'
addi $t2, $t2, 1# increment the alphabet numeric count
j loop# return to the top of the loop
alp1:
bgt $t5, a5, alp1# check for greather than 'z'
blt $t5, a3, alp1# check for greather than 'a'
addi $t2, $t2, 1# increment the alphabet numeric count
j loop# return to the top of the loop
exit:
addi $t0, $t0, 1# increment the count for the '.' character
li $v0, $t0# print totals
la $a0, totals
syscall
li $v0, $t1# print number count
la $a0, number
syscall
li $v0, $t2# print alphabet count
la $a0, alphas
syscall
end:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.