This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

(VARIABLE NOT HOLDING OVERFLOW IN CHECKSUM)

Hello
iam working on cygnal microcontrollers c8051f124,iam performing checksum as i written below.
The datas are written in external memoryarea
when iam performing checksum at 4th byte operation iam exeeding the 8 bit register value ie sum=7b+ff=17a(378 inn decimal)
but microcontroller is holding only 0x007a its ignoring overflow 1.but i defined sum as unsigned short int its not holding the overflow of ff value
what i have to do now?

johne
char xdata test_string[100]_at_ 0x5555={0x0f,0x2e,0x3e,0xff,0xff,0x00,0xfe,0xff};
void main()
{
int x=8,y;
unsigned short int sum=0;
for(y=0;y<8;++y)
{
sum=sum+test_string[y];
if(sum>0xff)
{
sum=sum-0xff;
}
}
test_string[y]=0xff-sum;
test_string1[100]=test_string[100];
printf("checksum=%x\n",test_string[y]);
}

Parents
  • "microcontroller is holding only 0x007a its ignoring overflow"

    How do you know this?
    Are you relying on your printf output?

    printf("checksum=%x\n",test_string[y]);
    remember that %x requires an int value to print - you are giving it only a char

    You need to specify %bx for a single byte - see the Manual
    test_string1[100]=test_string[100];
    The maximum index for your test_string array is 99 - not 100.
    This will over-write whatever data happens to be stored immediately after the test_data array...!

Reply
  • "microcontroller is holding only 0x007a its ignoring overflow"

    How do you know this?
    Are you relying on your printf output?

    printf("checksum=%x\n",test_string[y]);
    remember that %x requires an int value to print - you are giving it only a char

    You need to specify %bx for a single byte - see the Manual
    test_string1[100]=test_string[100];
    The maximum index for your test_string array is 99 - not 100.
    This will over-write whatever data happens to be stored immediately after the test_data array...!

Children