Keil Logo

Function Return Values

MCU registers pass function return values. The following table lists the return types and the registers used for each.

Return Type Register Description
bit Carry Flag Single bit returned in the carry flag
char/unsigned char,
1-byte pointer
R11 Single byte type returned in R11
int, unsigned int,
2-byte pointer
WR6 MSB in R6, LSB in R7.
long, unsigned long DR4 MSB in R4, LSB in R7
float DR4 32-Bit IEEE format: 'exponent' and 'sign' in WR4
double DR0, DR4 64-Bit IEEE format: 'exponent' and 'sign' in WR0
4-byte pointer DR0 MSB in R0, LSB in R3.

For parameter passing to C51 functions; 3 byte pointers are returned in the registers R1/R2/R3. Refer to PARM51 or PARM251 for more information.

Struct return types of structs of size [1..8] are returned in Register R0..R7, with the LSB of the last structure element always ending in R7. For example, a 3 byte structure value is returned in R5, R6, R7. A struct of size 5 is returned in R3, R4, R5, R6, R7.

Structures containing more than 8 bytes, are returned with the help of an internal memcpy function. The address of the destination has to be passed to the function at call time in DR12.

  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.