Assignment Description: Write a MIPS assembly language program that prompts for
ID: 3555824 • Letter: A
Question
Assignment Description:
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. Then the program should
display the array content on the console window. Then it should find the number that is computed by
the following C program.
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
1 of 4
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
------------------------------------------
Explanation / Answer
.data array: .space 40 prompt: .asciiz "Enter a number: " spacee: .asciiz " " output: .asciiz "The numbers are: " .text main: li $t1,10 #load 10 into $t1 la $a1,array #load a pointer to array into $a1 loop: addi $t1,$t1,-1 #subtract 1 from $t1, save to $t1 li $v0,4 #load 4 into $v0 (print string) la $a0,prompt #load prompt text into $a syscall #display prompt li $v0,5 #load 5 into $v0 (read integer) syscall #prompt for input sw $v0,0($a1) #store input int to array addi $a1,$a1,4 #add 4 to $a1, save to $a1 bnez $t1,loop #if $t1 isn't zero,goto loop li $t1,9 #if $t1 is zero, load 9 into $t1 li $t2,9 #and load 9 into $t2 la $a1,array #load array pointer into $a1 loop1: beqz $t2,here #if $t2 is zero, goto here addi $t2,$t2,-1 #subtract 1 from $t2, save to $t2 lw $t5,0($a1) #load an input int into $t5 lw $t6,4($a1) #load the next one into $t6 addi $a1,$a1,4 #add 4 to $a1, save to $a1 ble $t5,$t6,loop1 #if $t5Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.