Question

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 operations to read floating point numbers from the keyboard.

Assignment Description:

Write a MIPS assembly language program that prompts for a user to enter how many floating point numbers to enter, then prompts to enter a series of floating point numbers and reads in numbers and store them in an array, then asks a user how many small numbers to print, and computes and prints them.

Consult the green sheet and the chapter 3 for assembly instructions for floating point numbers. Here is one instruction that you might use:

c.lt.s   $f2, $f4
bc1t   Label1

Here if the value in the register $f2 is less than the value in $f4, it jumps to the Label1. If it should jump when the value in the register $f2 is NOT less than the value in $f4, then it should be:

c.lt.s   $f2, $f4
bc1f   Label1

To load a single precision floating point number (instead of lw for an integer), you might use:

l.s   $f12, 0($t0)

To store a single precision floating point number (instead of sw for an integer), you might use:

s.s   $f12, 0($t0)

To assign a constant floating point number (instead of li for an integer), you might use:

li.s    $f12, 123.45

To copy a floating point number from one register to another (instead of move for an integer), you might use:

mov.s    $f10, $f12

The following shows the syscall numbers needed for this assignment.

System Call           System Call                           System Call
Number                  Operation                              Description

2                              print_float             $v0 = 2, $f12 = float number to be printed
4                              print_string           $v0 = 4, $a0 = address of beginning of ASCIIZ string
6                              read_float              $v0 = 6; user types a float number at keyboard; value is stored in $f0
8                              read_string            $v0 = 8; user types a string at keybd; addr of beginning of string is stored in $a0; len in $a1

------------------------------------------
C program will ask a user how many floating numbers will be entered,
then read floating point numbers and store them in an array.
Then it asks a user how many smallest numbers to print, then print that many smallest numbers.
-------------------------------------------
void main( )
 {
 int arraysize = 25;
 float array[arraysize];
 int i, j, howMany, howManySmall;
 float num, temp;
 
 printf("Specify how many numbers should be stored in the array (at most 25):\n");
 scanf("%d", &howMany);
 
 //The following loop reads in floating point numbers
 //and stores them into the array
 i = 0;
 while (i < arraysize && i < howMany)
   {
     printf("Enter a number:\n");
     
     //read an integer from a user input and store it in num
     scanf("%f", &num);
     
     array[i] = num;
     i++;
   }
     
 //Print out each number in the array
 printf("The original array contains the following:\n");
 i = 0;
 while (i < arraysize && i < howMany)
   {
     printf("%f\n", array[i]);
     i++;
   }
     
     
  printf("Specify how many small numbers to print:\n");
  scanf("%d", &howManySmall);
     
  int minIndex;
  for (i = 0; i < howManySmall && i < arraysize-1 && i < howMany; i++)
   {
     minIndex = i;
     for (j = i+1; j < arraysize && j < howMany; j++)
       {
         if (array[j] < array[minIndex])
           {
             minIndex = j;
           }
       }
     temp = array[i];
     array[i] = array[minIndex];
     array[minIndex] = temp;
     
     printf("The smallest #%d : %f\n", (i+1), array[i]);
   }

   return;
 }

Here are sample outputs (user input is in bold): -- note that you might get some rounding errors.

Specify how many numbers should be stored in the array (at most 25):
14
Enter a number:
3.2
Enter a number:
6.43
Enter a number:
-3.23
Enter a number:
4.3
Enter a number:
4.3
Enter a number:
-3.24
Enter a number:
-5.4
Enter a number:
3.2
Enter a number:
3.2
Enter a number:
5.1
Enter a number:
6.5
Enter a number:
8.8
Enter a number:
8.8
Enter a number:
9.9
The original array contains the following:
3.200000
6.430000
-3.230000
4.300000
4.300000
-3.240000
-5.400000
3.200000
3.200000
5.100000
6.500000
8.800000
8.800000
9.900000
Specify how many small numbers to print:
4
The smallest #1 : -5.400000
The smallest #2 : -3.240000
The smallest #3 : -3.230000
The smallest #4 : 3.200000

0 0
Add a comment Improve this question Transcribed image text
Answer #1

smallest.asm:

.data

string1:.asciiz "\nSpecify how many numbers should be stored in the array (at most 25):"
string2:.asciiz "\nThe original array contains the following:"
string3:.asciiz "\nSpecify how many small numbers to print:"
string4: .asciiz "\nThe smallest #"
string5: .asciiz "\nEnter a number:"
col: .asciiz " : "
newline: .asciiz "\n"
array: .float 40000
val:   .float 10000.00
.text
   li $t0,1
  
   l.s $f10,val
   la $t1, array
   li $v0,4
   la $a0,string1 #print string 1
   syscall  
  
  
   li $v0, 5
   syscall
   move $s0,$v0 #store user number of array elements
  
while:   bgt $t0,$s0,init
  
   li $v0,4
   la $a0,string5 #print string 5
   syscall  
   li $v0, 6 #gets user input floating point number and stores it into $f0
   syscall
   s.s $f0,0($t1) #store floating point number in array
   addi $t1,$t1,4
   addi $t0,$t0,1
   j while
  
  
init:   li $v0,4
   la $a0,string2 #print string 2
   syscall
   la $t1, array
   li $t0,1
  
print:   bgt $t0,$s0,final
   li $v0,4
   la $a0,newline #print new line
   syscall
  
   li $v0, 2         
   l.s $f12, ($t1)         #print array elements
   syscall  
   addi $t1,$t1,4
   addi $t0,$t0,1
   j print  
  
final:   li $v0,4
   la $a0,string3 #print string 3
   syscall
  
   li $v0, 5
   syscall
   move $s1,$v0 #store number of smallest elements to be printed
  
   li $t2,1
  
