In: Computer Science
In MIPS Assembly Language in Mars, define a method 1 to check if a number is divisible by 4. Then, define a method 2 to generate a random number, call method 1, and return result(number, yes/no) to main. Lastly, have the main method call method 2, and display the results.
.data
y: .asciiz"\nyes"
n: .asciiz"\nno"
.text
.globl main
main: # call method2 and print number, yes/no
jal method2
move $a0, $v0
li $v0, 1
syscall
beqz $v1, if
li $v0, 4
la $a0, n
syscall
j end
if: # to print yes
li $v0, 4
la $a0, y
syscall
j end
method1: # to check if number is divisible by 4
li $t1, 4
div $a0, $t1
mfhi $v1
jr $ra
method2: # generate random number and call method 1
li $v0, 42 # 42 is system call code to generate random
int
li $a1, 100 # $a1 is where you set the upper
bound
syscall # your generated
number will be at $a0
move $v0, $a0
move $v0, $a0
sw $ra, ($sp)
jal method1
lw $ra, ($sp)
jr $ra
end:
li $v0, 10
syscall
#code snippet
#Output