Question

In: Computer Science

This is to be done with MIPS assembly language. Write MIPS code which is equivalent to...

This is to be done with MIPS assembly language.

Write MIPS code which is equivalent to the follow java program:

int day = (int)(Math.random() * 7);

switch (day) {

case 1: System.out.println(“Monday”); break

case 2: System.out.println(“Tuesday”); break

case 3: System.out.println(“Wednesday”); break

case 4: System.out.println(“Thursday”); break

case 5: System.out.println(“Friday”); break

case 6: System.out.println(“Saturday”); break

case 0: System.out.println(“Sunday”); break }

Solutions

Expert Solution

Please find the answer below.
Please do comments in case of any issue. Also, don't forget to rate the question. Thank You So Much.

.data
msg1: .asciiz "Monday"
msg2: .asciiz "Tuesday"
msg3: .asciiz "Wednesday"
msg4: .asciiz "Thursday"
msg5: .asciiz "Friday"
msg6: .asciiz "Saturday"
msg7: .asciiz "Sunday"

.globl main
.text
main:
li $a1, 7 #Here you set $a1 to the max bound.
li $v0, 42 #generates the random number.
syscall
move $t0,$a0#get random number
beq $t0,0,case1
beq $t0,1,case2
beq $t0,2,case3
beq $t0,3,case4
beq $t0,4,case5
beq $t0,5,case6
beq $t0,6,case7
case1:
li $v0,4
la $a0,msg1 #it will print prompt
syscall
j exit

case2:
li $v0,4
la $a0,msg2 #it will print prompt
syscall
j exit

case3:
li $v0,4
la $a0,msg3 #it will print prompt
syscall
j exit

case4:
li $v0,4
la $a0,msg4 #it will print prompt
syscall
j exit

case5:
li $v0,4
la $a0,msg5 #it will print prompt
syscall
j exit

case6:
li $v0,4
la $a0,msg6 #it will print prompt
syscall
j exit

case7:
li $v0,4
la $a0,msg7 #it will print prompt
syscall
j exit


exit:


Related Solutions

Write a MIPS assembly language to transpose a square integer matrix in code
Write a MIPS assembly language to transpose a square integer matrix in code
Write a MIPS assembly language program that implements the following pseudo-code operation: result = x +...
Write a MIPS assembly language program that implements the following pseudo-code operation: result = x + y – z + A[j] x and y should be in reserved memory words using the .word directive and labeled as x and y. Initialize x=10 and y=200. Read in z from the console. Input the value -8. This is the value for z, not for –z. Store this value in memory with the label z. To begin, you could just initialize z to...
This is to be done using MIPS assembly language. Display the following menus, ask user to...
This is to be done using MIPS assembly language. Display the following menus, ask user to select one item. If 1-3 is selected, display message “item x is selected”, (x is the number of a menu item), display menus again; if 0 is selected, quit from the program. 1. Menu item 1 2. Menu item 2 3. Menu item 3 0. Quit Please select from above menu (1-3) to execute one function. Select 0 to quit
I'm trying to code in MIPS (MIPS Assembly Language) to calculate the hamming distance between two...
I'm trying to code in MIPS (MIPS Assembly Language) to calculate the hamming distance between two integers. Ideally, the program would ask for the user to type in the two integers. Then, the program would calculate the hamming distance. Afterward, it would ask if you'd like to find another hamming distance. If the user says yes, it would loop back to the beginning and ask for two new integers. Below is the code that I've created so far. Guidance with...
MIPS Assembly LanguageWrite a MIPS assembly language program that asks the user toinput an...
MIPS Assembly LanguageWrite a MIPS assembly language program that asks the user to input an integer and then prints out a string that shows how that integer should be encoded using 16 bits. Your program should handle both positive and negative valued inputs. Your program should also print out an error message if the given input cannot be expressed as a 16 bit signed integer.As an example, if the input is 12, your program should output “0000000000001100”. If the input...
Write a program in MIPS assembly language to perform the calculation of the following equation and...
Write a program in MIPS assembly language to perform the calculation of the following equation and save the result accordingly:    f = 5x + 3y + z Assumptions: - Registers can be used to represent variables x, y, z, and f - Initialize x, y, and z to values of your choice. f can be initialized to zero. - Use comments to specify your register usage and explain your logic
In MIPS assembly language, write a function that will display the max and min value in...
In MIPS assembly language, write a function that will display the max and min value in an array. Then write a function to calculate and display the average of all values in an array. This must be done in MIPS assembly language.
Write a MIPS Assembly Language program which runs interactively to convert between decimal, binary, and hexadecimal....
Write a MIPS Assembly Language program which runs interactively to convert between decimal, binary, and hexadecimal. 1. Request input data type. 2. Request input data. 3. Request output data type. 4. Output the data. Use any algorithm
Write a mips assembly language program to ask the user to enter two integers A and...
Write a mips assembly language program to ask the user to enter two integers A and B and then display the result of computing the expression: A + 2B - 5.
Write a mips assembly language program that asks the user to enter an unsigned number and...
Write a mips assembly language program that asks the user to enter an unsigned number and read it. Then swap the bits at odd positions with those at even positions and display the resulting number. For example, if the user enters the number 9, which has binary representation of 1001, then bit 0 is swapped with bit 1, and bit 2 is swapped with bit 3, resulting in the binary number 0110. Thus, the program should display 6.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT