piclist 2001\01\10\123726a >
Thread: IP Checksum coding challenge ?
www.piclist.com/techref/method/errors.htm?key=checksum
face
flavicon
face BY : Scott Dattalo email (remove spam text)



On Wed, 10 Jan 2001, Nikolai Golovchenko wrote:

{Quote hidden}

<snip>

You're right. Bill caught this too.


> I think there should be 2 too many instructions, as always :)

You're right again :). This is what I posted to Bill:

I was thinking add +1 in which case the carry and Z would both be set. However,
that's not necessarily the case. You can say that if Z is set after the addwf,
then the carry will be set too. So change the spknz above to a skpnc.

Now suppose the carry is set after the addwf. The skpnc will not skip and the
incf ipcksum_l will execute. If this rolls over, then the z bit will be set (but
the carry won't be affected. The next skpnz will detect this rollover and
increment the high byte accordingly.

Note, at the cost of increasing the worst case execution time, you can improve
the average execution time by inverting the polarity of the skp instructions and
execute returns if the skip is not taken.

; enter with "b" in W

ipsum_running:

   incf   ipcksum_b,f
   btfsc  ipcksum_b,0
    goto  l1

   addwf  ipcksum_h,f
   skpnc
    incf  ipcksum_l,f
   skpnz
    incf  ipcksum_h,f
   return

l1:
   addwf  ipcksum_l,f
   skpnc
    incf  ipcksum_h,f
   skpnz
    incf  ipcksum_l,f
   return



Scott

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spamlistservspamspamBeGonemitvma.mit.edu with SET PICList DIGEST in the body


<Pine.LNX.4.21.0101101130570.22644-100000@tempest2.blackhat.net>

In reply to: <4412819840.20010110104528@yahoo.com>
See also: www.piclist.com/techref/method/errors.htm?key=checksum
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) IP Checksum coding challenge ?

month overview.

new search...