I'm trying to store a list of floating point numbers in a dynamic array using MIPS. The program prompts the user for the number of floats to enter, and then loops while receiving the input. With integers I know how to do this, but I am having a hard time making it work with floats. Here's what I have right now. This gets the number of floats to be entered and allocates the memory accordingly:
#get number of floats to be entered li $v0, 5 syscall move $t0, $v0 #t0 is number of floats #allocate the memory required sll $a0, $v0, 2 li $v0, 9 syscall
This is the loop where I collect the floats:
move $t1, $zero #idx for loop move $t2, $v0 #t2 is address of dynamic memory loop: bge $t1, $t0, done #idx check li $v0, 4 la $a0, prompt #prompt user input syscall # read in and store int li $v0, 6 syscall sw $v0, 0($t2) addi $t1, $t1, 1 # ++idx addi $t2, $t2, 4 #add four to move to next memory location j loop done:
The output here is just 0.0 for any float that gets entered, when it should be the user entered numbers. I assume I must be storing them wrong. Is there a better way to bring in the floats than this?