INCHKSUM.ASM
资源名称:wattcp.rar [点击查看]
上传用户:better800
上传日期:2022-06-13
资源大小:1853k
文件大小:1k
源码类别:
TCP/IP协议栈
开发平台:
DOS
- ;
- ;
- ; Usage :
- ; void far *inchksum()
- ;
- ; Internet compatible 1's complement checksum
- ;
- ; (c) 1990 Erick Engelke
- ;
- ; version
- ;
- ; 0.1 17 Dec -1990 E. P. Engelke
- ;
- ;
- include masmdefs.hsm
- include model.hsm
- codedef INCHKSUM
- datadef
- cstart INCHKSUM
- cpublic inchksum
- ; Compute 1's-complement sum of data buffer
- ;
- ; unsigned lcsum( usigned far *buf, unsigned cnt)
- push DS
- lds SI, +@AB + 0 [BP]
- mov CX, +@AB + 4 [BP] ; cx = cnt
- mov BL, CL
- shr CX, 1 ; group into words
- xor DX, DX ; set checksum to 0
- cld
- jcxz remain
- clc
- deloop: lodsw
- adc DX, AX
- loop deloop
- adc DX, 0 ; only two necessary
- adc DX, 0
- remain: and BL, 1
- jz done
- xor AH, AH
- lodsb
- add DX, AX
- adc DX, 0
- adc DX, 0
- done: mov AX,DX ; result into ax
- or AX,AX
- ok: pop DS
- creturn inchksum
- cend INCHKSUM
- end