cksum.c

来自「Hitech microchip PIC C18 Compiler」· C语言 代码 · 共 53 行

C
53
字号
#include <htc.h>#include "cksum.h"// Determine whether an addition or subtraction algorithm is used.#if (_ALGORITHM < 0) #define _SUM(x,y) x -= y #define _BYTEOP (_ALGORITHM * -1)#else #define _SUM(x,y) x += y #define _BYTEOP _ALGORITHM#endif// Calculate the number of iterations through the loop.#define _SIZE (( _END - _START + 1 ) / _BYTEOP)// the return type is based on _RESULT_WIDTH in cksum.h_D_TYPEcksum(void){   _D_TYPE  sum;#if _SIZE > 0xFFFF   unsigned long counter;#else   unsigned int counter;#endif	sum = _OFFSET;		// initial offset (usually zero)	counter = _SIZE;   TBLPTR=(far char *)_START;	// point to start of checksum range   while(counter){      asm("tblrd*+");      _SUM(sum,TABLAT);		// read and accumulate a byte#if _BYTEOP >= 2      asm("tblrd*+");      _SUM(sum,(TABLAT<<8));#endif#if _BYTEOP >= 3      asm("tblrd*+");      _SUM(sum,(TABLAT<<16));#endif#if _BYTEOP == 4      asm("tblrd*+");      _SUM(sum,(TABLAT<<24));#endif      counter--;   }#if (_END >= 0xFFFF) && defined(SMALL_DATA)   TBLPTRU=0;	// if this register is non-zero, it must be zeroed in this mode#endif   return sum;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?