Log in

View Full Version : Asm help needed: What type of CRC is this?


morlac
February 9th, 2001, 09:32
Im trying to figure what type of a CRC this is code generate with no luck, assuming that its a CRC function:

--------------------------------------
push esi
mov edx, [esp+arg_0]
sub ax, ax
mov ecx, [esp+arg_4]
cmp ecx, edx
jbe short exit
loop:
mov si, ax
shr si, 0Fh
add ax, ax
or si, ax
mov al, [edx]
and eax, 0FFFF00FFh
add ax, si
inc edx
cmp ecx, edx
ja short loop
exit:
pop esi
retn 8
--------------------------------------

Can anybody help?

Best regards,
Morlac

Anonymous
February 11th, 2001, 15:23
It's the summation of m terms (n-1)=(n-1)*2 MOD 65535 + n, where n is the nth term: it looks like a checksum calculation.

IcyDee
February 11th, 2001, 15:40
That eqn. is not right, what about all those OR's and right shifts etc.

Anonymous
February 11th, 2001, 16:35
Quote:
IcyDee (02-11-2001 04:43):
That eqn. is not right, what about all those OR's and right shifts etc.


push esi
mov edx, [esp+arg_0]<=pointer to the first item
sub ax, ax <=initialize
mov ecx, [esp+arg_4]<=pointer to the last item
cmp ecx, edx
jbe short exit
loop:
mov si, ax
shr si, 0Fh <=this means:"put 1 in SI if SI signed value
is negative, 0 if SI is positive"
add ax, ax <=this means:"multiply current item by two,
in a 16 bit register"
or si, ax <=this means:"if last sum result is negative,
complement the value (set bit 0 to 1
if ax signed value was negative)"
mov al, [edx] <=next item in AL
and eax, 0FFFF00FFh <=mask AH with zeroes
add ax, si <=sum next item
inc edx
cmp ecx, edx <=finished?
ja short loop
exit:
pop esi
retn 8

This is the significance of "all those OR's and right shifts etc.". It's sufficient that you write a small program in C that contains a vector of values and the equation:

item=item*2e535+vector[counter];

and then put in an Assembler skeleton the assembly routine, and compare the results. In this way "all those OR's and right shifts etc." will become clear.
Regards

morla
February 12th, 2001, 08:52
Thankx guy. This was a great help.

Thankx again