3 Replies Latest reply on Jan 11, 2017 11:32 PM by RaAl_264636

    wrong assembler output when using bitwise inversion?






      I've a problem with a simple comparison of two variables. Both are of type uint8_t, one contains the bitwise inversion of the other (0x80 and 0x7F). The comparison is 'if(A == ~B) {...}. I'd expect true as result of the comparison. However, debbuging the disassembly shows that the result of ~B is 0xFFFFFF80 is stored in the register, therefore the compare instruction fails.


      IMHO this is a bug, because both variables are of type uint8_t, so the result of the inversion should be stripped down to 8 bit. Used PSoC Creator version is 3.3 CP3 & 4.0, GCC for both Creator installations is 'ARM GCC 4.9-2015-q1-update'. Used hardware is a CY8CKIT-059.


      Attached is a simple project to show the behaviour. If the variables are made non-volatile, the optimization level must be set to 'none', otherwise the test loop would be optimized out.