4 !!LICENCE!! Public Domain
5 !!AUTHOR!! Marc 'BlackJack' Rintsch
9 Compiler is build from cc65-snapshot-2.13.9.20101031 sources.
11 Expected results and also what I get from this without any optimisations
14 When I turn on ``-O``: 58096 and 58096. After swapping the two variable
15 declaration lines in `calculate_checksum()` the results are correct
18 But with ``--O --static-locals`` the results are incorrect again (31757
19 and 15408). ``--static-locals`` alone works though.
25 // uint16_t __fastcall__ calculate_checksum(uint8_t *block);
28 uint16_t calculate_checksum(uint8_t *block)
30 uint16_t i, result = 0xffff;
33 for (i = 0; i < 256; ++i) {
34 result ^= block[i] << 8;
35 for (j = 0; j < 8; ++j) {
36 if (result & (1 << 15)) {
37 result = (result << 1) ^ 0x1021;
50 printf("zeroes: %u\n", calculate_checksum(block));
51 for (i = 0; i < 256; ++i) block[i] = i;
52 printf("0..255: %u\n", calculate_checksum(block));