Vault 7: Projects
This publication series is about specific projects related to the Vault 7 main publication.
Fixed-Point Arithmetic Support
2012-2013 Microchip Technology Inc. DS50002071C-page 141
9.6 EXTERNAL DEFINITIONS
The MPLAB XC16 C compiler provides an include file, stdfix.h, which provides con-
stant, pragma, typedef, and function definitions as described in section 7.18a of N1169.
Fixed point conversion specifiers for formatted I/O, as described in section 4.1.9 For-
matted I/O functions for fixed-point arguments of N1169, are not supported in the cur-
rent MPLAB XC16 standard C libraries. Fixed-point variables may be displayed via
(s)printf by casting them to the appropriate floating point representation (double
for _Fract, long double for long _Fract and _Accum), and then displaying the
value in that format. To scan a fixed-point number via (s)scanf, first scan it as the
appropriate double or long double floating point number, and then cast the value
obtained to the desired fixed-point type.
The fixed point functions described in section 4.1.7 of N1169 are not provided in the
current MPLAB XC16 standard C libraries.
Fixed point constants, with suffixes of k (K) and r (R), as described in section 4.1.5 of
N1169, are supported by the MPLAB XC16 C compiler.
9.7 MIXING C AND ASSEMBLY LANGUAGE CODE
The MPLAB XC16 C compiler generates fixed-point code that assumes that certain
16-bit device resources are managed by the compiler's start-up and run-time code.
Hand-written assembly code built into the same program could interfere with the state
of the CPU assumed by the code the compiler generates.
MPLAB XC16 programs may contain both fixed-point C and assembly language code
that utilizes 16-bit device intrinsic fixed-point capabilities directly, but in order for these
two kinds of code to inter-operate safely, the compiler must save certain dsPIC regis-
ters around calls to assembly language functions that may change their state. The C
compiler can be instructed to do so by providing prototypes for assembly language
functions for which this is necessary. These prototypes should specify the
save(CORCON) attribute for the target assembly language function, as described in
Section 13.2.2 Function Attributes. Programs constructed in this manner will oper-
ate correctly, at the expense of some state saves and restores around calls to the indi-
cated assembly routines.
Protego_Release_01_05-Related-OEM-Documentation-MPLAB-XC16-C-Compiler.pdf