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

Homework Answers

Answer #1

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

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
C++ programming Write a program that reads a comma-separated file (CSV) with integer values and prints...
C++ programming Write a program that reads a comma-separated file (CSV) with integer values and prints the number of integer values in the file. Your program's input will be a string with the name of the file. If the file does not exist, then the program must print: Error opening the file For example, given the following CSV file input1.csv: 1,10,20,30,40 The output of your program must be: 5 You can safely assume that the input file will be a...
c++ Write a program that calls a function calculateSum to calculate the sum from -1 to...
c++ Write a program that calls a function calculateSum to calculate the sum from -1 to N. The function calculateSum has one parameter N of type integer and returns an integer which represents the sum from -1 to N, inclusive. Write another function calculateAverage that calculates an average. This function will have two parameters: the sum and the number of items. It returns the average (of type float). The main function should be responsible for all inputs and outputs. Your...
Write a C++ program to do the following: Declare and assign values to int variables x,...
Write a C++ program to do the following: Declare and assign values to int variables x, y Declare an int variable z; and store the sum of x and y in it Declare a pointer called pz and point it in the heap direction (using new) Store the z value in the heap location using the pz pointer Print the content of the pz pointer Print the pointer (the address)
Write a function that takes two integer inputs and returns the sum of all even numbers...
Write a function that takes two integer inputs and returns the sum of all even numbers between these inputs, and another function that takes two integer inputs and returns the sum of odd numbers between these inputs .In main function, the program will asks the user to enter two integer numbers and then passes them to these two functions and display the result of each of them.         [0.5 mark] (BY USING C PROGRAM)
C++ PROGRAM. (C++ INTRO QUESTION) Write a program that prints the count of all prime numbers...
C++ PROGRAM. (C++ INTRO QUESTION) Write a program that prints the count of all prime numbers between A and B (inclusive), where A and B are defined as follows: A = 55000 B = A + 5000 Just a recap on prime numbers: A prime number is any number, greater or equal to 2, that is divisible ONLY by 1 and itself. Here are the first 10 prime numbers: 2, 5, 7, 11, 13, 17, 19, 23, and 29. Rules:...
Function Example: Write a Python function that receives two integer arguments and writes out their sum...
Function Example: Write a Python function that receives two integer arguments and writes out their sum and their product. Assume no global variables. def writer(n1, n2): sum = n1 + n2 product = n1*n2 print("For the numbers", n1, "and", n2) print("the sum is", sum) print("and the product is", product) ... 1) Create a PYHW2 document that will contain your algorithms in flowchart and pseudocode form along with your screen shots of the running program. 2) Create the algorithm in both...
Java Program : Please save the program with the name ‘Dstring.java’ Write a program that reads...
Java Program : Please save the program with the name ‘Dstring.java’ Write a program that reads a string from the keyboard. If the length of the string is an even number, your program should split the string into two strings of equal length. If the length of the string is odd, your program should split the string into two strings where the first part has one more character than the second part. Your program should output the two strings it...
Using Prolog: Write a program that reads an integer x and a list of integers L;...
Using Prolog: Write a program that reads an integer x and a list of integers L; then locate the list of all positions of x into L, and return the resulting list. For example, for x=2 and L=[1,2,3,4,2,5,2,6] the program should return the list R=[2,5,7]. Note:The build-in function are not allowed.
PYTHON 3 Write a program that prints the count of all prime numbers between A and...
PYTHON 3 Write a program that prints the count of all prime numbers between A and B (inclusive), where A and B are defined as follows: A = 21212 B = A + 5000 Just a recap on prime numbers: A prime number is any number, greater or equal to 2, that is divisible ONLY by 1 and itself. Here are the first 10 prime numbers: 2, 5, 7, 11, 13, 17, 19, 23, and 29. Rules: You should first...
Write a program in python that prints the count of all prime numbers between A and...
Write a program in python that prints the count of all prime numbers between A and B (inclusive), where A and B are defined as follows: A = The 5 digit unique number you had picked at the beginning of the semester B = A + 5000 Just a recap on prime numbers: A prime number is any number, greater or equal to 2, that is divisible ONLY by 1 and itself. Here are the first 10 prime numbers: 2,...