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 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 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 :...
(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...
How do I do this: Write a program that can read a text file of numbers...
How do I do this: Write a program that can read a text file of numbers and calculate the mean and standard deviation of those numbers. Print the result in another text file. Put the result on the computer screen. EACH LINE OF THE PROGRAM MUST BE COMMENTED!
Do Not Use Pseudo Insturctions or li la instructions, etc... Write and test a MIPS program...
Do Not Use Pseudo Insturctions or li la instructions, etc... Write and test a MIPS program consisting of four functions. In the following descriptions, the symbol & means “address of”. void main(): The main function must 1) print your name 2) call the readData function 3) call count function 4) complete the program. The main function must set up all parameters before calling each of the functions. int readData (&array): The starting address of an array is passed to the...
Hello I am needing an example of how to write an assembly (MIPS) code that with...
Hello I am needing an example of how to write an assembly (MIPS) code that with will ask the user for two numbers then for addition or multiplication by typing in + or * into the command prompt. For example if I type in the number 2 and 5 then + The code should add the sum between the two numbers like 2 + 3 + 4 + 5 = 14. If multiplication is implemented then it will do the...
2. What characters do all plants and green algae share? 3. What characters do all plants...
2. What characters do all plants and green algae share? 3. What characters do all plants share that green algae do not share? 4. What is meant by alternation of generations? 5. What are the terrestrial adaptations that plants have evolved and which groups share those characters? 6. Compare and contrast phloem and xylem. 7. Compare and contrast the life cycles of the four groups of plants. The sporophyte generation compared to the gametophyte generation. Which is dominant in each...
write a program in C Write a function that is passed an array of characters containing...
write a program in C Write a function that is passed an array of characters containing letter grades of A, B, C, D, and F, and returns the total number of occurrences of each letter grade. Your function should accept both lower and upper case grades, for example, both 'b' and 'B' should be bucketed into your running total for B grades. Any grade that is invalid should be bucketed as a grade of 'I' for Incomplete. You must use...
Coding Problem 1: In this program, you are asked to write a program in assembly (MIPS)...
Coding Problem 1: In this program, you are asked to write a program in assembly (MIPS) which works as a simple calculator. The program will get two integer numbers, and based on the requested operation, the result should be shown to the user. a. The program should print a meaningful phrase for each input, and the result. i. “Enter the first number” ii. “Enter the second number” iii. “Enter the operation type” iv. “The result is” b. The user should...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT