Fixed-Point Variable Support : Specifying Fixed-Point Variables : The Generated Code

The Generated Code

Fixed-point variables are implemented using uint variables (sint8, sint16, sint32), with hardcoded shift values. MicroC allocates data according to the wordSize of the variable.

:

 

All calls to functions or expressions requiring integer values are done through an FXP-to-int cast, including the test-driver/ panel driver. Specifically, the operators “ROUND” and “TRUNC” are called with an FXP-to-int cast.

For example, given a fixed-point variable fxp_var, an integer variable int_var, and the following actions:

INT_VAR := FXP_VAR + 4;
FXP_VAR := INT_VAR/5;
 
 

The generated code is as follows, if you specify fixed-point mode:

INT_VAR = RS_FXP2FXP16(FXP_VAR + LS_FXP2FXP16(0x4,
0, FXP_VAR_FXP_SHIFT), FXP_VAR_FXP_SHIFT, 0);
FXP_VAR = LS_FXP2FXP16(INT_VAR / 0x5, 0,
FXP_VAR_FXP_SHIFT);