home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol158 / updcrc.a86 < prev    next >
Encoding:
Text File  |  1984-04-29  |  2.5 KB  |  82 lines

  1. ;updcrc.a86
  2. ;************************************************************************
  3. ;* CRCSUBS (Cyclic Redundancy Code Subroutines) version 1.20        *
  4. ;* 8086 Mnemonics                            *
  5. ;*                                    *
  6. ;*         This subroutine will compute and check a true 16-bit        *
  7. ;*    Cyclic Redundancy Code for a message of arbitrary length.    *
  8. ;*                                    *
  9. ;*    The  use  of this scheme will guarantee detection of all    *
  10. ;*    single and double bit errors, all  errors  with  an  odd    *
  11. ;*    number  of  error bits, all burst errors of length 16 or    *
  12. ;*    less, 99.9969% of all 17-bit error bursts, and  99.9984%    *
  13. ;*    of  all  possible  longer  error bursts.  (Ref: Computer    *
  14. ;*    Networks, Andrew S.  Tanenbaum, Prentiss-Hall, 1981)        *
  15. ;*                                    *
  16. ;*                                    *
  17. ;************************************************************************
  18. ;*                                    *
  19. ;*    From: CRCSUB12.ASM                        *
  20. ;*    Designed & coded by Paul Hansknecht, June 13, 1981        *
  21. ;*      Converted to 8086 for Computer Innovations C86 Compiler        *
  22. ;*    by Paul Homchick Aug 27, 1983                    *
  23. ;*                                    *
  24. ;*    Copyright (c) 1981, Carpenter Associates            *
  25. ;*                Box 451                    *
  26. ;*                Bloomfield Hills, MI 48013            *
  27. ;*                313/855-3074                *
  28. ;*                                    *
  29. ;*    This program may be freely reproduced for non-profit use.    *
  30. ;*                                    *
  31. ;************************************************************************
  32. ;
  33. ;    unsigned updcrc(char, oldcrc)
  34. ;
  35. ;    At start of packet, oldcrc is set to initial value
  36. ;        oldcrc=0;
  37. ;
  38. ;    crc is accumulated by:
  39. ;        oldcrc=updcrc(char, oldcrc);
  40. ;
  41. ;    at end of packet,
  42. ;        oldcrc=updcrc(0,updcrc(0,oldcrc));
  43. ;        send(oldcrc>>8); send(oldcrc);
  44. ;
  45. ;    on receive, the return value of updcrc is checked after the
  46. ;    last call (with the second CRC byte); 0 indicates no error detected
  47. ;
  48.  
  49.  
  50. DEFCGBL    equ    0c1h
  51. DEFDGBL    equ    0c2h
  52. RELCGBL    equ    0c3h
  53. ABSCGBL    equ    0c4h
  54.  
  55.     cseg
  56.  
  57. upd_crc:
  58.     push    bp        ; save frame pointer
  59.     mov    bp,sp        ; stack pointer to frame pointer
  60.     mov    ax,4[bp]    ; get char
  61.     mov    bx,6[bp]    ; get oldcrc
  62.  
  63.     mov    cx,8        ; The generator is X^16 + X^12 + X^5 + 1       
  64. updloop:                        ; as recommended by CCITT.                     
  65.     rol    al,1            ; An alternate generator which is often        
  66.     rcl    bx,1            ; used in synchronous transmission protocols   
  67.     jnb    skipit          ; is X^16 + X^15 + X^2 + 1. This may be        
  68.                 ; used by substituting XOR 8005H for
  69.     xor    bx,1021H    ; XOR 1021H in the adjacent code.
  70. skipit:    loop    updloop        
  71.     mov    ax,bx        ; mov to accumulator for return                
  72.     pop    bp
  73.     ret            ; return with latest crc in ax
  74.  
  75.     eseg
  76.  
  77.     dw    upd_crc
  78.     db    DEFCGBL,'updcrc',0
  79.     dw    0,0
  80.  
  81.     end
  82.