CRC.asm 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. ; Seven Kingdoms: Ancient Adversaries
  2. ;
  3. ; Copyright 1997,1998 Enlight Software Ltd.
  4. ;
  5. ; This program is free software: you can redistribute it and/or modify
  6. ; it under the terms of the GNU General Public License as published by
  7. ; the Free Software Foundation, either version 2 of the License, or
  8. ; (at your option) any later version.
  9. ;
  10. ; This program is distributed in the hope that it will be useful,
  11. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ; GNU General Public License for more details.
  14. ;
  15. ; You should have received a copy of the GNU General Public License
  16. ; along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. ;
  18. ;Filename : CRC.ASM
  19. ;Description : calculate 8-bit CRC
  20. INCLUDE ALL.inc
  21. .CODE
  22. DIVISOR = 101001011b
  23. ;----------- BEGIN OF FUNCTION crc8 ------------
  24. ;
  25. ; calculate the remainder of cyclic division
  26. ;
  27. ; Syntax : CRC8( dataBuf, dataLen )
  28. ;
  29. ; unsigned char *dataBuf - data buffer
  30. ; int dataLen - length of data
  31. ;
  32. PUBLIC crc8
  33. crc8 PROC dataBuf, dataLen
  34. PUSH ECX
  35. PUSH ESI
  36. XOR EAX, EAX
  37. MOV ESI, dataBuf
  38. MOV ECX, dataLen
  39. OR ECX, ECX
  40. JZ @@end
  41. LODSB ; load the first byte
  42. DEC ECX
  43. JZ @@lastByte7
  44. @@nonLastByte7:
  45. MOV AH,AL
  46. LODSB
  47. TEST AH, 80h
  48. JZ @@nonLastByte6
  49. XOR AX, DIVISOR SHL 7
  50. @@nonLastByte6:
  51. TEST AH, 40h
  52. JZ @@nonLastByte5
  53. XOR AX, DIVISOR SHL 6
  54. @@nonLastByte5:
  55. TEST AH, 20h
  56. JZ @@nonLastByte4
  57. XOR AX, DIVISOR SHL 5
  58. @@nonLastByte4:
  59. TEST AH, 10h
  60. JZ @@nonLastByte3
  61. XOR AX, DIVISOR SHL 4
  62. @@nonLastByte3:
  63. TEST AH, 8h
  64. JZ @@nonLastByte2
  65. XOR AX, DIVISOR SHL 3
  66. @@nonLastByte2:
  67. TEST AH, 4h
  68. JZ @@nonLastByte1
  69. XOR AX, DIVISOR SHL 2
  70. @@nonLastByte1:
  71. TEST AH, 2h
  72. JZ @@nonLastByte0
  73. XOR AX, DIVISOR SHL 1
  74. @@nonLastByte0:
  75. TEST AH, 1h
  76. JZ @@nonLastByteX
  77. XOR AX, DIVISOR
  78. @@nonLastByteX:
  79. LOOP @@nonLastByte7
  80. @@lastByte7:
  81. SHL AX, 8
  82. TEST AH, 80h
  83. JZ @@lastByte6
  84. XOR AX, DIVISOR SHL 7
  85. @@lastByte6:
  86. TEST AH, 40h
  87. JZ @@lastByte5
  88. XOR AX, DIVISOR SHL 6
  89. @@lastByte5:
  90. TEST AH, 20h
  91. JZ @@lastByte4
  92. XOR AX, DIVISOR SHL 5
  93. @@lastByte4:
  94. TEST AH, 10h
  95. JZ @@lastByte3
  96. XOR AX, DIVISOR SHL 4
  97. @@lastByte3:
  98. TEST AH, 8h
  99. JZ @@lastByte2
  100. XOR AX, DIVISOR SHL 3
  101. @@lastByte2:
  102. TEST AH, 4h
  103. JZ @@lastByte1
  104. XOR AX, DIVISOR SHL 2
  105. @@lastByte1:
  106. TEST AH, 2h
  107. JZ @@lastByte0
  108. XOR AX, DIVISOR SHL 1
  109. @@lastByte0:
  110. TEST AH, 1h
  111. JZ @@end
  112. XOR AX, DIVISOR
  113. @@end:
  114. AND EAX, 0ffh ; only least 8-bit is significant
  115. POP ESI
  116. POP ECX
  117. RET
  118. crc8 ENDP
  119. ;----------- END OF FUNCTION crc8 ----------
  120. END