Ad

When I'm Accessing Memory Values In My Microcontroller Why Is It Pointing To The End Of My Data Value?

I'm trying to get the value of at an address in memory in my microcontroller. The address is at 0x1fff7000 and that's the start of the memory block (so anything before is undefined). In my code I have char *ptr = (char *)BASE_ADDR; where #define BASE_ADDR ((uint32_t)0x1FFF7000). My value at 0x1FFF7000 is 0x12345678 and I know 100% that it's there.

In GDB, I'm doing (gdb) p/x *ptr and my return value is $6 = 0x78. Why is it at 0x78 and not returning 0x12345678 or even 0x12?

Ad

Answer

Because you have a little-endian system/mcu, which means least significant bytes are stored first. In your example, the 0x12345678, stored as a 32 bit integer, is going to look as 78 56 34 12 as raw data in memory.

Ad
source: stackoverflow.com
Ad