217k views
3 votes
Compose a program to examine the string "Hello, world!\\", and calculate the total decimal numeric value of all the characters in the string (including punctuation marks), less the numeric value of the vowels.

The program should load each letter, add that numerie value to the running total to produce a total sum, and then add the value to a "vowels running total as well. The program will require a loop. You do not need a counter, since the phrase is null terminated. Remember, punctuation (even spaces!) have a numeric value as well.

1 Answer

4 votes

Answer:

.data

str: .asciiz "Hello, world!\\"

output: .asciiz "\\Total character numeric sum = "

.text

.globl main

main:

la $t0,str # Load the address of the string

li $t2,0 # Initialize the total value to zero

loop: lb $t1,($t0) # Load one byte at a time from the string

beqz $t1,end # If byte is a null character end the operation

add $t2,$t2,$t1 # Else add the numeric value of the byte to the running total

addi $t0,$t0,1 # Increment the string pointer by 1

b loop # Repeat the loop

end:

# Displaying the output

li $v0,4 # Code to print the string

la $a0,output # Load the address of the string

syscall # Call to print the output string

li $v0,1 # Code to print the integer

move $a0,$t2 # Put the value to be printed in $a0

syscall # Call to print the integer

# Exiting the program

li $v0,10 # Code to exit program

syscall # Call to exit the program

Step-by-step explanation:

User Caglayan DOKME
by
4.4k points