re VAX CRC Instruction
utzoo!decvax!cca!hplabs!hao!csu-cs!bentson at sri-unix
utzoo!decvax!cca!hplabs!hao!csu-cs!bentson at sri-unix
Sun Nov 14 01:15:44 AEST 1982
I've dug up some old code that I wrote about a
year ago to make use of the CRC command. As you
can see in the C code equivalent, the instruction
is rather simple in its execution. It computes
the partial remainder of the modulus division a
nibble at a time. For more information about the
method used, see "An Efficient Software Method for
Implementing Polynomial Error Detection Codes,"
Joseph S. Whiting, Computer Design, March 1975.
Here's a use of the CRC command. I had to peek in
the VMS code to get it correct. As I remember, the
first argument was the tricky one.
/* crc tbl.ab, inicrc.rl, strlen.rw, stream.ab => R0 */
.text
.align 1
.globl _calcbcc
_calcbcc:
.word 0x0ffe
crc *4(ap),8(ap),12(ap),*16(ap)
ret
Here's the equivalent code to calculate the
CRC using partial modulus division */
calcbcc(table,initcrc,len,buf)
long table[];
long initcrc;
int len;
char *buf;
{
int inibble;
while(len--){
inibble=(*buf ^ initcrc) & 0xf;
initcrc = (initcrc>>4) ^ table[inibble];
inibble=((*buf++)>>4 ^ initcrc) & 0xf;
initcrc = (initcrc>>4) ^ table[inibble];
};
return(initcrc);
}
Here's what you've asked for: the code to generate
the table that the CRC command requires.
tablegen(poly,table)
long poly,
*table;
{
int index,
i;
long tmp,
x;
for(index=0;index<16;index++){
tmp=index;
for(i=0;i<4;i++){
x = tmp & 1;
tmp = (tmp>>1);
if (x)
tmp=tmp ^ poly;
};
table[index]=tmp;
};
};
This is used to test the use of the table and
the CRC command invocation.
main()
{
long table[16];
char *ts;
int index;
tablegen(0120001,table);
for(index=0;index<16;index++)
printf("%4X%s",table[index],((index+1)%4)?" ":"\n");
ts = "\005\006\300\000\000\001";
printf("STRT %x\n",calcbcc(table,0,6,ts));
ts[1]='\007';
printf("STACK %x\n",calcbcc(table,0,6,ts));
printf("End of test\n");
/* as might be guessed, I was looking at
implementing DDCMP */
}
My apologies for the lack of further description,
Randy Bentson
Colo State U - Comp Sci
More information about the Comp.sources.unix
mailing list