This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Unable to set variables' values

I am running the following code, compiled (with no optimisation) by ARMCC 5.06u7, in MDK 5.34.

The four 1B variables `ext_flag`, `coarse_bytes`, `fine_bytes`, and `timecode_id` are initialised to zero, not the values given. If I set them to those values again after initialisation, they remain zero.

If I make those variables static, the variables take on nonzero values, but not the ones given here.

It is so strange, and I have checked my sanity with two other programmers.

Has anyone encountered this behaviour before? Is this the Keil debugger, or the ARM compiler?

```

T_Result result = RESULT_OK;

T_Utils_Result utils_result = UTILS_RESULT_OK;

uint8_t ext_flag     = 0x80;
uint8_t coarse_bytes = 0x0C;
uint8_t fine_bytes   = 0x03;
uint8_t timecode_id  = 0x70;

ext_flag &= buffer[0];
ext_flag >>= POSITION_EXT_FLAG;

coarse_bytes &= buffer[0];
coarse_bytes >>= POSITION_COARSE_BYTES;

fine_bytes &= buffer[0];
fine_bytes >>= POSITION_FINE_BYTES;

if ((NO_EXTENDED_PREAMBLE != ext_flag)     ||
    (COARSE_BYTES         != coarse_bytes) ||
    (FINE_BYTES           != fine_bytes))
{
    result = RESULT_INVALID_PACKET;
}

```

Here is the disassembly, which is clearly not intended:
```

0x0000593A E92D5FFC  PUSH          {r2-r12,lr}
0x0000593E 4604      MOV           r4,r0
0x00005940 4688      MOV           r8,r1
0x00005942 4615      MOV           r5,r2
    95:     T_Result result       = RESULT_OK;
0x00005944 2700      MOVS          r7,#0x00
    96:     T_Utils_Result          utils_result = UTILS_RESULT_OK;
    97:      
0x00005946 46B9      MOV           r9,r7
    98:     uint8_T ext_flag     = 0x80;
0x00005948 46BA      MOV           r10,r7
0x0000594A 2000      MOVS          r0,#0x00
    99:     uint8_T coarse_bytes = 0x0C;
0x0000594C 9001      STR           r0,[sp,#0x04]
0x0000594E 4683      MOV           r11,r0
   100:     uint8_T fine_bytes   = 0x03;
0x00005950 2600      MOVS          r6,#0x00
0x00005952 9000      STR           r0,[sp,#0x00]

```

Any ideas?