From: Rod B. <ro...@bo...> - 2003-03-13 17:50:49
|
Your are not think variable size here. When doing a 16-bit checksum you set the variable overflow. This is haw it is done is hardware. Add all the bytes up and throw away the overflow but make sure you use a 16-bit variable. If you want to do an 8-bit checksum use a 8-bit variable. Same for 32-bit checksums. The overflow is surposed to happen. (unsigned short)0xfff5 + (unsigned char)0x0f = (unsigned short)0x0004 or something like that. I haven't had my morning coffee yet. Regards, Rod On Thu, 13 Mar 2003 11:37:23 -0500 "Olaniyi Bajomo" <zu...@em...> wrote: > WEll yes I have tried to do it in C but it don't work casue I can perform 2's complement addition in C,my main problem is how to deal with an overflow? > > Any ideas? > > thanks > > > > >Ever thought of trying it with plain C ? > >Best regards, > > >Michael > > > -----Urspr=FCngliche Nachricht----- > > Von: sdc...@li...=20 > > > [mailto:sdc...@li...] > Im Auftrag von=20 > > Olaniyi Bajomo > > Gesendet: Donnerstag, 13. M=E4rz 2003 15:45 > > An: sdc...@li... > > > Betreff: [Sdcc-user] Calculating IP Checksum > >=20 > >=20 > > Hello guys/Gals I have a small problem. I want biuld an=20 > > TCP/IP packet in my code and calculate the checksum for IP=20 > > and the TCP. but for some reason I can't get my checksum=20 > > program to so it. All it those is perfrom 16bit 2's=20 > > complement addition of a buffer that contains the IP pseudo=20 > > header, the TCP header and data. but I think there is a=20 > > problem when ever the summation results in 0xff in any of my=20 > > 8bit result registers as I dont think this is treated as a=20 > > carry or am I wrong? I have the code attached to=20 > > this email. if anyone has a better idea as to how to do this=20 > > p>lease let me know. thanks > >=20 > > ------------------------CODE STRIP----------------------------- > >=20 > > code unsigned int ip_checksum(xdata u_int16_t *Ip_Pak, int=20 > > pckLength) { > > Ip_Pak; > > pckLength; > > // first 16bit set to r1 r2 > > // second 16bit set to r5 r6 > > // pckLength set to _ip_checksum_PARM_2 > > _asm > > =09 > > mov r3, _ip_checksum_PARM_2 > > mov r4, (_ip_checksum_PARM_2+1) > > mov a ,r3 // divide lenght by 2 > > clr c // clear carry > > rrc a // shift lower length by 1 to right > > mov r3,a // save lower > > mov a,r4 =20 > > clr c > > rrc a // shift high length by 1 to right > > mov r4,a // save higher > > movx a, @dptr > > mov r1,a // get high byte of 16 bit numer > > inc dptr > > movx a, @dptr > > mov r2,a // get lower byte of 16bit number > > dec r3 > > loop: > > inc dptr > > movx a, @dptr =20 > > mov r5, a // get next number > > inc dptr > > movx a, @dptr > > add a,r2 // add lower bytes > > mov r2,a > > ;clr a > > mov a,r1 > > addc a,r5 // add carrys > > ;add a,r5 // add higher byte > > mov r1,a // store addition=20 > > clr a > > addc a,r2 // add carry to lower byte > > mov r2,a > > djnz r3 , loop > > cjne r4,#0x00,high > > finish: > > mov a, r1 > > cpl a > > mov dph,a > > mov a, r2 > > cpl a > > mov dpl,a > > ajmp end > > high: > > djnz r4,loop > > ajmp finish > > end: > > _endasm; > > } > > ------------------END CODE STRIP----------------------------- > -- > _______________________________________________ > Sign-up for your own FREE Personalized E-mail at Mail.com > http://www.mail.com/?sr=signup > > > > ------------------------------------------------------- > This SF.net email is sponsored by:Crypto Challenge is now open! > Get cracking and register here for some mind boggling fun and > the chance of winning an Apple iPod: > http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0031en > _______________________________________________ > Sdcc-user mailing list > Sdc...@li... > https://lists.sourceforge.net/lists/listinfo/sdcc-user > |