Question

In: Computer Science

CSE/EEE 230 Assignment 4 Fall 2019 Due Sept 30 (11:59PM) In this assignment, you are to...


CSE/EEE 230 Assignment 4
Fall 2019
Due Sept 30 (11:59PM)
In this assignment, you are to complete a MIPS program so it will perform the required tasks. The main function of the code is provided. Do not change the code in the main function. There is a loop in the main function.
You are to complete the program by writing two functions. Pay particular attention to the purpose of each function and how the parameters and return value are to be used.
1. getinput
$a0 - minimum value
$a1 – maximum value
$v0 – integer input in range defined
This function must prompt the user to input an integer and then get the input from the user. The process of printing a prompt and then reading input must be repeated until a value from the minimum to the maximum values is read (inclusive). The input value is then returned in $v0.
2. printsum
The function is to the add the two parameters ($a0 and $a1) and then print the sum.
Sample Input and output:
Enter a number 2  This means that the main will loop 2 times.
Enter a number 7
Enter a number 3
The sum is 10
Enter a number -3
Enter a number -1
Enter a number 25
Enter a number 3
Enter a number 0
Enter a number 6
The sum is 9
General:
• Comment the beginning of your programs with your name and assignment number.
• Comment every instruction.
• Comment each function. Describe which registers are used in the function and how they are used.
Submit your .asm file with the complete program.
Copyright 2019 D.Calliss Arizona State University All rights reserved.
.data
# add any strings at this point as needed
.text
.globl main
main:
addi $a0, $0, 2 # set minimum value as 1
addi $a1, $0, 5 # set maximum value as 15
jal getinput # get a positive number for the loop
addi $s0, $v0, 0 # save input value
repeat:
beq $s0, $0, end # while there are more repeats
addi $a0, $0, 1 # set minimum value as 1
addi $a1, $0, 15 # set maximum value as 15
jal getinput # get a value from 1..15
ori $s1, $v0, 0 # save the result
addi $a0, $0, 3 # set minimum value as 3
addi $a1, $0, 18 # set maximum value as 18
jal getinput # get a value from 4..18
ori $a1, $v0, 0 # set the second parameter for printsum
ori $a0, $s1, 0 # set the first parameter for printsum
jal printsum # call function to print sum of input
addi $s0, $s0, -1 # decrement counter
j repeat # do it again
end: ori $v0, $0, 10 # set command to stop program,
syscall # end program

Solutions

Expert Solution

Screenshot

-------------------------------------------------------------------------------------------------

Program

.data
    input: .asciiz "Enter a number "
    output: .asciiz "The sum is "
# add any strings at this point as needed
.text
.globl main
main:
   addi $a0, $0, 1 # set minimum value as 1
   addi $a1, $0, 15 # set maximum value as 15
   jal getinput # get a positive number for the loop
   addi $s0, $v0, 0 # save input value
repeat:
   beq $s0, $0, end # while there are more repeats
   addi $a0, $0, 1 # set minimum value as 1
   addi $a1, $0, 15 # set maximum value as 15
   jal getinput # get a value from 1..15
   ori $s1, $v0, 0 # save the result
   addi $a0, $0, 3 # set minimum value as 3
   addi $a1, $0, 18 # set maximum value as 18
   jal getinput # get a value from 4..18
   ori $a1, $v0, 0 # set the second parameter for printsum
   ori $a0, $s1, 0 # set the first parameter for printsum
   jal printsum # call function to print sum of input
   addi $s0, $s0, -1 # decrement counter
   j repeat # do it again
end:
   ori $v0, $0, 10 # set command to stop program,
   syscall # end program

#Function to get input from user
getinput:
   #Save arguments min and max temporary
   add $t0,$0,$a0
   add $t1,$0,$a1
#Loop to check the upper and lower bounds of input
again:
   #Display prompt for input
   addi $v0,$0,4
   la $a0,input
   syscall
   #Read input
   add $v0,$0,5
   syscall
   #Bounds check
   blt $v0,$t0,next
   bgt $v0,$t1,next
   #Return to main
   jr $ra
#If not in the bound ask again
next:
   j again

#Function to generate sum
printsum:
   #Find sum and store in t0
   add $t0,$a0,$a1
   #Display output message
   add $v0,$0,4
   la $a0,output
   syscall
   #Display sum
   add $a0,$0,$t0
   addi $v0,$0,1
   syscall
   #Print next line
   addi $a0,$0,10
   addi $v0,$0,11
   syscall
   #Return to main
   jr $ra

------------------------------------------------

Output

Enter a number 2
Enter a number 7
Enter a number 3
The sum is 10
Enter a number -3
Enter a number -1
Enter a number 25
Enter a number 3
Enter a number 0
Enter a number 6
The sum is 9


Related Solutions

