I think your ccdiv function in c80_lib is not correct?the example is following?
int tstary2 = {0xaabb, 0x99aa};
// sends a hexadecimal value to the UART printhex(hval) int hval; { char hbyte; char lbyte; char temp; hbyte = hval/256; //use the >>8 is ok lbyte = hval%256; //
sendbyte(hbyte);
sendbyte(lbyte);
temp = (hbyte & 0xf0)>>4;
if(temp > 9)
sendbyte('a'+temp-10);
else
sendbyte('0'+temp);
temp = (hbyte & 0x0f);
if(temp > 9)
sendbyte('a'+temp-10);
else
sendbyte('0'+temp);
temp = (lbyte & 0xf0)>>4;
if(temp > 9)
sendbyte('a'+temp-10);
else
sendbyte('0'+temp);
temp = (lbyte & 0x0f);
if(temp > 9)
sendbyte('a'+temp-10);
else
sendbyte('0'+temp);
}
printstr("Hex value: 0x"); printhex(tstary0); nl(); printstr("Hex value: 0x"); printhex(tstary1); nl();
the result of print as following?
When testing this bug report a different problem was found in the assembly code generated by the compiler. After fixing the problem, the bug could not be reproduced. Please check the updated compiler version (after it will be committed). Moti
think you for you reply rapidly! I update the compiler you have committed latest But the result is also the same:
the example is following?
int tstary2 = {0xaabb, 0x99aa};
// sends a hexadecimal value to the UART printhex(hval) int hval; { char hbyte; char lbyte; char temp; hbyte = hval/256; //use the >>8 is ok lbyte = hval%256; //
temp = (hbyte & 0xf0)>>4; if(temp > 9) sendbyte('a'+temp-10); else sendbyte('0'+temp);
temp = (hbyte & 0x0f); if(temp > 9) sendbyte('a'+temp-10); else sendbyte('0'+temp);
temp = (lbyte & 0xf0)>>4; if(temp > 9) sendbyte('a'+temp-10); else sendbyte('0'+temp);
temp = (lbyte & 0x0f); if(temp > 9) sendbyte('a'+temp-10); else sendbyte('0'+temp); }
printstr("Hex value: 0x"); printhex(tstary0); nl(); printstr("Hex value: 0x"); printhex(tstary1); nl();
the print result is :
I think the problem happen in your "ccdiv" function of c80_lib ????????????????????
This was a great riddle to solve. There is no bug in the compiler. In the above example the usage of shift right by 8 works (>>8) but division by 256 does not. The cause of the problem is that the div function is implemented SIGNED. The values in the example above are signed and the results are correct. Example:
0xaabb = 43707 UNSIGNED 43707 SIGNED = 43707 - 2^16 = -21829 -21829 / 256 = |-85.269...| = -85 -85 SIGNED = -85+256 = 171 UNSIGNED = 0xab !!!!!!
And thus the text printed to the UART for an integer value of 0xaabb is 0xabbb. The same is also true for the second value 0x99aa. Moti