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



Scott Dattalo wrote:
> 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.

I'm afraid that doesn't work either. Suppose the carry is cleared
after the addwf, and zero flag is set, which is the case when
zero added to zero. The increment after skpnc will be skipped,
but the next one after skpnz won't!

> 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.

That would fix the problem also, since the increment will never
be executed on cleared carry. But I see a way to avoid the code
size grows. Take a look:

; enter with "b" in W

ipsum_running:

   incf   ipcksum_b,f
   btfss  ipcksum_b,0
    goto  l1

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

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

Nikolai

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


<54129707.20010111061523@yahoo.com> 7bit

In reply to: <Pine.LNX.4.21.0101101130570.22644-100000@tempest2.blackhat.net>
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...