home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / hamradio / wattcp.zip / INCHKSUM.ASM < prev    next >
Assembly Source File  |  1992-03-05  |  1KB  |  62 lines

  1. ;
  2. ;
  3. ;  Usage :
  4. ;           void far *inchksum()
  5. ;
  6. ;  Internet compatible 1's complement checksum
  7. ;
  8. ;  (c) 1990 University of Waterloo,
  9. ;           Faculty of Engineering,
  10. ;           Engineering Microcomputer Network Development Office
  11. ;
  12. ;  version
  13. ;
  14. ;    0.1    17 Dec -1990   E. P. Engelke
  15. ;
  16. ;
  17.         include masmdefs.hsm
  18.         include model.hsm
  19.  
  20. codedef INCHKSUM
  21. datadef
  22.  
  23. cstart  INCHKSUM
  24. cpublic inchksum
  25.         ; Compute 1's-complement sum of data buffer
  26.         ;
  27.         ; unsigned lcsum( usigned far *buf, unsigned cnt)
  28.     push    DS
  29.         lds     SI, +@AB + 0 [BP]
  30.     mov     CX, +@AB + 4 [BP]       ; cx = cnt
  31.  
  32.         mov     BL, CL
  33.  
  34.     shr     CX, 1            ; group into words
  35.     xor    DX, DX            ; set checksum to 0
  36.         cld
  37.  
  38.         jcxz    remain
  39.         clc
  40. deloop: lodsw
  41.     adc    DX, AX
  42.     loop    deloop
  43.  
  44.         adc     DX, 0                   ; only two necessary
  45.         adc     DX, 0
  46.  
  47. remain: and     BL, 1
  48.         jz      done
  49.  
  50.         xor     AH, AH
  51.         lodsb
  52.         add     DX, AX
  53.         adc     DX, 0
  54.         adc     DX, 0
  55.  
  56. done:   mov    AX,DX        ; result into ax
  57.         or      AX,AX
  58. ok:     pop     DS
  59. creturn inchksum
  60. cend    INCHKSUM
  61.         end
  62.