simple question about flash memory of 8-bit/16-bit/32-bit MCU

Thread Starter

bug13

Joined Feb 13, 2012
2,002
Hi guys

Just an simple question, say I have a constant
Code:
char str[] = "HELLO";
In a 8-bit MCU, it will take 6 bytes flash memory. Now my question is, how many bytes will it take in a 16-bit/32-bit MCU. Will that take 12 bytes flash memory in a 16-bit MCU and 32 bytes flash memory in a 32-bit MCU? Or does it still take only 6 bytes?

I mainly use 8-bit MCU, but there is a project that I will need to use 16-bit MCU, and it looks like the flash memory in a 16-bit MCU is used up a lot faster for some simple code.

Thanks guys!
 

spinnaker

Joined Oct 29, 2009
7,830
It will depend on the MCU and maybe even the compiler but each character should take 8bits or 1 byte. You really should check your specific documentation to be sure. That is way it was written.
 

Thread Starter

bug13

Joined Feb 13, 2012
2,002
It will depend on the MCU and maybe even the compiler but each character should take 8bits or 1 byte. You really should check your specific documentation to be sure. That is way it was written.
Any pointer on which section should I be looking at? The flash and memory section? Compiler? The 16-bit MCUs I am talking about are MSP430 and the 32-bit MCUs are PIC32MM.
 

Thread Starter

bug13

Joined Feb 13, 2012
2,002
It will take 6 bytes.
Modern 16-bit and 32-bit MCUs will pack bytes as required into multi-byte memory locations.
That's good to know, how about memory use? I assume it will be packed bytes as required?

You mentioned multi-byte memory locations. Are you referring to a special memory location that you can pack bytes, or just a general memory location that everyone can use?
 

MrChips

Joined Oct 2, 2009
30,824
That's good to know, how about memory use? I assume it will be packed bytes as required?

You mentioned multi-byte memory locations. Are you referring to a special memory location that you can pack bytes, or just a general memory location that everyone can use?
By multi-byte, I mean if memory is organized as 16-bit words, you get two bytes packed into one word.

MSP430 may be a 16-bit processor but memory is still organized in 8-bit locations. There is nothing special for you to worry about.
Generally, constant bytes are stored in CODE space, i.e. in FLASH memory.
 

Thread Starter

bug13

Joined Feb 13, 2012
2,002
By multi-byte, I mean if memory is organized as 16-bit words, you get two bytes packed into one word.

MSP430 may be a 16-bit processor but memory is still organized in 8-bit locations. There is nothing special for you to worry about.
Generally, constant bytes are stored in CODE space, i.e. in FLASH memory.
Thanks for the quick reply, appreciated it!
 
Top