# A program that increments a single-precision floating-point value # (starting from 1.0) by adding 10 times the value 0.1. Before each # increment, the program prints on the console a message reporting the # current value. Then, the program exits. .data # The next items are stored in the Data memory segment msg: # Label for the mem addr of the first char of the string below .string "The current value is: " # Allocate a string, in C-style: a # sequence of characters in adjacent # memory addresses, terminated with 0 .text # The next items are stored in the Text memory segment li t0, 0x3f800000 # Load this immediate value into register t0 # The value above is the 32-bit hexadecimal representation of # the single-precision floating-point number 1.0. # To convert values between floating-point and hex, see e.g.: # https://www.h-schmidt.net/FloatConverter/IEEE754.html fmv.w.x ft0, t0 # Move the content of t0 into floating-point reg ft0 # Register ft0 contains the value we will increment li t0, 0x3dcccccd # Load this immediate value into register t0 # The value above is the 32-bit hexadecimal representation of # the single-precision floating-point number 0.1 fmv.w.x ft1, t0 # Move the content of t0 into floating-point reg ft1 # Register ft1 contains the increment we will add to ft0 li t0, 0 # Load value 0 into register t0 (used as counter) li t1, 1 # Load value 1 into register t1 (used as counter increment) li t2, 10 # Load value 10 into register t2 (number of increments) loop_begin: # Label for memory location of the beginning of the loop la a0, msg # Load address of label 'msg' into a0, for printing below li a7, 4 # Load immediate value 4 into register a7 ecall # Syscall. In RARS, if a7=4, this means: "PrintString" li a7, 2 # Load value 2 into register a7 fmv.s fa0, ft0 # Copy float value in ft0 into fa0, for printing below ecall # Syscall. In RARS, if a7=2, this means: "PrintFloat" li a0, '\n' # Load value of char '\n' into a0, for printing below li a7, 11 # Load immediate value 11 into register a7 ecall # Syscall. In RARS, if a7=11, this means: "PrintChar" beq t0, t2, loop_end # If t0 and t2 are equal, jump to loop_end fadd.s ft0, ft0, ft1 # Increment the floating-point value: add the # contents of floating point registers ft0 and # ft1, write the result in ft0 add t0, t0, t1 # Increment loop couunter: add t0 and t1, result in t0 j loop_begin # Jump to the beginning of the loop loop_end: # Label for memory location of the end of the loop li a7, 10 # Load the immediate value 10 in register a7 ecall # Perform syscall. In RARS, if a7 is 10, this means: "Exit"