Question

Computer Architecture

Project Description:

You will learn how fractions (floating point numbers) are stored in the computer and how to use MIPS assembly language instructions to work with such numbers In statistics, arithmetic mean μ (or simply mean, average, or expected value) of a series ao» a1, аз, aN-1 is defined as: Write an assembly program named average.asm that reads a list of floating point numbers from the keyboard and displays the measure given above on the simulators console The input specifications are given below . Prompt the user for the number of floating point values that the user will enter. You MUST save this number as in integer or 10 points are deducted from the assignment. Later you will need to convert it to a float. By using a loop, repeatedly prompt the user to enter the floating point numbers. You may read the floating point number the user entered into a floating point register. Assume the format for the number to enter is 3 decimal numbers, one for the integer part and two numbers after the decimal point; e.g. the user may enter 4.29,-5.90, 0.02, etc. » For example, given the following input: A [0.11 0.34 1.23 5.34 0.76 0.65 0.34 0.12 0.87 0.56] The programs output should be similar to given in the following The Mean of A 1.03 Prompt the user for each number separately. An example dialog is How many numbers would you like to average? 3 Please enter a 3 digit decimal d.dd: 4.12 Please enter a 3 digit decimal d.dd: 0.99 Please enter a 3 digit decimal d.dd: 1.87 The average is: 2.326666666666

 

File farh-to-cel.asm :

# Revised and added code taken from Hennesey and Patterson 5th edition
# to work with this simulator.
#
# Prompts a user to enter a Fahrenheit temperature as a floating point.
# Displays the converted temperature in Celcius.
# 10/28/2015

.data
const5:         .float 5.0    # store a floating point constant 5.0 
const9:         .float 9.0
const32:        .float 32.0
            .align 2   # align the next string on a word boundary
                .space 100
prompt:     .asciiz  "Please enter Farh as a float:\n"
                .align 2   #align next prompt on a word boundary

constfahr:  .float 1   # will hold the user's input 

                .text
                .globl  main
main:  
###############################################################
# system call to prompt user
                la $a0,prompt           # system call 4 for print string needs address of string in $a0
                li $v0,4                        # system call 4 for print string needs 4 in $v0
                syscall 
###############################################################
# system call to store user input of a float into register $f0
                li $v0,6                     # system call 6 for reading a float is required in $v0
                syscall              # the user's input is placed in register $f0
###############################################################
# do the conversion from Fahrenheit to Celcius
                mov.s $f12, $f0              # load the value wanting to convert from Fahr to Celcius
f2c:    lwc1 $f16, const5($zero)     #load 5.0
                lwc1 $f18, const9($zero)     # load 9.0
                div.s $f16, $f16, $f18       # $f16 =  5.0 / 9.0
                lwc1 $f18, const32($zero)    # load 32.0
                sub.s $f18, $f12, $f18       #  $f18 = fahr - 32
                mul.s $f0, $f16, $f18        # $f0 gets the result of ((5.0/9.0)*(fahr - 32.0))
# http://www.h-schmidt.net/FloatConverter/IEEE754.html  can be used to convert the result in $f0
# from single precision float to a decimal number (we should know how to do by hand too!)

###############################################################
# system call to print the float in register $f12
        mov.s $f12, $f0
                li $v0,2                     # system call 2 to print a float is required in $v0
        syscall              # the user's input is placed in register $f0
###############################################################
# Exit gracefully
         li   $v0, 10       # system call for exit
         syscall            # close file
###############################################################
0 0
Add a comment Improve this question Transcribed image text
Answer #1


.data
prompt1: .asciiz "Daniel Bevilacqua's Floating Point Average Calculator \n"
prompt2: .asciiz "How many numbers would you like to average? "
prompt3: .asciiz "Please enter a 3 digit decimal d.dd: "
prompt4:   .asciiz "The average is: "

newline: .asciiz "\n"
               .text
          .globl main
main:
        la      $a0, prompt1    # prints prompt1
        li      $v0, 4               
        syscall       

        la      $a0, prompt2    # prints prompt2
        li      $v0, 4               
        syscall       

        li      $v0, 5          # reads in an integer (number of floats to average)
        syscall
      
        add $s0, $v0, $zero   # Stores number of floats
      
        mtc1 $v0, $f1       # puts user input, $v0 into $f1
        cvt.s.w $f1, $f1   # Convert from integer into single precision float point
      
        jal dataCollect
      
        jal averageLoop

   # system call to exit the program
        li $v0, 10
        syscall

dataCollect:
   bge $t0, $s0, exit
  
   la      $a0, prompt3   # prints prompt3
        li      $v0, 4               
        syscall       
      
        li      $v0, 6            # read the float the user input
        syscall
  
   add.s $f2, $f2, $f0   # adds float inputs
   addi $t0, $t0, 1
   j dataCollect
exit:
   jr $ra
averageLoop:
   div.s $f3, $f2, $f1
  
   la      $a0, newline    # prints an endl for beauty
        li      $v0, 4
        la      $a0, prompt4    # prints the average prompt for user understanding
        li      $v0, 4                  
        syscall
          
   mov.s $f12, $f3     # loads the final answer to be displayed
   li $v0, 2
   syscall
  
   jr $ra
  

Add a comment
Know the answer?
Add Answer to:
Computer Architecture Project Description: farh-to-cel.asm : # Revised and added code taken from Hennesey and Patterson...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (Mips) The below program is "Broken" , what 4 instructions need to be added to fix...

    (Mips) The below program is "Broken" , what 4 instructions need to be added to fix it, make sure you care clear where the instructions are added in the program. .data input : .asciiz "\nPlease Enter the Temperature in Fahrenheit:" Output: .asciiz"\nThe Temperature in Celsius is:" zero1: .float 0.0 onept8:.float 1.8 thirty2: .float 32.0 .text .global main main: la $a0,input li $v0,4 syscall #print input String li $v0,6 syscall #read floating point number in $f0 l.s $f4, zero1 #initialize $f4...

  • CSE/EEE230 Assignment11 Due Date Thursday, April 25th, 5pm Note: the lowest scored assignment wil...

    CSE/EEE230 Assignment11 Due Date Thursday, April 25th, 5pm Note: the lowest scored assignment will be dropped. Important: This is an individual assignment. Please do not collaborate. It must be submitted on-line (Blackboard). No late assignment will be accepted Minimal Submitted Files You are required to turn in the following source file: assignment11.s Objectives: -write assembly language programs to:             -perform arithmetic on floating point numbers             -use syscall operations to display floating point numbers and strings on the console window             -use syscall...

  • Calculator Project

    AssignmentYou will be designing a calculator complete with user interface to take input from the user, process a response, and produce the output.Step 1: Present a menuFirst thing you should do is present a menu to the user when your program is first ran. Make sure that the operations match the numbers presented below, otherwise the graders won't be able to grade your program.1. Cartesian distance 2. Vector x matrix 3. Normalize 4. Quit Enter command:You will present the menu and wait for the user to input their...

  • For this c++ assignment, Overview write a program that will process two sets of numeric information....

    For this c++ assignment, Overview write a program that will process two sets of numeric information. The information will be needed for later processing, so it will be stored in two arrays that will be displayed, sorted, and displayed (again). One set of numeric information will be read from a file while the other will be randomly generated. The arrays that will be used in the assignment should be declared to hold a maximum of 50 double or float elements....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT