1 ! oneC_sum
() - One complement`s checksum Author
: Kees J. Bot
3 ! See RFC
1071, "Computing the Internet checksum"
4 ! See also the C version of this code.
15 mov ax
, 4(bp
) ! Checksum of previous block
16 mov si
, 6(bp
) ! Data to compute checksum over
17 mov di
, 8(bp
) ! Number of bytes
21 align
: test si
, #1 ! Is the data aligned?
25 movb dh
, (si
) ! First unaligned byte in high half of
26 dec di
! the dx register
, i.e. rotate
8 bits
28 movb cl
, #8 ! Number of bits "rotated"
29 ror ax
, cl
! Rotate the checksum likewise
30 aligned
:add ax
, dx
! Summate the unaligned byte
31 adc ax
, #0 ! Add carry back in for one`s complement
35 add6
: add ax
, (si
) ! Six times unrolled loop
, see below
50 add1
: add ax
, (si
) ! while
((di
-= 2) >= 0)
51 adc ax
, #0 ! ax += *si++;
58 jz done
! Is there an extra byte?
59 movb dl
, (si
) ! Load extra byte in word
61 add ax
, dx
! Add in the last bits
64 rol ax
, cl
! Undo the rotation at the beginning