Next: Register Caching, Previous: Register Information Functions, Up: Register Representation

#### 11.6.4 Using Different Register and Memory Data Representations

Some architectures have different representations of data objects, depending whether the object is held in a register or memory. For example:

- The Alpha architecture can represent 32 bit integer values in floating-point registers.
- The x86 architecture supports 80-bit floating-point registers. The `long double` data type occupies 96 bits in memory but only 80 bits when stored in a register.

In general, the register representation of a data type is determined by the architecture, or gdb's interface to the architecture, while the memory representation is determined by the Application Binary Interface.

For almost all data types on almost all architectures, the two representations are identical, and no special handling is needed. However, they do occasionally differ. An architecture may define the following `struct gdbarch` functions to request conversions between the register and memory representations of a data type:

— Architecture Function: int gdbarch_convert_register_p (struct gdbarch *gdbarch, int reg)

> Return non-zero (true) if the representation of a data value stored in this register may be different to the representation of that same data value when stored in memory. The default value is `NULL` (undefined).

> If this function is defined and returns non-zero, the `struct gdbarch` functions `gdbarch_register_to_value` and `gdbarch_value_to_register` (see below) should be used to perform any necessary conversion.

> If defined, this function should return zero for the register's native type, when no conversion is necessary.

— Architecture Function: void gdbarch_register_to_value (struct gdbarch *gdbarch, int reg, struct type *type, char *from, char *to)

> Convert the value of register number reg to a data object of type type. The buffer at from holds the register's value in raw format; the converted value should be placed in the buffer at to.

> > Note: `gdbarch_register_to_value` and `gdbarch_value_to_register` take their reg and type arguments in different orders.

> `gdbarch_register_to_value` should only be used with registers for which the `gdbarch_convert_register_p` function returns a non-zero value.

— Architecture Function: void gdbarch_value_to_register (struct gdbarch *gdbarch, struct type *type, int reg, char *from, char *to)

> Convert a data value of type type to register number reg' raw format.

> > Note: `gdbarch_register_to_value` and `gdbarch_value_to_register` take their reg and type arguments in different orders.

> `gdbarch_value_to_register` should only be used with registers for which the `gdbarch_convert_register_p` function returns a non-zero value.