bit CheckPacket(void) { unsigned char idata *pBuf = g_UART0Buf; unsigned char len, checksum; if (*pBuf == PACKET_START_ID / 256) { pBuf++; if (*pBuf == PACKET_START_ID % 256) { pBuf++; len = *pBuf; checksum = *pBuf; pBuf++; len++; do { checksum += *pBuf; pBuf++; len--; } while (len); if(!checksum) { return 1; } } } return 0; }
; FUNCTION CheckPacket (BEGIN) ; SOURCE LINE # 13 ; SOURCE LINE # 14 ; SOURCE LINE # 15 E MOV R7,#LOW g_UART0Buf ;---- Variable 'pBuf' assigned to Register 'R7' ---- ; SOURCE LINE # 18 MOV R0,AR7 MOV A,@R0 XRL A,#07H R xJNZ ?C0001 ; SOURCE LINE # 19 ; SOURCE LINE # 20 INC R7 ; SOURCE LINE # 21 INC R0 MOV A,@R0 XRL A,#0EH R xJNZ ?C0001 ; SOURCE LINE # 22 ; SOURCE LINE # 23 INC R7 ; SOURCE LINE # 24 INC R0 MOV A,@R0 MOV R6,A ;---- Variable 'len' assigned to Register 'R5' ---- MOV R5,A ; SOURCE LINE # 25 ;---- Variable 'checksum' assigned to Register 'R6' ---- ; SOURCE LINE # 26 INC R7 ; SOURCE LINE # 27 INC R5 ?C0005: ; SOURCE LINE # 29 ; SOURCE LINE # 30 MOV R0,AR7 MOV A,@R0 ADD A,R6 MOV R6,A ; SOURCE LINE # 31 INC R7 ; SOURCE LINE # 32 R DJNZ R5,?C0005 ; SOURCE LINE # 33 ; SOURCE LINE # 34 R xJNZ ?C0001 ; SOURCE LINE # 35 ; SOURCE LINE # 36 SETB C RET ; SOURCE LINE # 37 ; SOURCE LINE # 38 ; SOURCE LINE # 39 ?C0001: ; SOURCE LINE # 40 CLR C ; SOURCE LINE # 41 ?C0007: RET ; FUNCTION CheckPacket (END)
6 bytes smaller than previous, and the pointer only use R0, but I don't know why.
You'd have your answers if you had the source code to the compiler. But it is closed-source, so there you have it. Obviously, it's not a professional project you are working on, since you can spend so much time on such a minor matter. Your interest would be justified if you were working on improving the compiler. Just leave it. Believe me, your time can be spent much more productively.