simple test code for the purpose.
To form 32bit integer in RAM area, however ~() will renders result with -0x00000100.
why ? a bug ?
// sdcc 3.6.0
// build script,
// sdcc -mhc08 --data-loc 0x80 --code-loc 0xEE00 --stack-loc 0xFF sdcc360_bug.c -o sdcc360_bug.S19
// perhaps bug, why ~() and -0x0100
// 2018-OCT-28
#define MOD 0xBEBE0000
#include <mc68hc908qy.h>
volatile unsigned long int value;
void main() {
// supposedly same long value
value = (0xBEBE7B84);
value = (0xBEBE0000 + 0x7B84);
value = (0xBEBE0000 + 0x7B00 + 0x84);
value = (MOD + 0x7B00 + 0x84);
value = (0xBEBE7B00 + ~0x7B); // it is odd, -0x0100
value = (0xBEBE0000 + 0x7B00 + ~0x7B); // it is odd, -0x0100
value = (MOD + 0x7B00 + ~0x7B); // it is odd, -0x0100
// supposedly same long
value = (0xBEBEFF01);
value = (0xBEBE0000 + 0xFF01);
value = (0xBEBE0000 + 0xFF00 + 0x01);
value = (MOD + 0xFF00 + 0x01);
value = (0xBEBE0000 + 0xFF00 + ~0xFE); // it is odd, -0x0100
value = (MOD + 0xFF00 + ~0xFE); // it is odd, -0x0100
}
```
asm show the same odd thing,
i.e. #0x7b is expected,
EE5E A6 7B [ 2] 232 lda #0x7b
this one is about #0x7b-1 = 0x7a
final result is always -0x00000100,
EE6E A6 7A [ 2] 241 lda #0x7a
227 ;sdcc360_bug.c:17: value = (MOD + 0x7B00 + 0x84);
EE56 45 00 80 [ 3] 228 ldhx #_value
EE59 A6 BE [ 2] 229 lda #0xbe
EE5B F7 [ 2] 230 sta ,x
EE5C E7 01 [ 3] 231 sta 1,x
EE5E A6 7B [ 2] 232 lda #0x7b
EE60 E7 02 [ 3] 233 sta 2,x
EE62 A6 84 [ 2] 234 lda #0x84
EE64 E7 03 [ 3] 235 sta 3,x
236 ;sdcc360_bug.c:18: value = (0xBEBE7B00 + ~0x7B); // it is odd, -0x0100
EE66 45 00 80 [ 3] 237 ldhx #_value
EE69 A6 BE [ 2] 238 lda #0xbe
EE6B F7 [ 2] 239 sta ,x
EE6C E7 01 [ 3] 240 sta 1,x
EE6E A6 7A [ 2] 241 lda #0x7a
EE70 E7 02 [ 3] 242 sta 2,x
EE72 A6 84 [ 2] 243 lda #0x84
EE74 E7 03 [ 3] 244 sta 3,x
~~~
latest release of sdcc 3.8.0 has gone through same compiling process, the problem persisted,
~0xfe is not 0x84.
Philipp
P.S.: (uint8_t)(~0xfe) is 0x84.
Last edit: Philipp Klaus Krause 2018-10-28
sorry. could not follow, do you have complete example.
there are perhaps 1's complement and the 2's complement, i.e.,
0x7b,
1's complement = 0x84 (NOT 0x7B)
2's complement = 0x85 (-0x7B)
The constant is an integer, not an unsigned char.
~0x7B == ~0x007B == 0xFF84