Question

# Write spim program and execute it on mars. Your program reads two integer values x and...

Write spim program and execute it on mars. Your program reads two integer values x and y. Write a function called sum that gets x and y passed as parameters and return the sum of odd values between x and y inclusive. In addition write another function called even that gets x and y as parameters and returns the count of all even numbers between x and y inclusive. Also in main print the quotient and remainder of diving y by x (y/x) and (y % x) In main should read x and y. then call the functions print your name followed by the results. Assume input is 3 12 Output: Your name Sum = 35 Count even 5 y/x = 4 y%x = 0

Screenshot

Program

#Data declaration part
.data
x: .asciiz "Enter x value: "
y: .asciiz "Enter y value: "
odd: .asciiz "Sum = "
even: .asciiz "\nCount even = "
#Main , Program start
.globl main
.text
main:
la \$a0,x
syscall
syscall
#Store in a1
la \$a0,y
syscall
syscall
#Store in a2
#Call function to get sum
jal oddSum
#display sum
la \$a0,odd
syscall
syscall
#Call function to get even count
jal evenCount
#display even count
la \$a0,even
syscall
syscall
syscall
#find and display qoutient
syscall
syscall
syscall
syscall
div \$t0,\$a1
mflo \$a0
syscall
syscall
#Display reminder
syscall
syscall
syscall
syscall
mfhi \$a0
syscall
#End of the program
syscall

#Function for calculating odd sum
oddSum:
#x value in t0
#Variable for result
#for odd finding
oddLoop:
bgt \$t0,\$a2,retOdd
div \$t3,\$t1
mfhi \$t2
beqz \$t2,nextOdd
nextOdd:
j oddLoop
retOdd:
jr \$ra

#Function return even count
evenCount:
#x value in t0
#Variable for result
#for odd finding
evenLoop:
bgt \$t0,\$a2,retEven
div \$t3,\$t1
mfhi \$t2
bnez \$t2,nextEven
nextEven:
j evenLoop
retEven:
jr \$ra

Output

Enter x value: 3
Enter y value: 12
Sum = 35
Count even = 5
12/3=4
12%3=0