home *** CD-ROM | disk | FTP | other *** search
/ Graphics Programming Black Book (Special Edition) / BlackBook.bin / disk1 / source / chapter21 / l21-2.asm < prev    next >
Assembly Source File  |  1997-06-18  |  1KB  |  28 lines

  1. ; Calculates TCP/IP (16-bit carry-wrapping) checksum for buffer
  2. ;  starting at ESI, of length ECX words.
  3. ; Returns checksum in AX.
  4. ; High word of EAX, DX, ECX and ESI destroyed.
  5. ; All cycle counts assume 32-bit protected mode.
  6. ; Assumes buffer length > 0.
  7.  
  8.         sub     eax,eax         ;initialize the checksum
  9.         mov     dx,[esi]        ;first word to checksum
  10.         dec     ecx             ;we'll do 1 checksum outside the loop
  11.         jz      short ckloopend ;only 1 checksum to do
  12.         add     esi,2           ;point to the next word to checksum
  13.  
  14. ckloop:
  15.         add     al,dl           ;cycle 1 U-pipe
  16.         mov     dl,[esi]        ;cycle 1 V-pipe
  17.         adc     ah,dh           ;cycle 2 U-pipe
  18.         mov     dh,[esi+1]      ;cycle 2 V-pipe
  19.         adc     eax,0           ;cycle 3 U-pipe
  20.         add     esi,2           ;cycle 3 V-pipe
  21.         dec     ecx             ;cycle 4 U-pipe
  22.         jnz     ckloop          ;cycle 4 V-pipe
  23.  
  24. ckloopend:
  25.         add     ax,dx           ;checksum the last word
  26.         adc     eax,0
  27.  
  28.