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

Discussion in 'Embedded Systems and Microcontrollers' started by bug13, Jan 22, 2018.

  1. bug13

    Thread Starter Senior Member

    Feb 13, 2012
    1,692
    62
    Hi guys

    Just an simple question, say I have a constant
    Code (Text):
    1. 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!
     
  2. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    7,815
    3,716
    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.
     
  3. MrChips

    Moderator

    Oct 2, 2009
    19,138
    6,150
    It will take 6 bytes.
    Modern 16-bit and 32-bit MCUs will pack bytes as required into multi-byte memory locations.
     
  4. bug13

    Thread Starter Senior Member

    Feb 13, 2012
    1,692
    62
    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.
     
  5. bug13

    Thread Starter Senior Member

    Feb 13, 2012
    1,692
    62
    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?
     
  6. MrChips

    Moderator

    Oct 2, 2009
    19,138
    6,150
    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.
     
  7. bug13

    Thread Starter Senior Member

    Feb 13, 2012
    1,692
    62
    Thanks for the quick reply, appreciated it!
     
Loading...