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++ 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)
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...
In Java. Write a program that reads-in a times table-number. The program, using this table-number will...
In Java. Write a program that reads-in a times table-number. The program, using this table-number will produce the following report (as shown). The first item in the report is a number with starting value 1. Second column is the word “ X ” (representing the times symbol). Third column is the table-number (itself). Following is an equal sign “ = “ (representing a result). Last column is the result of the operation for that line or row which is the...
float sum( float x, float y, float z ) ​program in c++
Here are the function prototypes for your homeworkWrite out the actual functions themselves Also, create a main function that demonstrates that all four functions work The user should be able to provide four values to your program (three floats and an int) Your program should then use your four new functions and also display the results to the user NONE of these functions should print values themselvesfloat sum( float x, float y, float z ); // returns the sum of three floatsfloat mean( float...
Write a program in c++ to Convert an array of inches to an array of centimeters....
Write a program in c++ to Convert an array of inches to an array of centimeters. The program should contain a function called inchesTOcm with three parameters (inches array that contains the values in inches, cm array to save the result in, and an integer variable that defines the length of the array). In the main function: 1. Define an array (inches) of length 3. 2. Initialize the array by asking the user to input the values of its elements....
Write a function in c using #include <stdio.h> that takes a one-dimensional integer array and returns...
Write a function in c using #include <stdio.h> that takes a one-dimensional integer array and returns the index of the first occurance of the smallest value in the array. Your function must be able to process all the elements in the array. Create a function prototype and function definition (after the main function). Your main function should declare a 100 element integer array. Prompt the user for the number of integers to enter and then prompt the user for each...
A) write a program the computes nx and store the result into y You can use...
A) write a program the computes nx and store the result into y You can use y = Math.pow( Mantissa, exponent) Requirements: Besides main() your program must have one method with two parameters, one double and one int n and x are positive numbers read from the keyboard if the user makes an entry that does not meet this criteria, the user must be given to opportunity retry the entry the user must be able to quit prior to entering...