Forum : 8051
Original Post
Post Information | Post |
---|---|
April 4, 2008 - 3:51pm
|
Please consider this piece of code: void testif(unsigned int a) { data unsigned int b = 0; if (10 > (a - b)) { _nop_(); // correct } else { _nop_(); // wrong result !!!! } } void main() { testif(5); } Obviously 10 > (5 - 0) , but this test is compiled in a bad way, and the result is wrong. If I initialize b with 1 everything is ok, and the compiled code became very different void testif(unsigned int a) { data unsigned int b = 1; // ***** with this value the test is working ****** if (10 > (a - b)) { _nop_(); // correct } else { _nop_(); // wrong result !!!! } } void main() { testif(5); } This is the assembly code of the not working test: ; FUNCTION _testif (BEGIN) ; Register R6R7 is assigned to parameter a ; SOURCE LINE # 1083 0000 EE MOV A,R6 0001 9400 SUBB A,#000H ; here the carry is setted, and so the accumulator became 0xFF, probably the CLR C istruction is missing 0003 B40003 CJNE A,#000H,?LAB283 0006 BF0A00 CJNE R7,#00AH,?LAB283 0009 ?LAB283: 0009 5002 JNC ?ELSE109 ; SOURCE LINE # 1084 000B 00 NOP 000C 22 RET 000D ?ELSE109: ; SOURCE LINE # 1086 000D 00 NOP ; SOURCE LINE # 1088 000E 22 RET ; FUNCTION _testif (END) Please let me know what do you think. Thank you |
You are right. There is a bug due to the constant folding (substract with 0 should remove the two SUBB instructions, not only one in this specific case).
can you suggest a workaround ?
Massimo,
Can you provide your RC51 version or your Ride Build Number (BN) ?
Stéphane
Build number: BN746-51
RC51 Compiler: Version 3.03.42
Massimo,
Obviously the bug is due to the 'null value' for b that is improperly propagated. And 'a-0' is of course equivalent to a. Therefore the first workaround consists in not subtracting b from a when you are sure that b is zero.
Anyway we will send yo a patch.
Ok,
please give me the time frame for the patch, I have to schedule my activities.
I'd like also to receive a complete list of the known bugs, even if are not yet fixed.
We are using your compiler with hardwares that can be dangerous for human beings, so I must be informed about every trouble with the compiler.
For the last few years, there are only a few bugs reported within the 8051 compiler. You can find with each release the list of the fixed bugs. They are generally very specific (in your case, substracting a value known as 0 is not so frequent and it seems not to be present in our test suites...). Anyway, the patch you will receive does not contain any known bug...
good news....
when can you send me the patch ?
When the tests will be passed... It takes several hours.
The patch is ok.
Thank you very much for your support.