News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

CRC24

Started by guga, October 09, 2022, 05:12:54 AM

Previous topic - Next topic

guga

Someone has a working faster example of a CRC24 function in masm ?

I tried to port this C example, but it is too slow:


  #define CRC24_INIT 0xB704CEL
  #define CRC24_POLY 0x1864CFBL

  typedef long crc24;
  crc24 crc_octets(unsigned char *octets, size_t len)
  {
      crc24 crc = CRC24_INIT;
      int i;
      while (len--) {
          crc ^= (*octets++) << 16;
          for (i = 0; i < 8; i++) {
              crc <<= 1;
              if (crc & 0x1000000)
                  crc ^= CRC24_POLY;
          }
      }
      return crc & 0xFFFFFFL;
  }



The goal is to make 2 functions. One for general usage where the user feeds a Data sequence of a certain length, defined in octets and len parameters. And the other is to create a fixed length data of 9 bytes only.

One question. The generated CRC24 maximum values are from 0 to 00_FF_FF_FF right ?
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

LiaoMi


guga

Tks you a lot, LiaoMi
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

TimoVJL

With Pelles C:
_crc_octets@8:
  [00000000] 56                     push              esi
  [00000001] 57                     push              edi
  [00000002] 8B44240C               mov               eax,dword ptr [esp+C]
  [00000006] 8B542410               mov               edx,dword ptr [esp+10]
  [0000000A] 4A                     dec               edx
  [0000000B] B9CE04B700             mov               ecx,B704CE
  [00000010] 83FAFF                 cmp               edx,FFFFFFFF
  [00000013] 742E                   je                00000043
  [00000015] 40                     inc               eax
  [00000016] 0FB670FF               movzx             esi,byte ptr [eax-1]
  [0000001A] C1E610                 shl               esi,10
  [0000001D] 31F1                   xor               ecx,esi
  [0000001F] 31F6                   xor               esi,esi
  [00000021] EB14                   jmp               00000037
  [00000023] 01C9                   add               ecx,ecx
  [00000025] 89CF                   mov               edi,ecx
  [00000027] 81F7FB4C8601           xor               edi,1864CFB
  [0000002D] F7C100000001           test              ecx,1000000
  [00000033] 0F45CF                 cmovne            ecx,edi
  [00000036] 46                     inc               esi
  [00000037] 83FE08                 cmp               esi,8
  [0000003A] 7CE7                   jl                00000023
  [0000003C] 85D2                   test              edx,edx
  [0000003E] 8D52FF                 lea               edx,[edx-1]
  [00000041] 75D2                   jne               00000015
  [00000043] 89C8                   mov               eax,ecx
  [00000045] 25FFFFFF00             and               eax,FFFFFF
  [0000004A] 5F                     pop               edi
  [0000004B] 5E                     pop               esi
  [0000004C] C20800                 ret               8

crc_octets:
  [0000000000000000] 4883EA01                     sub               rdx,1
  [0000000000000004] B8CE04B700                   mov               eax,B704CE
  [0000000000000009] 4883FAFF                     cmp               rdx,FFFFFFFFFFFFFFFF
  [000000000000000D] 7449                         je                0000000000000058
  [000000000000000F] 4883C101                     add               rcx,1
  [0000000000000013] 440FB641FF                   movzx             r8d,byte ptr [rcx-1]
  [0000000000000018] 41C1E010                     shl               r8d,10
  [000000000000001C] 4431C0                       xor               eax,r8d
  [000000000000001F] 4531C0                       xor               r8d,r8d
  [0000000000000022] EB25                         jmp               0000000000000049
  [0000000000000024] 0F1F00                       nop               [rax]
  [0000000000000027] 660F1F840000000000           nop               [rax+rax+0]
  [0000000000000030] 01C0                         add               eax,eax
  [0000000000000032] 4189C1                       mov               r9d,eax
  [0000000000000035] 4181F1FB4C8601               xor               r9d,1864CFB
  [000000000000003C] A900000001                   test              eax,1000000
  [0000000000000041] 410F45C1                     cmovne            eax,r9d
  [0000000000000045] 4183C001                     add               r8d,1
  [0000000000000049] 4183F808                     cmp               r8d,8
  [000000000000004D] 7CE1                         jl                0000000000000030
  [000000000000004F] 4885D2                       test              rdx,rdx
  [0000000000000052] 488D52FF                     lea               rdx,[rdx-1]
  [0000000000000056] 75B7                         jne               000000000000000F
  [0000000000000058] 25FFFFFF00                   and               eax,FFFFFF
  [000000000000005D] C3                           ret               
May the source be with you