Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a MIPS assembly language program that prompts for a user to enter a series

ID: 3766115 • Letter: W

Question

Write a MIPS assembly language program that prompts for a user to enter a series of floating point numbers and calls read_float to read in numbers and store them in an array only if the same number is not stored in the array yet. Then the program should display the array content on the console window.

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

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

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

c.eq.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 store in $f0
8                              read_string            $v0 = 8; user types string at keybd; addr of beginning of string is store in $a0; len in $a1

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

Enter a number:
3
Enter a number:
54.4
Enter a number:
2
Enter a number:
5
Enter a number:
2
Enter a number:
-4
Enter a number:
5
Enter a number:
76
Enter a number:
-23
Enter a number:
43.53
Enter a number:
-43.53
Enter a number:
43.53
Enter a number:
65.43
The array contains the following:
3.00000000
54.40000153
2.00000000
5.00000000
-4.00000000
76.00000000
-23.00000000
43.52999878
-43.52999878
65.43000031

Explanation / Answer

Given below is the MIPS code for the question . Output also shown. Please don't forget to rate the answer if it helped. Thank you.

.data

arraysize: .word 10

array: .float 0.0:10

prompt1: .asciiz "Enter a number: "

msg1: .asciiz "The array contains the following: "

newline: .asciiz " "

.text

#store size of array in t0

lw $t0, arraysize

la $t1, 0 #offset

li $t2, 0 #index

loop1:

bge $t2, $t0, loop1_end #reached end of array

#prompt the user

la $a0, prompt1

li $v0, 4

syscall

#read the float number

li $v0, 6

syscall

mov.s $f1, $f0

li $t3, 0 #offset

li $t4, 0 #alreadystored = 0

loop2:

bge $t3, $t1, loop2_end

l.s $f2, array($t3)

c.eq.s $f1 $f2

bc1f loop2_next

li $t4, 1

loop2_next:

addi $t3, $t3, 4

b loop2

loop2_end:

beq $t4, 1, loop1 #already in array

s.s $f1, array($t1)

addi $t1, $t1, 4 #increment offset

addi $t2, $t2, 1 #increment index

b loop1

loop1_end:

#print the array

la $a0, msg1

li $v0, 4

syscall

li $t1, 0 #offset is 0

li, $t2, 0 #index

loop3:

bge $t2, $t0, loop3_end

l.s $f12, array($t1)

li $v0, 2

syscall

la $a0, newline

li $v0, 4

syscall

addi $t2, $t2, 1 #increment index

addi $t1, $t1, 4 #increment offset

b loop3

loop3_end:

#exit

li $v0, 10

syscall

  

output

Enter a number: 3

Enter a number: 54.4

Enter a number: 2

Enter a number: 5

Enter a number: 2

Enter a number: -4

Enter a number: 5

Enter a number: 76

Enter a number: -23

Enter a number: 43.53

Enter a number: -43.53

Enter a number: 43.53

Enter a number: 65.43

The array contains the following:

3.0

54.4

2.0

5.0

-4.0

76.0

-23.0

43.53

-43.53

65.43

-- program is finished running --

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote