Microchip Technology XC8 Standard Compiler (Workstation) SW006021-1 SW006021-1 User Manual

Product codes
SW006021-1
Page of 518
MPLAB
®
 XC8 C Compiler User’s Guide
DS52053B-page 306
 2012 Microchip Technology Inc.
8.6.1.5
-CK
The -CK option is for calculating a checksum. The usage of this option is:
-CK=start-end@destination [+offset][wWidth][tCode][gAlogithm]
where:
• start and end specify the address range over which the checksum will be 
calculated.
• destination is the address where the checksum result will be stored. This 
value cannot be within the range of calculation.
• offset is an optional initial value to add to the checksum result.
• Width is optional and specifies the byte-width of the checksum result. Results 
can be calculated for byte-widths of 1 to 4 bytes. If a positive width is requested, 
the result will be stored in big-endian byte order. A negative width will cause the 
result to be stored in little-endian byte order. If the width is left unspecified, the 
result will be 2 bytes wide and stored in little-endian byte order.
• Code is a hexadecimal code that will trail each byte in the checksum result. This 
can allow each byte of the checksum result to be embedded within an instruction. 
• Algorithm   is an integer to select which HEXMATE algorithm to use to calculate 
the checksum result. A list of selectable algorithms are given in Table 8-9. If 
unspecified, the default checksum algorithm used is 8 bit addition (1).
A typical example of the use of the checksum option is:
-CK=0-1FFF@2FFE+2100w2
This will calculate a checksum over the range 0-1FFFh and program the checksum 
result at address 2FFEh. The checksum value will be offset by 2100h. The result will 
be two bytes wide.
TABLE 8-9:
HEXMATE
 CHECKSUM ALGORITHM SELECTION
Selector
 Algorithm description
-4
Subtraction of 32 bit values from initial value
-3
Subtraction of 24 bit values from initial value
-2
Subtraction of 16 bit values from initial value
-1
Subtraction of 8 bit values from initial value
1
Addition of 8 bit values from initial value
2
Addition of 16 bit values from initial value
3
Addition of 24 bit values from initial value
4
Addition of 32 bit values from initial value
7
Fletcher’s checksum (8 bit)
8
Fletcher’s checksum (16 bit)