CS2123 Data Structures - Fall 2019 Assignment 1: Function Runtimes Table Due 9/11/19 by 11:59pm Completing...
CS2123 Data Structures - Fall 2019 Assignment 1: Function Runtimes Table Due 9/11/19 by 11:59pm Completing the Program (15 points) This program prints a table of runtimes (these are displayed in seconds) for given functions on arrays. The program tests different array sizes to establish a relationship between input size and runtime. It tests each array size multiple times and then takes an average of the times. Here are example calls to the timing functions: int sizes[] = { 1000,...
This assignment was locked Feb 27 at 11:59pm. A. There are three types of taxable income;...
This assignment was locked Feb 27 at 11:59pm. A. There are three types of taxable income; 1. active, 2. portfolio, 3. passive.  Describe each (in your own words) and make sure you understand the tax implications of these incomes. B. Debra Ferguson received the items and amounts of income shown below during 2016. Help her calculate, (a) her gross income and (b) that portion (dollar amount) of her income that is tax exempt. Salary                                                      $33,500 Dividends                                                  800            Gift from mother                                       500  ...
STAT 2023 Assignment 8 Fall 2019 due by 10pm on Monday, October 21 Estimation of the...
STAT 2023 Assignment 8 Fall 2019 due by 10pm on Monday, October 21 Estimation of the Population Mean, Lesson 13 Whitmore Farms sells theAmeraucana hens who lay light blue eggs. A random sample of 64 of these hens produced a mean standing height of 14.4 inches. The standard deviation of standing height of Ameraucana hens is known to be .8 inch. Use this information to answer the rest of the questions on this assignment. 1. What is the point estimate...
CS 238 – Assembly Language Programming Fall 2019 Assignment 1 (Due: September 10, 2019) Submission Instructions:...
CS 238 – Assembly Language Programming Fall 2019 Assignment 1 (Due: September 10, 2019) Submission Instructions: Online submissions on Blackboard are preferred. Feel free to edit this Word document to insert your answers. Multiple online submissions on Blackboard are allowed, but only the last online submission made by the midnight of September 10 will be graded. Alternatively, a paper submission is possible, but it needs to be done in class on September 10. 1. Data can be interpreted as required...
PSY 2030 -Assignment 4: One-Way Anova -Due by Sunday, April 19th, at 11:30 PM -Scores out...
PSY 2030 -Assignment 4: One-Way Anova -Due by Sunday, April 19th, at 11:30 PM -Scores out of 25 points (16 points for Question and 9 points for Question 2) -Submit by uploading file(s) within "Assignment 4" on Canvas -SHOW ALL WORK!! Either very clearly type it (making sure your formulas and integrity/formatting of formulas are extremely clear) or write it out by hand and attach a scan or photo of your work. Remember that all assignments must reflect your own...
Due Sept 25th at 11:55 pm You are going to make an advanced ATM program When...
Due Sept 25th at 11:55 pm You are going to make an advanced ATM program When you run the program, it will ask you if you want to: Either log in or make a new user Exit Once I have logged in, I will have 3 balances, credit, checking, and savings. From here it will ask which account to use. Once the account is picked they can deposit, withdraw, check balance, or log out. Each time the user performs one...
COMP1805AB (Fall 2019)  "Discrete Structures I" Specification for Assignment 1 of 4 Please ensure that...
COMP1805AB (Fall 2019)  "Discrete Structures I" Specification for Assignment 1 of 4 Please ensure that you include your name and student number on your submission. Your submission must be created using Microsoft Word, Google Docs, or LaTeX. Translate the following English expressions into logical statements. You must explicitly state what the atomic propositions are (e.g., "Let p be proposition ...") and then show their logical relation. If it is red then it is not blue and it is not...
This due Monday 11:59PM From this article Barnes, H. (2015). Exploring the Factors that Influence Nurse...
This due Monday 11:59PM From this article Barnes, H. (2015). Exploring the Factors that Influence Nurse Practitioner Role Transition. The Journal for Nurse Practitioners : JNP, 11(2), 178–183. http://doi.org/10.1016/j.nurpra.2014.11.004 Do Literature Review . The review of literature is a critical, analytical summary and synthesis of the current knowledge of your research topic. Thus it should compare and relate different theories, findings, etc., rather than just summarize them individually.
Weekly Discussion (Due Today by 11:59PM) No unread replies.No replies. Prepare a comparative chart based on...
Weekly Discussion (Due Today by 11:59PM) No unread replies.No replies. Prepare a comparative chart based on the physical differences you would see when performing a physical survey of a client who had good nutritional status versus a client with poor nutritional status. Grading Rubric to Achieve the Full 5 Points (See Grading Rubric for Complete Grading Breakdown) Demonstrates critical thinking. Student answers question(s) and relates key points to the discussion topic. Student uses Internet sources from acceptable research sites (see...
Deadline Due by the end of Week 5 at 11:59pm, ET. Directions Prepare an intra-office memorandum...
Deadline Due by the end of Week 5 at 11:59pm, ET. Directions Prepare an intra-office memorandum for the senior partner explaining how a case management program might be used to organize a case. Specifically explain how the program can help a trial attorney in each phase of the case: Case Intake Investigation Discovery Settlement Negotiations Trial Your memorandum should be a minimum of two pages in length and contain proper spelling and grammar.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT