Question

Write a MIPS program to demonstrate the operation of the following switch statement. switch (S) {...

Write a MIPS program to demonstrate the operation of the following switch statement.

switch (S) {
   case  5: A = A + 1; break;
   case 25: A = A - 1; break;
   default: A = A * 2; break;
}

Implement and simulate your solution. Allocate .data locations for the variables S and A, and load these values into registers before performing the switch statement on the registers. Run your program several times with different values for these variables, to ensure that your program works as expected. Bonus marks if your program prompts the user for the values of S and A, and displays results of the computation to the user.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

.data
   inputS: .asciiz "Enter value of S: "
   inputA: .asciiz "Enter value of A: "
   outMsg: .asciiz "A = "
   S: .word 0
   A: .word 0
.text
   #print string
   li $v0, 4
   la $a0, inputS
   syscall
  
   #read int and save to S
   li $v0, 5
   syscall

   sw $v0, S
  
   #print string
   li $v0, 4
   la $a0, inputA
   syscall
  
   #read int and save to A
   li $v0, 5
   syscall

   sw $v0, A
  
   lw $t1, S
   lw $t2, A
  
switch:
   beq $t1, 5, case5
   beq $t1, 25, case25
default:
   mul $t2, $t2, 2
   b end_switch
  
case5:
   add $t2, $t2, 1
   b end_switch
case25:
   sub $t2, $t2, 1
   b end_switch

end_switch:
   sw $t2, A  
   #display value of A
   li $v0, 4
   la $a0, outMsg
   syscall
  
   move $a0, $t2
   li $v0, 1
   syscall
  
   #exit
   li $v0, 10
   syscall


output
---
Enter value of S: 20
Enter value of A: 3
A = 6
-- program is finished running --

Enter value of S: 5
Enter value of A: 6
A = 7
-- program is finished running --

Enter value of S: 25
Enter value of A: 9
A = 8
-- program is finished running --

Add a comment
Know the answer?
Add Answer to:
Write a MIPS program to demonstrate the operation of the following switch statement. switch (S) {...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The switch Statement C++program This lab work with the switch statement. • Remove the break statements...

    The switch Statement C++program This lab work with the switch statement. • Remove the break statements from each of the cases. What is the effect on the execution of the program? • Add an additional switch statement that allows for a Passing option for a grade of D or better. Use the sample run given below to model your output. Sample Run: What grade did you earn in Programming I? YOU PASSED! An A - excellent work! The following is...

  • Find the errors in following program. //This program uses a switch statement to assign a //...

    Find the errors in following program. //This program uses a switch statement to assign a // letter grade (A, B, C, D, or F) to numeric test score. #include <iostream> uisng namespace std; int main() { int testScore; cout<<"Enter your test score and I will tell you\n"; cout<<"the letter grade you earned: "; cin>>testScore; switch (testScore) { case (testScore < 60) cout<<"Your grade is F.\n"; break; case (testScore <70) cout<<"Your grade is D.\n" break; case (testScore <80) cout<<"Your grade is...

  • Find the errors in following program.   //This program uses a switch statement to assign a...

    Find the errors in following program.   //This program uses a switch statement to assign a // letter grade (A, B, C, D, or F) to numeric test score.     #include <iostream> uisng  namespace std;   int main() {                         int testScore;                         cout<<"Enter your test score and  I will tell you\n";             cout<<"the letter grade you earned: ";             cin>>testScore;               switch (testScore)             {                         case  (testScore < 60)                                     cout<<"Your grade is F.\n";...

  • Pick a switch statement from the reading. Put it into a main() Java program and make...

    Pick a switch statement from the reading. Put it into a main() Java program and make it work. Attach the .java file and copyAndPaste the output into the WriteSubmissionBox The switch Statement S1.51 Multiway if-else statements can become unwieldy when you must choose from among many possible courses of action. If the choice is based on the value of an integer or character expres- sion, the switch statement can make your code easier to read. The switch statement begins with...

  • Write a C program that does the following: • Displays a menu (similar to what you...

    Write a C program that does the following: • Displays a menu (similar to what you see in a Bank ATM machine) that prompts the user to enter a single character S or D or Q and then prints a shape of Square, Diamond (with selected height and selected symbol), or Quits if user entered Q. Apart from these 2 other shapes, add a new shape of your choice for any related character. • Program then prompts the user to...

  • Write a c++ expression representing the following algebraic expression. Assume that all variables in your program...

    Write a c++ expression representing the following algebraic expression. Assume that all variables in your program are of the type double and that your program has already included the <cmath> header file. 3x + 1/y - 10 + Squareroot g Your answer: (b) Rewrite the same expression assuming that variables x and y in your program are of type int your answer: Convert the following switch statement into an equivalent if-else if statement switch (ch) {case 'A'; cout << "...

  • Write a program named "VegetablePricer" which prompts the user for a vegetable from the pricing table...

    Write a program named "VegetablePricer" which prompts the user for a vegetable from the pricing table shown below. The program will then display the cost per pound for that vegetable, again using the table provided. Your program must use a switch statement to process the input value and display the desired output. Be sure to provide a default case in your switch statement which handles unrecognized input. Use named constants for all constant strings (e.g. prompts and vegetable names) and...

  • please use c programme Write a program which simulates a calculator using the following specifications. (50...

    please use c programme Write a program which simulates a calculator using the following specifications. (50 points - 10pts for syntax, 10pts for commenting and 30pts for successful execution) • User input must have the following format - value1 operator value2 • Compute value1 operator value2 • Use switch statement • Operators must be ’+’ ,’-’, ’*’, ’/’ and ’%’ • Division by 0 in C leads to an error. Terminate the program before divison occurs in such cases. •...

  • Write a menu driven program to demonstrate the use of array and switch. It must be...

    Write a menu driven program to demonstrate the use of array and switch. It must be written in C language . Here is the menu - Press 1 to add a number to the array. Press 2 to display the numbers entered in the array so far Press 3 to find the average of the numbers entered. Press 4 to exit. Option 1 - The user should be able to enter 20 numbers only. If all twenty numbers are entered...

  • Methods and File Output and Exceptions Outcome: Student will demonstrate the ability to write, use and...

    Methods and File Output and Exceptions Outcome: Student will demonstrate the ability to write, use and call methods Student will demonstrate the ability to pass values to and from methods Student will demonstrate the ability to catch exceptions Student will demonstrate the ability to create a text file Student will demonstrate the ability to validate input data Program Specifications: You to write a menu driven program. The program will use a switch statement. The cases will be as follows: Get...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT