In: Computer Science
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 }
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: