Loading a Real Constant

Writing code to load a floating-point or fixed-point real constant can be challenging.

There are a couple of different ways to load a floating-point constant into a register, but the best method depends on the value of the constant. The VMOV instruction is the most efficient method, but only works for a very specific set of values. A floating-point 0.0 is most easily created using VSUB.F32 to subtract a register from itself. All other values require creating the constant in memory using a .float directive, and then loading the constant into a register using the VLDR instruction.

Fixed-point reals are represented using integer data types, so loading a fixed-point constant is no more difficult than loading an integer constant. However, the challenge is determining the corresponding integer value to use.

(Click anywhere to remove this message.)

Loading a Real Constant
Revised: Thursday, 23-Jun-2022 20:37:26 PDT
Operand Data Type: float Q32.32 Q16.16
Desired Real Constant
Decimal Input:
Q32.32 Fixed-Point Real R1 R0 ARM Assembly
Representation (64 Bits):
Q16.16 Fixed-Point Real R0 ARM Assembly
Representation (32 Bits):
32-bit Floating-Point S0 ARM Assembly
Representation (32 Bits):
Accuracy
Represented Value and Error:
User
Entry
Representation Subnormal Underflow Overflow Accuracy