Floating Point Numbers but the output is always 0

24 Views Asked by At

The program is running but the output is wrong. I am also getting an "Odd FP double register number"

Output Example

Below is the code for the program:

.data
    prompt1: .asciiz "Enter a decimal number with at least 5 decimal places: "
    prompt2: .asciiz "Enter a precision value between 1 and 4: "
    error1: .asciiz "Invalid input. Please enter a valid decimal number: "
    error2: .asciiz "Invalid precision value. Please enter a precision value between 1 and 4: "
    original: .asciiz "The original number entered was: "
    selected: .asciiz "You selected to set the precision to: "
    newline: .asciiz "\n"
    message: .asciiz "Enter 1 to try again or 0 to exit: "

input: .space 50

.text
main:
    li $t2, 1

while:
    beq $t2, $zero, exit

    li $v0, 4
    la $a0, prompt1
    syscall

    li $v0, 8
    la $a0, input
    li $a1, 50
    syscall

    l.d $f2, input
    j check_input

check_input:
    li $v0, 4
    la $a0, original
    syscall
    li $v0, 3
    mov.d $f12, $f0
    syscall
    li $v0, 4
    la $a0, newline
    syscall

    li $v0, 4
    la $a0, prompt2
    syscall

    li $v0, 5
    syscall
    move $t0, $v0

    blt $t0, 1, invalid
    bgt $t0, 4, invalid

    cvt.d.s $f1, $f2
    li $t1, 1
    blt $t1, $t0, loop
    div.d $f1, $f2, $f2
    j exit_loop

loop:
    li.d $f4, 10.0
    mul.d $f1, $f1, $f4
    cvt.w.d $f3, $f1
    cvt.d.w $f1, $f3
    div.d $f1, $f1, $f4
    sub.d $f2, $f1, $f3
    mul.d $f2, $f2, $f4
    cvt.w.d $f3, $f2
    cvt.d.w $f2, $f3
    c.lt.d $f2, $f0
    bc1t carry
    j exit_loop

carry:
    add.d $f1, $f1, $f4
    j exit_loop

exit_loop:
    addi $t1, $t1, 1
    blt $t1, $t0, loop

    li $v0, 4
    la $a0, selected
    syscall
    li $v0, 3
    mov.d $f12, $f1
    syscall
    li $v0, 4
    la $a0, newline
    syscall


    li $v0, 4
    la $a0,message
    syscall


invalid:
    li $v0, 4
    la $a0, error2
    syscall
    j while

error1_label:
    li $v0, 4
    la $a0, error1
    syscall
    j while

exit:
    li $v0, 10
    syscall

the first output should be the same as the decimal number that I inputted. the second input should be asking for the precision value before rounding off but I am getting an "Odd FP double register number" error. The error message when the precision value input is wrong is working as expected.

0

There are 0 best solutions below