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:
#Read x value
la $a0,x
addi $v0,$0,4
syscall
addi $v0,$0,5
syscall
#Store in a1
add $a1,$0,$v0
#Read y value
la $a0,y
addi $v0,$0,4
syscall
addi $v0,$0,5
syscall
#Store in a2
add $a2,$0,$v0
#Call function to get sum
jal oddSum
#display sum
add $t0,$0,$v0
la $a0,odd
addi $v0,$0,4
syscall
add $a0,$0,$t0
addi $v0,$0,1
syscall
#Call function to get even count
jal evenCount
#display even count
add $t0,$0,$v0
la $a0,even
addi $v0,$0,4
syscall
add $a0,$0,$t0
addi $v0,$0,1
syscall
addi $a0,$0,10
addi $v0,$0,11
syscall
#find and display qoutient
add $a0,$0,$a2
addi $v0,$0,1
syscall
addi $a0,$0,47
addi $v0,$0,11
syscall
add $a0,$0,$a1
addi $v0,$0,1
syscall
addi $a0,$0,61
addi $v0,$0,11
syscall
add $t0,$0,$a2
div $t0,$a1
mflo $a0
addi $v0,$0,1
syscall
addi $a0,$0,10
addi $v0,$0,11
syscall
#Display reminder
add $a0,$0,$a2
addi $v0,$0,1
syscall
addi $a0,$0,37
addi $v0,$0,11
syscall
add $a0,$0,$a1
addi $v0,$0,1
syscall
addi $a0,$0,61
addi $v0,$0,11
syscall
mfhi $a0
addi $v0,$0,1
syscall
#End of the program
addi $v0,$0,10
syscall
#Function for calculating odd sum
oddSum:
#x value in t0
add $t0,$0,$a1
#Variable for result
addi $v0,$0,0
#for odd finding
addi $t1,$0,2
oddLoop:
bgt $t0,$a2,retOdd
add $t3,$0,$t0
div $t3,$t1
mfhi $t2
beqz $t2,nextOdd
add $v0,$v0,$t0
nextOdd:
addi $t0,$t0,1
j oddLoop
retOdd:
jr $ra
#Function return even count
evenCount:
#x value in t0
add $t0,$0,$a1
#Variable for result
addi $v0,$0,0
#for odd finding
addi $t1,$0,2
evenLoop:
bgt $t0,$a2,retEven
add $t3,$0,$t0
div $t3,$t1
mfhi $t2
bnez $t2,nextEven
add $v0,$v0,1
nextEven:
addi $t0,$t0,1
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
Get Answers For Free
Most questions answered within 1 hours.