loop:   bgt $t2,$s1,end
   la $t1, array
   l.s $f6, ($t1)   #min
   li $t0,1  
in:   bgt $t0,$s0,brk
   l.s $f8,($t1)
   c.le.s $f8,$f6
   bc1t swap
   bc1f update
brk:   #add.s $f8,$f8,$f10
   s.s $f10,0($t7)  
   li $v0,4
   la $a0,string4 #print string 4
   syscall
  
   li $v0,1
   move $a0,$t2
   syscall
  
   li $v0,4
   la $a0,col #print colon
   syscall
  
   li $v0, 2         
   mov.s $f12,$f6         #print smallest element
   syscall  
   addi $t2,$t2,1
   j loop
update: addi $t1,$t1,4
   addi $t0,$t0,1
   j in  
swap:     mov.s $f6,$f8
   move $t7,$t1
   j update
end:   li $v0, 10#stop the program and exit
         syscall
        


Output:

Mars Messages Run /O ecify how many numbers should be stored in the array (at most 25):14 ter a number:3.2 nter a number:6.43

Mars Messages Run I/O ter a number:4.3 ter a number:-3.24 Clear Enter a number:-5.4 ter a number:3.2 ter a number:3.2

Mars Messages Run I/O ter a number:5.1 ter a number:6.5 ter a nunber:8.8 ter a number:8.8 ter a number:9.9 Clear

Mars Messages Run Vo If checked, will display line number for each line of text. The original array contains the following: 3

Mars Messages Run l/O 5 12.4 8 43.93 Clear Specify how many small numbers to print:4 e smallest #1 : -5.4 e smallest #2 : -3.

Add a comment
Know the answer?
Add Answer to:
CSE/EEE230 Assignment11 Due Date Thursday, April 25th, 5pm Note: the lowest scored assignment wil...
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
  • Computer Architecture Project Description: farh-to-cel.asm : # Revised and added code taken from Hennesey and Patterson...

    Computer Architecture Project Description: 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...

  • Prime Number Programing in C Note: The program is to be written using the bitwise operation....

    Prime Number Programing in C Note: The program is to be written using the bitwise operation. Use an integer array (not a Boolean array) and a bit length (for instance 32 bits). In this program you will write a C program to find all prime numbers less than 10,000. You should use 10,000 bits to correspond to the 10,000 integers under test. You should initially turn all bits on (off) and when a number is found that is not prime,...

  • Using Java In this assignment we are working with arrays. You have to ask the user...

    Using Java In this assignment we are working with arrays. You have to ask the user to enter the size of the integer array to be declared and then initialize this array randomly. Then use a menu to select from the following Modify the elements of the array. At any point in the program, if you select this option you are modifying the elements of the array randomly. Print the items in the array, one to a line with their...

  • CIST 2371 Introduction to Java Unit 03 Lab Due Date: ________ Part 1 – Using methods...

    CIST 2371 Introduction to Java Unit 03 Lab Due Date: ________ Part 1 – Using methods Create a folder called Unit03 and put all your source files in this folder. Write a program named Unit03Prog1.java. This program will contain a main() method and a method called printChars() that has the following header: public static void printChars(char c1, char c2) The printChars() method will print out on the console all the characters between c1 and c2 inclusive. It will print 10...

  • This is a quick little assignment I have to do, but I missed alot of class...

    This is a quick little assignment I have to do, but I missed alot of class due to the Hurricane and no one here knows what theyre doing. please help! this is Java with intelli-J Overview In this project students will build a four-function one-run calculator on the command line. The program will first prompt the user for two numbers, then display a menu with five operations. It will allow the user to select an option by reading input using...

  • In this assignment you are to utilize the Node data structure provided on Blackboard. In this...

    In this assignment you are to utilize the Node data structure provided on Blackboard. In this assignmet you are to write a main program that implements two methods and a main method as their driver. So, only main and two methods with it. Note: You may not use any of the LinkedList class provided on Blackboard, you may use the methods in it as a guide (you should actually look at them) but you cannot use any of the methods...

  • 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....

  • NOTE: ALL C PROGRAMS MUST BE DONE IN UNIX SYSTEM WITH VI EDITOR 1. Write a...

    NOTE: ALL C PROGRAMS MUST BE DONE IN UNIX SYSTEM WITH VI EDITOR 1. Write a program that asks the user to enter a U.S. dollar amount and then shows how to pay that amount using the smallest number of $20, $10, $5 and $1 bills. Save the file as dollarAmountToNotesFirstinitialLastname.c Sample output: Enter a dollar amount: 93 $20 bills: 4 $10 bills: 1 $5 bills: 0 $1 bills: 3 Hint: Divide the amount by 20 to determine the number...

  • Questin 1 (CO 2) Which of the following is not a valid name in python? last_name...

    Questin 1 (CO 2) Which of the following is not a valid name in python? last_name lastName last name lname Question 2 (CO 3) How many times will “Hello World” be displayed after the following code executes? num=2 while num<12:     print("Hello world")     num+=2 2 12 5 4 Question 3 (CO 1) The following code contains an error, what type of error is it and what line number is it? 1 count=1 2 while count<4 3    print("count = ",...

  • In C++ Please please help.. Assignment 5 - Payroll Version 1.0 In this assignment you must create and use a struct to hold the general employee information for one employee. Ideally, you should use an...

    In C++ Please please help.. Assignment 5 - Payroll Version 1.0 In this assignment you must create and use a struct to hold the general employee information for one employee. Ideally, you should use an array of structs to hold the employee information for all employees. If you choose to declare a separate struct for each employee, I will not deduct any points. However, I strongly recommend that you use an array of structs. Be sure to read through Chapter...

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