.text

# -----------------------------------------------------------------------------
# main:
#
# Entry point
#
# Args:
#   N/A
#
# Returns:
#   N/A
# -----------------------------------------------------------------------------
main:
    # Compute the roots
    li          a0, 100
    jal         to_double
    # Print the results
    li          a7, 3           # Print double
    ecall
    li          a7, 11          # Print char
    li          a0, '\n'        # a0 <- '\n'
    ecall
    # Exit
    li          a7, 10          # Exit without errors
    ecall

# -----------------------------------------------------------------------------
# to_double:
#
# Convert the input to a double & add 10.
#
# Args:
#   a0: x
#
# Returns:
#   fa0: float(x) + 10
# -----------------------------------------------------------------------------
to_double:
    # Save the stack
    addi        sp, sp, -16
    sw          ra,  0(sp)
    sw          s0,  4(sp)
    fsd         fs0, 8(sp)
    # Convert to a float
    fcvt.d.w    fs0, a0         # fs0 <- float(x)
    li          t0, 10          # t0 <- 10
    fcvt.d.w    ft0, t0         # ft0 <- 10.0
    fadd.d      fs0, fs0, ft0   # fs0 <- float(x) + 10.0
    fmv.d       fa0, fs0        # fa0 <- fs0
    # Restore the stack
    lw          ra,  0(sp)
    lw          s0,  4(sp)
    fld         fs0, 8(sp)
    addi        sp, sp, 16
    ret
