The
wordSize
andshift
of an object are defined by its design attributes (specified in the element properties). The MicroC Code Generator determines thewordSize
andshift
of expressions made of objects and operators by using the formulas listed in the macro definition table below.The conventions used in the table are as follows:
●
●
●
●
●
●
wordSize and shift of the left operand Converted to the FXP type of the FormalParameterIf the evaluated wordSize is greater than 32 bits, MicroC displays the following messages:
● generated code -/* Warning - Fixed- Point Overflow in Expression.*
This message is located right after the expression.When you use fixed-point variables in integer arithmetic, the special functions (or C macros) provided in the FXP package are used to perform the calculations. The following table lists these macros
FXP2INT (FPvalue, FPshift) (FPvalue >>FPshift) Converts a fixed-point number with shift=FPshift to an integer. LS_FXP2FXP8 (FPvalue, fromFPshift, toFPshift) ((sint8(FPvalue)) <<((toFPshift) - (fromFPshift))) Converts a fixed-point number with shift=fromFPshift to an 8-bit fixed-point number with shift=toFPshift using left shifting. RS_FXP2FXP8 (FPvalue, fromFPshift,toFPshift) ((sint8(FPvalue)) >>((fromFPshift) - (toFPshift))) Converts a fixed-point number with shift=fromFPshift to an 8-bit fixed-point number with shift=toFPshift using right shifting. LS_FXP2FXP16 (FPvalue, fromFPshift,toFPshift) ((sint16(FPvalue)) <<((toFPshift) - (fromFPshift))) Converts a fixed-point number with shift=fromFPshift to a 16-bit fixed-point number with shift=toFPshift by using left shifting. RS_FXP2FXP16 (FPvalue, fromFPshift,toFPshift) ((sint16(FPvalue)) >>((fromFPshift) - (toFPshift))) Converts a fixed-point number with shift=fromFPshift to a 16-bit fixed-point number with shift=toFPshift using right shifting. LS_FXP2FXP32 (FPvalue, fromFPshift,toFPshift) ((sint32(FPvalue)) <<((toFPshift) - (fromFPshift))) Converts a fixed-point number with shift=fromFPshift to a 32-bit fixed-point number with shift=toFPshift using left shifting. RS_FXP2FXP32 (FPvalue, fromFPshift,toFPshift) ((sint32(FPvalue)) >>
((fromFPshift) - (toFPshift))) Converts a fixed-point number with shift=fromFPshift to a 32-bit fixed-point number with shift=toFPshift using right shifting.