Announcement

Collapse
No announcement yet.

Crc-8

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Crc-8

    I'm looking at performing an 8-bit CRC calculation for short data records (around 84 bytes). There's quite a few references for CRC-16 and CRC-32 but not lot for CRC-8. However, I did find some C source code for, reportedly, a CCITT implementation of CRC-8. I converted this to PB, and the output matches results from some on-line calculators. It seems that there's a few different implementation of CRC-8 but this is the one that I found code for. Does anyone out there have experience using CRC-8 and, if so, am I doing this correctly?

    Here's the C source code.

    Code:
    static const uint8_t CRC_TABLE[256] = {
        0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15,
        0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D,
        0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65,
        0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D,
        0xE0, 0xE7, 0xEE, 0xE9, 0xFC, 0xFB, 0xF2, 0xF5,
        0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD,
        0x90, 0x97, 0x9E, 0x99, 0x8C, 0x8B, 0x82, 0x85,
        0xA8, 0xAF, 0xA6, 0xA1, 0xB4, 0xB3, 0xBA, 0xBD,
        0xC7, 0xC0, 0xC9, 0xCE, 0xDB, 0xDC, 0xD5, 0xD2,
        0xFF, 0xF8, 0xF1, 0xF6, 0xE3, 0xE4, 0xED, 0xEA,
        0xB7, 0xB0, 0xB9, 0xBE, 0xAB, 0xAC, 0xA5, 0xA2,
        0x8F, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9D, 0x9A,
        0x27, 0x20, 0x29, 0x2E, 0x3B, 0x3C, 0x35, 0x32,
        0x1F, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0D, 0x0A,
        0x57, 0x50, 0x59, 0x5E, 0x4B, 0x4C, 0x45, 0x42,
        0x6F, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7D, 0x7A,
        0x89, 0x8E, 0x87, 0x80, 0x95, 0x92, 0x9B, 0x9C,
        0xB1, 0xB6, 0xBF, 0xB8, 0xAD, 0xAA, 0xA3, 0xA4,
        0xF9, 0xFE, 0xF7, 0xF0, 0xE5, 0xE2, 0xEB, 0xEC,
        0xC1, 0xC6, 0xCF, 0xC8, 0xDD, 0xDA, 0xD3, 0xD4,
        0x69, 0x6E, 0x67, 0x60, 0x75, 0x72, 0x7B, 0x7C,
        0x51, 0x56, 0x5F, 0x58, 0x4D, 0x4A, 0x43, 0x44,
        0x19, 0x1E, 0x17, 0x10, 0x05, 0x02, 0x0B, 0x0C,
        0x21, 0x26, 0x2F, 0x28, 0x3D, 0x3A, 0x33, 0x34,
        0x4E, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5C, 0x5B,
        0x76, 0x71, 0x78, 0x7F, 0x6A, 0x6D, 0x64, 0x63,
        0x3E, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2C, 0x2B,
        0x06, 0x01, 0x08, 0x0F, 0x1A, 0x1D, 0x14, 0x13,
        0xAE, 0xA9, 0xA0, 0xA7, 0xB2, 0xB5, 0xBC, 0xBB,
        0x96, 0x91, 0x98, 0x9F, 0x8A, 0x8D, 0x84, 0x83,
        0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB,
        0xE6, 0xE1, 0xE8, 0xEF, 0xFA, 0xFD, 0xF4, 0xF3
    };
    
    uint8_t crc8ccitt(const void * data, size_t size) {
            uint8_t val = 0;
    
            uint8_t * pos = (uint8_t *) data;
            uint8_t * end = pos + size;
    
            while (pos < end) {
                   val = CRC_TABLE[val ^ *pos];
                   pos++;
            }
    
            return val;
    }
    And here's the PB conversion (I am NOT at all good with C).

    Code:
    FUNCTION crc8ccitt (BYVAL pData AS BYTE PTR, dLen AS LONG) AS BYTE
      STATIC init   AS LONG
      REGISTER n    AS LONG
      STATIC pTable AS BYTE PTR
      LOCAL crc     AS BYTE
    
      '-- Static byte val translate table.
      DIM b(0 TO 255) AS STATIC BYTE
      DATA    &H00, &H07, &H0E, &H09, &H1C, &H1B, &H12, &H15
      DATA    &H38, &H3F, &H36, &H31, &H24, &H23, &H2A, &H2D
      DATA    &H70, &H77, &H7E, &H79, &H6C, &H6B, &H62, &H65
      DATA    &H48, &H4F, &H46, &H41, &H54, &H53, &H5A, &H5D
      DATA    &HE0, &HE7, &HEE, &HE9, &HFC, &HFB, &HF2, &HF5
      DATA    &HD8, &HDF, &HD6, &HD1, &HC4, &HC3, &HCA, &HCD
      DATA    &H90, &H97, &H9E, &H99, &H8C, &H8B, &H82, &H85
      DATA    &HA8, &HAF, &HA6, &HA1, &HB4, &HB3, &HBA, &HBD
      DATA    &HC7, &HC0, &HC9, &HCE, &HDB, &HDC, &HD5, &HD2
      DATA    &HFF, &HF8, &HF1, &HF6, &HE3, &HE4, &HED, &HEA
      DATA    &HB7, &HB0, &HB9, &HBE, &HAB, &HAC, &HA5, &HA2
      DATA    &H8F, &H88, &H81, &H86, &H93, &H94, &H9D, &H9A
      DATA    &H27, &H20, &H29, &H2E, &H3B, &H3C, &H35, &H32
      DATA    &H1F, &H18, &H11, &H16, &H03, &H04, &H0D, &H0A
      DATA    &H57, &H50, &H59, &H5E, &H4B, &H4C, &H45, &H42
      DATA    &H6F, &H68, &H61, &H66, &H73, &H74, &H7D, &H7A
      DATA    &H89, &H8E, &H87, &H80, &H95, &H92, &H9B, &H9C
      DATA    &HB1, &HB6, &HBF, &HB8, &HAD, &HAA, &HA3, &HA4
      DATA    &HF9, &HFE, &HF7, &HF0, &HE5, &HE2, &HEB, &HEC
      DATA    &HC1, &HC6, &HCF, &HC8, &HDD, &HDA, &HD3, &HD4
      DATA    &H69, &H6E, &H67, &H60, &H75, &H72, &H7B, &H7C
      DATA    &H51, &H56, &H5F, &H58, &H4D, &H4A, &H43, &H44
      DATA    &H19, &H1E, &H17, &H10, &H05, &H02, &H0B, &H0C
      DATA    &H21, &H26, &H2F, &H28, &H3D, &H3A, &H33, &H34
      DATA    &H4E, &H49, &H40, &H47, &H52, &H55, &H5C, &H5B
      DATA    &H76, &H71, &H78, &H7F, &H6A, &H6D, &H64, &H63
      DATA    &H3E, &H39, &H30, &H37, &H22, &H25, &H2C, &H2B
      DATA    &H06, &H01, &H08, &H0F, &H1A, &H1D, &H14, &H13
      DATA    &HAE, &HA9, &HA0, &HA7, &HB2, &HB5, &HBC, &HBB
      DATA    &H96, &H91, &H98, &H9F, &H8A, &H8D, &H84, &H83
      DATA    &HDE, &HD9, &HD0, &HD7, &HC2, &HC5, &HCC, &HCB
      DATA    &HE6, &HE1, &HE8, &HEF, &HFA, &HFD, &HF4, &HF3
    
      '-- Build a lookup table the first time called.
      IF ISFALSE init THEN
        pTable = VARPTR(b(0))
        FOR n = 0 TO DATACOUNT - 1
          @pTable[n] = VAL(READ$(n + 1))
        NEXT n
        init = 1
      END IF
    
      IF dLen THEN
        FOR n = 0 TO dLen - 1
          crc = @pTable[@pData[n] XOR crc]
        NEXT n
        FUNCTION = crc
      END IF
    
    END FUNCTION
    I tried fiddling with ASM but couldn't seem to get a table value into a byte register, so I gave up on that.

    Thanks!

  • #2
    Hi Jerry, the code looks correct but it can be simplified if you're using PBCC 6 or PBWin10.

    Here's an example using the new ASMDATA statement. It stores data as read only bytes in the CODE section.
    If you need more speed, assembly would be the way to go.


    Code:
    #compile exe
    #dim all
    
    global pTable as byte ptr
    
    function PBMain() as long
       local s as string
       s = "The quick brown fox jumps over the lazy dog"
    
       pTable = codeptr(crc8) ' initialize the CRC data table
    
       ? "CRC=" trim$(crc8ccitt(strptr(s),len(s)))
    
    end function
    
    
    function crc8ccitt (byval pData as byte ptr, byval dLen as long) as byte
       local n as long
       local crc as long
    
       for n = 0 to dLen-1
          crc = @pTable[@pData[n] XOR crc]
       next
       function = crc
    end function
    
    asmdata crc8
       db &H00, &H07, &H0E, &H09, &H1C, &H1B, &H12, &H15
       db &H38, &H3F, &H36, &H31, &H24, &H23, &H2A, &H2D
       db &H70, &H77, &H7E, &H79, &H6C, &H6B, &H62, &H65
       db &H48, &H4F, &H46, &H41, &H54, &H53, &H5A, &H5D
       db &HE0, &HE7, &HEE, &HE9, &HFC, &HFB, &HF2, &HF5
       db &HD8, &HDF, &HD6, &HD1, &HC4, &HC3, &HCA, &HCD
       db &H90, &H97, &H9E, &H99, &H8C, &H8B, &H82, &H85
       db &HA8, &HAF, &HA6, &HA1, &HB4, &HB3, &HBA, &HBD
       db &HC7, &HC0, &HC9, &HCE, &HDB, &HDC, &HD5, &HD2
       db &HFF, &HF8, &HF1, &HF6, &HE3, &HE4, &HED, &HEA
       db &HB7, &HB0, &HB9, &HBE, &HAB, &HAC, &HA5, &HA2
       db &H8F, &H88, &H81, &H86, &H93, &H94, &H9D, &H9A
       db &H27, &H20, &H29, &H2E, &H3B, &H3C, &H35, &H32
       db &H1F, &H18, &H11, &H16, &H03, &H04, &H0D, &H0A
       db &H57, &H50, &H59, &H5E, &H4B, &H4C, &H45, &H42
       db &H6F, &H68, &H61, &H66, &H73, &H74, &H7D, &H7A
       db &H89, &H8E, &H87, &H80, &H95, &H92, &H9B, &H9C
       db &HB1, &HB6, &HBF, &HB8, &HAD, &HAA, &HA3, &HA4
       db &HF9, &HFE, &HF7, &HF0, &HE5, &HE2, &HEB, &HEC
       db &HC1, &HC6, &HCF, &HC8, &HDD, &HDA, &HD3, &HD4
       db &H69, &H6E, &H67, &H60, &H75, &H72, &H7B, &H7C
       db &H51, &H56, &H5F, &H58, &H4D, &H4A, &H43, &H44
       db &H19, &H1E, &H17, &H10, &H05, &H02, &H0B, &H0C
       db &H21, &H26, &H2F, &H28, &H3D, &H3A, &H33, &H34
       db &H4E, &H49, &H40, &H47, &H52, &H55, &H5C, &H5B
       db &H76, &H71, &H78, &H7F, &H6A, &H6D, &H64, &H63
       db &H3E, &H39, &H30, &H37, &H22, &H25, &H2C, &H2B
       db &H06, &H01, &H08, &H0F, &H1A, &H1D, &H14, &H13
       db &HAE, &HA9, &HA0, &HA7, &HB2, &HB5, &HBC, &HBB
       db &H96, &H91, &H98, &H9F, &H8A, &H8D, &H84, &H83
       db &HDE, &HD9, &HD0, &HD7, &HC2, &HC5, &HCC, &HCB
       db &HE6, &HE1, &HE8, &HEF, &HFA, &HFD, &HF4, &HF3
    end asmdata
    Last edited by Ross Boyd; 10 Oct 2019, 09:24 PM.

    Comment


    • #3
      Nice function, but:

      I suggest you create the code tags first and then paste your code between them

      That way you won't get:
      ? "CRC=" &amp; trim$(crc8ccita(strptr(s),len(s)))

      also compare the function name above to the declaration:
      function crc8ccitt (byval pData as byte ptr, byval dLen as long) as byte.

      (an edit of your post above would be beneficial )

      Comment


      • #4
        Ross: I missed the ASMDATA statement. Thanks for pointing me there. Instead of declaring a GLOBAL, I use a STATIC pointer in the function. So, the new function code looks like this (below). I agree that ASM would be faster but I need to bone up on using it. In this form, it takes around .3us to calculate the CRC value for 84 bytes of data on my laptop.

        Stuart: I neglected to use BYVAL for the data length in the original function declaration. Thanks for noticing. I need to RTFM and figure out how to update a previous post (seems that it should be simple but...). And thanks for the tip on inserting code between the tags. I've run into the &amp problem in the past.

        Code:
        FUNCTION crc8ccitt (BYVAL pData AS BYTE PTR, BYVAL dLen AS LONG) AS BYTE
          REGISTER n    AS LONG
          STATIC pTable AS BYTE PTR
          LOCAL crc     AS LONG         ' <--- Changed from BYTE to LONG (faster)
        
          IF ISFALSE pTable THEN pTable = CODEPTR(crc8_table)
        
          IF dLen THEN
            FOR n = 0 TO dLen - 1
              crc = @pTable[@pData[n] XOR crc]
            NEXT n
            FUNCTION = crc
          END IF
        END FUNCTION
        
        ASMDATA crc8_table
          DB &H00, &H07, &H0E, &H09, &H1C, &H1B, &H12, &H15
          DB &H38, &H3F, &H36, &H31, &H24, &H23, &H2A, &H2D
          DB &H70, &H77, &H7E, &H79, &H6C, &H6B, &H62, &H65
          DB &H48, &H4F, &H46, &H41, &H54, &H53, &H5A, &H5D
          DB &HE0, &HE7, &HEE, &HE9, &HFC, &HFB, &HF2, &HF5
          DB &HD8, &HDF, &HD6, &HD1, &HC4, &HC3, &HCA, &HCD
          DB &H90, &H97, &H9E, &H99, &H8C, &H8B, &H82, &H85
          DB &HA8, &HAF, &HA6, &HA1, &HB4, &HB3, &HBA, &HBD
          DB &HC7, &HC0, &HC9, &HCE, &HDB, &HDC, &HD5, &HD2
          DB &HFF, &HF8, &HF1, &HF6, &HE3, &HE4, &HED, &HEA
          DB &HB7, &HB0, &HB9, &HBE, &HAB, &HAC, &HA5, &HA2
          DB &H8F, &H88, &H81, &H86, &H93, &H94, &H9D, &H9A
          DB &H27, &H20, &H29, &H2E, &H3B, &H3C, &H35, &H32
          DB &H1F, &H18, &H11, &H16, &H03, &H04, &H0D, &H0A
          DB &H57, &H50, &H59, &H5E, &H4B, &H4C, &H45, &H42
          DB &H6F, &H68, &H61, &H66, &H73, &H74, &H7D, &H7A
          DB &H89, &H8E, &H87, &H80, &H95, &H92, &H9B, &H9C
          DB &HB1, &HB6, &HBF, &HB8, &HAD, &HAA, &HA3, &HA4
          DB &HF9, &HFE, &HF7, &HF0, &HE5, &HE2, &HEB, &HEC
          DB &HC1, &HC6, &HCF, &HC8, &HDD, &HDA, &HD3, &HD4
          DB &H69, &H6E, &H67, &H60, &H75, &H72, &H7B, &H7C
          DB &H51, &H56, &H5F, &H58, &H4D, &H4A, &H43, &H44
          DB &H19, &H1E, &H17, &H10, &H05, &H02, &H0B, &H0C
          DB &H21, &H26, &H2F, &H28, &H3D, &H3A, &H33, &H34
          DB &H4E, &H49, &H40, &H47, &H52, &H55, &H5C, &H5B
          DB &H76, &H71, &H78, &H7F, &H6A, &H6D, &H64, &H63
          DB &H3E, &H39, &H30, &H37, &H22, &H25, &H2C, &H2B
          DB &H06, &H01, &H08, &H0F, &H1A, &H1D, &H14, &H13
          DB &HAE, &HA9, &HA0, &HA7, &HB2, &HB5, &HBC, &HBB
          DB &H96, &H91, &H98, &H9F, &H8A, &H8D, &H84, &H83
          DB &HDE, &HD9, &HD0, &HD7, &HC2, &HC5, &HCC, &HCB
          DB &HE6, &HE1, &HE8, &HEF, &HFA, &HFD, &HF4, &HF3
        END ASMDATA
        Last edited by Jerry Wilson; 11 Oct 2019, 12:25 AM.

        Comment


        • #5
          Originally posted by Stuart McLachlan View Post
          Nice function, but:

          I suggest you create the code tags first and then paste your code between them

          That way you won't get:
          ? "CRC=" &amp; trim$(crc8ccita(strptr(s),len(s)))

          also compare the function name above to the declaration:
          function crc8ccitt (byval pData as byte ptr, byval dLen as long) as byte.

          (an edit of your post above would be beneficial )
          Yes I know about using code tags...

          Interestingly, when I was writing my reply, I navigated away from the page and then went back and chose to 'recover' my editing. It was this that generated all the html &amp's in the post. I replaced the entire asmdata section but overlooked the one remaining &amp you saw.

          All amended now. Thanks for the heads up Stuart.

          Jerry, it looks pretty neat. On the topic of passing dLen ByVal, its also good to know that ByVal is faster than ByRef when passing scalar values.
          Plus, declaring the local crc variable as a LONG will result in ~25% faster code without any side effects.

          Comment


          • #6
            Originally posted by Ross Boyd View Post

            All amended now.
            Actually, you've ended up deleting the "&amp;" rather than replacing it with "&" so it won't compile as is. Anther edit?

            Comment


            • #7
              Hmm, I've just learnt something new.

              I wasn't aware of TRIM$(numeric_expression), I've always used FORMAT$(numeric_expression).

              Note to self: yet again,

              Comment


              • #8
                Same here! So checked Help files. The feature is new with PBWin 10 and PBCC 6

                added - Just remembered; I've been using DEC$ (also new with 10 & 6) for integers without leading spaces.

                Cheers,
                .
                Dale

                Comment


                • #9
                  I'm all out of edits Stuart - too late.
                  Re TRIM$(), I believe someone did some benchmarks and it was the fastest builtin function to convert numbers to strings.

                  Revised...

                  Code:
                   
                   #compile exe #dim all  global pTable as byte ptr  function PBMain() as long    local s as string    s = "The quick brown fox jumps over the lazy dog"     pTable = codeptr(crc8) ' initialize the CRC data table     ? "CRC=" & trim$(crc8ccitt(strptr(s),len(s)))  end function   function crc8ccitt (byval pData as byte ptr, byval dLen as long) as byte    local n as long    local crc as long  ' A byte could be used here but a LONG is ~25% faster     for n = 0 to dLen-1       crc = @pTable[@pData[n] XOR crc]    next    function = crc end function  asmdata crc8    db &H00, &H07, &H0E, &H09, &H1C, &H1B, &H12, &H15    db &H38, &H3F, &H36, &H31, &H24, &H23, &H2A, &H2D    db &H70, &H77, &H7E, &H79, &H6C, &H6B, &H62, &H65    db &H48, &H4F, &H46, &H41, &H54, &H53, &H5A, &H5D    db &HE0, &HE7, &HEE, &HE9, &HFC, &HFB, &HF2, &HF5    db &HD8, &HDF, &HD6, &HD1, &HC4, &HC3, &HCA, &HCD    db &H90, &H97, &H9E, &H99, &H8C, &H8B, &H82, &H85    db &HA8, &HAF, &HA6, &HA1, &HB4, &HB3, &HBA, &HBD    db &HC7, &HC0, &HC9, &HCE, &HDB, &HDC, &HD5, &HD2    db &HFF, &HF8, &HF1, &HF6, &HE3, &HE4, &HED, &HEA    db &HB7, &HB0, &HB9, &HBE, &HAB, &HAC, &HA5, &HA2    db &H8F, &H88, &H81, &H86, &H93, &H94, &H9D, &H9A    db &H27, &H20, &H29, &H2E, &H3B, &H3C, &H35, &H32    db &H1F, &H18, &H11, &H16, &H03, &H04, &H0D, &H0A    db &H57, &H50, &H59, &H5E, &H4B, &H4C, &H45, &H42    db &H6F, &H68, &H61, &H66, &H73, &H74, &H7D, &H7A    db &H89, &H8E, &H87, &H80, &H95, &H92, &H9B, &H9C    db &HB1, &HB6, &HBF, &HB8, &HAD, &HAA, &HA3, &HA4    db &HF9, &HFE, &HF7, &HF0, &HE5, &HE2, &HEB, &HEC    db &HC1, &HC6, &HCF, &HC8, &HDD, &HDA, &HD3, &HD4    db &H69, &H6E, &H67, &H60, &H75, &H72, &H7B, &H7C    db &H51, &H56, &H5F, &H58, &H4D, &H4A, &H43, &H44    db &H19, &H1E, &H17, &H10, &H05, &H02, &H0B, &H0C    db &H21, &H26, &H2F, &H28, &H3D, &H3A, &H33, &H34    db &H4E, &H49, &H40, &H47, &H52, &H55, &H5C, &H5B    db &H76, &H71, &H78, &H7F, &H6A, &H6D, &H64, &H63    db &H3E, &H39, &H30, &H37, &H22, &H25, &H2C, &H2B    db &H06, &H01, &H08, &H0F, &H1A, &H1D, &H14, &H13    db &HAE, &HA9, &HA0, &HA7, &HB2, &HB5, &HBC, &HBB    db &H96, &H91, &H98, &H9F, &H8A, &H8D, &H84, &H83    db &HDE, &HD9, &HD0, &HD7, &HC2, &HC5, &HCC, &HCB    db &HE6, &HE1, &HE8, &HEF, &HFA, &HFD, &HF4, &HF3 end asmdata

                  Comment


                  • #10
                    Jerry,
                    No speed test done, yours to try...

                    Code:
                    '_____________________________________________________________________________
                    
                    FUNCTION Crc8(sData AS STRING) AS BYTE
                     #REGISTER NONE
                    
                     ! lea ebx, pCrcTable 'Get CRC table memory address
                     ! mov esi, sData     'Get BSTR pointer in ESI
                     ! mov esi, [esi]     'Get data string pointer in ESI from BSTR pointer
                     ! mov edi, esi       'Copy data string pointer in EDI
                     ! mov eax, [esi - 4] 'Get data string lenght in EAX
                     ! add edi, eax       'Add EAX data lenght to EDI string pointer to get ending data string address
                     ! xor ah, ah         'Reset AH to zero
                    
                     ComputeCrc:          'Looping point
                     ! lodsb              'Copy byte at address ESI in AL and inc ESI
                     ! xor al, ah         'Xor AL and AH and put result in AL
                     ! xlatb              'Translate value in AL from table, EBX must point to pCrcTable
                     ! mov ah, al         'Copy AL in AH
                     ! cmp esi, edi       'Compare ESI and EDI to check end of string address and
                     ! jne ComputeCrc     'jump to ComputeCrc only if they are not equal
                    
                     ! mov FUNCTION, ah   'Job done, give AH as result
                     EXIT  FUNCTION
                    
                     pCrcTable:
                     !db &h00, &h07, &h0E, &h09, &h1C, &h1B, &h12, &h15, &h38, &h3F, &h36, &h31, &h24, &h23, &h2A, &h2D
                     !db &h70, &h77, &h7E, &h79, &h6C, &h6B, &h62, &h65, &h48, &h4F, &h46, &h41, &h54, &h53, &h5A, &h5D
                     !db &hE0, &hE7, &hEE, &hE9, &hFC, &hFB, &hF2, &hF5, &hD8, &hDF, &hD6, &hD1, &hC4, &hC3, &hCA, &hCD
                     !db &h90, &h97, &h9E, &h99, &h8C, &h8B, &h82, &h85, &hA8, &hAF, &hA6, &hA1, &hB4, &hB3, &hBA, &hBD
                     !db &hC7, &hC0, &hC9, &hCE, &hDB, &hDC, &hD5, &hD2, &hFF, &hF8, &hF1, &hF6, &hE3, &hE4, &hED, &hEA
                     !db &hB7, &hB0, &hB9, &hBE, &hAB, &hAC, &hA5, &hA2, &h8F, &h88, &h81, &h86, &h93, &h94, &h9D, &h9A
                     !db &h27, &h20, &h29, &h2E, &h3B, &h3C, &h35, &h32, &h1F, &h18, &h11, &h16, &h03, &h04, &h0D, &h0A
                     !db &h57, &h50, &h59, &h5E, &h4B, &h4C, &h45, &h42, &h6F, &h68, &h61, &h66, &h73, &h74, &h7D, &h7A
                     !db &h89, &h8E, &h87, &h80, &h95, &h92, &h9B, &h9C, &hB1, &hB6, &hBF, &hB8, &hAD, &hAA, &hA3, &hA4
                     !db &hF9, &hFE, &hF7, &hF0, &hE5, &hE2, &hEB, &hEC, &hC1, &hC6, &hCF, &hC8, &hDD, &hDA, &hD3, &hD4
                     !db &h69, &h6E, &h67, &h60, &h75, &h72, &h7B, &h7C, &h51, &h56, &h5F, &h58, &h4D, &h4A, &h43, &h44
                     !db &h19, &h1E, &h17, &h10, &h05, &h02, &h0B, &h0C, &h21, &h26, &h2F, &h28, &h3D, &h3A, &h33, &h34
                     !db &h4E, &h49, &h40, &h47, &h52, &h55, &h5C, &h5B, &h76, &h71, &h78, &h7F, &h6A, &h6D, &h64, &h63
                     !db &h3E, &h39, &h30, &h37, &h22, &h25, &h2C, &h2B, &h06, &h01, &h08, &h0F, &h1A, &h1D, &h14, &h13
                     !db &hAE, &hA9, &hA0, &hA7, &hB2, &hB5, &hBC, &hBB, &h96, &h91, &h98, &h9F, &h8A, &h8D, &h84, &h83
                     !db &hDE, &hD9, &hD0, &hD7, &hC2, &hC5, &hCC, &hCB, &hE6, &hE1, &hE8, &hEF, &hFA, &hFD, &hF4, &hF3
                    
                    END FUNCTION
                    '_____________________________________________________________________________
                    '
                    Last edited by Pierre Bellisle; Yesterday, 06:34 PM.

                    Comment


                    • #11
                      Thanks, Pierre.

                      Both functions (PB and ASM) yield the same value for input data - which matches test vectors that I found at https://crccalc.com/. I did a quick speed comparison test of the two functions with input data sizes of 16 and 84 bytes (CRC8 may not be useful for data sizes larger than 84 bytes). The test performed a loop, making 100M calculations of the same input data and averaging the result. For 16 bytes, the operation for both functions seemed to take around 0.05us. For 84 bytes, the PB function was just slightly faster at 0.22us vs 0.31us for the ASM function. Since I'm still trying to get my head around ASM, I can't explain the difference. However, either will be plenty fast for whatever I need the to do.

                      Comment

                      Working...
                      X