RISC-V Assembler language

When discussing decimal math in assembly language within the framework of IEEE standards, it is vital to distinguish between standard binary floating-point (float and double) and true IEEE 754 Decimal Floating-Point (DFP).

In the RISC-V Instruction Set Architecture (ISA), support for IEEE 754 Decimal Floating-Point (DFP) is reserved under the "L" standard extension. Unlike the binary floating-point extensions—such as F (single precision), D (double precision), and Q (quad precision)—the L extension has a unique architectural status.


Risc-v 32-bit Assembly Language (IEEE 754 Standard)

To print a floating-point number in the RARS (RISC-V Assembler and Runtime System) simulator, use system call (ecall) service 2 for a 32-bit single-precision float or service 3 for a 64-bit double-precision float, placing the value into argument register fa0. (Place the system Service code in a0.)

RISC-V single-precision floating-point values follow the IEEE 754 binary32 standard, providing a normalized numeric range roughly from 1.18E-38 to 3.40E38 (positive and negative). (Decimal Precision is approximately 7.22 significant digits.)

RISC-V double-precision floating-point values follow the IEEE 754 binary64 standard, providing a normalized numeric from approximately 4.94E-324 to 1.79E308. (Decimal precision is approximately 15 to 17 significant digits.)

Notes:

  1. f0–f31: Dedicated floating-point registers. They also use application ABI names like ft0-ft11 (temporaries), fs0-fs11 (saved), and fa0-fa7 (arguments/return).

  2. The IEEE 754 standard for floating-point arithmetic approximate range depends on the precision format chosen.

  3. Zero: Represented by a zero exponent and zero mantissa (both positive and negative zero exist).

  4. Infinity & NaN: Encoded with an exponent field of all ones, where all-zero mantissas represent infinity and non-zero mantissas represent Not-a-Number.

  5. Operations on subnormal numbers are handled in accordance with the IEEE 754-2008 standard.

  6. The runtime environment or simulator reads the IEEE 754 single-precision float stored in f12 and outputs its decimal text representation directly to the console.

  7. RARS does not provide a direct ecall option to format floats in scientific notation. To output a float in scientific format, you must write a short routine in RISC-V assembly to extract the sign, exponent, and mantissa (fraction), manually calculate the base-10 exponent, format the string, and print it using ecall service 4 (Print String).

Links

IEEE 754 Standard for Floating Point Binary Arithmetic (YouTube)

Floating Point Numbers (YouTube)

Docs