On Tue, 25 Feb 1997, Riccardo Bianchi wrote: > I'm looking for a way for implementing CRC calculation on C84. > I'm crazy? May be! I do not think that you are crazy at all. Bellow you will find a routine that I wrote in X86 assembler that does One Pass per Byte and accumulate the CRC16 of a message (routine CRC16) and a routine that checks a buffer to see if a recieved CRC16 is valid (routine ck_crc16). My only request is that after you modify it to PIC assembler you share it with the list. Chaipi PS. Do not ask me how it works, it DOES. ;***************************************************************************** ;* * ;* ROUTINE : ck_crc16 * ;* * ;* PROGRAMMER : CHAIPI WIJNBERGEN * ;* LAST REVISED : 26.01.1986 * ;* * ;* INPUT : data in a buffer pointed by a pointer in stack * ;* OUTPUT : crc16 calculated & returned AX * ;* * ;* DESTROYS : none * ;* * ;* CALLED BY : c program * ;* CALLING : crc16 * ;* * ;***************************************************************************** _ck_crc16 proc far save bp mov bp,sp save ax,bx,cx,si,es ; macro push registers mov si,ss:[bp+6] ;get pointer offset from stack mov ax,ss:[bp+8] ;get pointer segment mov es,ax ;use es sub ax,ax sub bx,bx sub cx,cx mov cl,es:byte ptr [si+len] ;length of data filed add cx,head_crc ;add header+type+len char1: cmp cx,0 ;end of buffer count? jz buf_end1 ;yes get out mov ah,es:byte ptr [si] ;get data byte from buf inc si ;point to next char in buffer call _crc16 ;calculate crc16 dec cx ;decrement counter jmp char1 buf_end1: mov es:byte ptr [si-2],0 mov _crc,bx ;save last crc16 restore bp,ax,bx,cx,si,es ; macro pop resgisters ret _ck_crc16 endp ;***************************************************************************** ;* * ;* ROUTINE : crc16 * ;* * ;* PROGRAMMER : CHAIPI WIJNBERGEN * ;* LAST REVISED : 15.01.1986 * ;* * ;* INPUT : AL = next char from buffer * ;* OUTPUT : BX = crc16 calculated & updated * ;* * ;* DESTROYS : none * ;* * ;* CALLED BY : make buf * ;* CALLING : none * ;* * ;***************************************************************************** _crc16 proc near xor bh,ah mov ah,bh shl ah,1 mov al,0 rcl al,1 xor ah,bh rcl ah,1 rcl al,1 xor al,bl test bh,bh jpe odd xor ax,0380h odd: mov bh,al mov bl,ah ret _crc16 endp crc16_TEXT ends END \\\|/// \\ ~ ~ // ( @ @ ) ----------------------------oOOo-(_)-oOOo-------------------------------------- ! ! ! Chaipi Wijnbergen ! ! Electronics/Computer Eng. M.Sc. Tel : +972-8-9343079 ! ! Optical Imaging Laboratory Fax : +972-8-9344129 ! ! Brain Research Center Email : chaipi@tohu0.weizmann.ac.il ! ! Weizmann Institute of Science URL : http://www.weizmann.ac.il/~chaipi ! ! Rehovot 76100 ISRAEL IPhone : chaipi ! ! ! ------------------------------------Oooo.-------------------------------------- .oooO ( ) ( ) ) / \ ( (_/ \_)