Question

In: Computer Science

How do I write a program in MIPS that will change all the characters in a...

How do I write a program in MIPS that will change all the characters in a string into lowercase.

For instance: string: " CANBERRA AUSTRALIA"

Output: "canberra australia"

Solutions

Expert Solution

Screenshot of the code:-

Screenshot of the output(in Mars Simulator):-

MIPS code to copy(with comments):-

.data
in_str: .asciiz "Enter the string: "
out_str: .asciiz "Capitalized String is: "
buff: .space 80 #this is the buffer

.text

main:
la $a0, in_str # Load and print string asking for string
li $v0, 4
syscall  
  
li $v0, 8 # Get the input
la $a0, buff # load the byte space into the address
li $a1, 80 # allot the byte space for string
syscall
move $s0, $a0 # save string
  
li $v0, 4
li $t0, 0

#Loop to convert to lowercase
loop:
lb $t1, buff($t0) #Load byte from 't0'th position in the buffer into $t1
beq $t1, 0, exit #If input ends, go to exit
bge $t1, 'A', maybe_not_capital #If greater than A, go to maybe_not_capital
ble $t1,'A',other_chars #If less than A,go to other_chars
  
j upper_to_lower
  
upper_to_lower:
addi $t1,$t1,32
sb $t1, buff($t0) #Store it back to 't0'th position in buffer
  
maybe_not_capital:
blt $t1, 'Z',upper_to_lower #If less than Z, go to upper_to_lower
addi $t0, $t0, 1 #else, increment $t0 and continue
j loop
  
other_chars:
beq $t1,' ',space #If it is space,then go to space
  
space:
addi $t0, $t0, 1
j loop
              
exit:
la $a0, out_str # load and print the capitalised string
li $v0, 4
syscall

move $a0, $s0   
li $v0, 4 # print string
syscall
li $v0, 10 # end program
syscall


Related Solutions

I have to do the following MIPS coding assignment. Question 1 Write a MIPS program that...
I have to do the following MIPS coding assignment. Question 1 Write a MIPS program that meets the following requirements (NOTE: your program statements should follow the order of the requirements and each requirement should correspond to only one assembly instruction): Loads the hexadecimal equivalent of 23710 into register 13 using an immediate bitwise OR instruction Loads the hexadecimal equivalent of 183410 into register 17 using an immediate bitwise OR instruction Performs the bitwise AND operation on the operands stored...
How would i write a MIPS program that converts 2 decimals to binary
How would i write a MIPS program that converts 2 decimals to binary
How can I write a simple MIPS program to print out the following elements of an...
How can I write a simple MIPS program to print out the following elements of an array of the size of 10: 5,10,15,20,25,30,35,40,45,50
Write a MIPS assembly program that calculates the sum of all the elements in the following...
Write a MIPS assembly program that calculates the sum of all the elements in the following array: int array[10]={12,21,3,40,15,6,17,8,29,10}
(b) You will write a program that will do the following: prompt the user enter characters...
(b) You will write a program that will do the following: prompt the user enter characters from the keyboard, you will read the characters until reading the letter ‘Q’ You will compute statistics concerning the type of characters entered. In this lab we will use a while loop. We will read characters from stdin until we read the character ‘Q’. Example input mJ0*5/]+x1@3qcxQ The ‘Q’ should be included when computing the statistics properties of the input. Since characters are integers...
write this program in C++ Write a program that prompts a user for three characters. The...
write this program in C++ Write a program that prompts a user for three characters. The program must make sure that the input is a number 10 - 100 inclusive. The program must re prompt the user until a correct input is entered. Finally output the largest and the lowest value. Example 1: Input : 10 Input : 20 Input : 30 The largest is 30. The lowest is 10. Example 2: Input : 100 Input : 50 Input :...
Write a MIPS Assembly program that computes the sum of all the odd numbers from 1...
Write a MIPS Assembly program that computes the sum of all the odd numbers from 1 ..99 and print out the answer.
Write a C++ main program that has the following: 9. Display all printable characters of the...
Write a C++ main program that has the following: 9. Display all printable characters of the ASCII table in 3 columns: first column: 32-63, second column: 64-95, third column: 96-127. Each column must include the numeric value and the corresponding character. Following is an example of one of 32 rows in the ASCII table: 33 ! 65 A 97 a
Write a program that takes a string from the user, identifies and counts all unique characters...
Write a program that takes a string from the user, identifies and counts all unique characters in that given string. You are bound to use only built-in string functions where necessary. For identification of unique characters and for counting of the characters make separate functions. For character identification Develop a program that takes a string argument, and returns an array containing all unique characters. For character counting Develop a program that takes an array returned from above function as an...
Write a program that takes a string from the user, identifies and counts all unique characters...
Write a program that takes a string from the user, identifies and counts all unique characters in that given string. You are bound to use only built-in string functions where necessary. For identification of unique characters and for counting of the characters make separate functions. For character identification Develop a program that takes a string argument, and returns an array containing all unique characters. For character counting Develop a program that takes an array returned from above function as an...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT