📄 cksum.c
字号:
#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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -