Your PROGRAM will define where the data goes - either to a specific register or to an address in RAM.
When you code for a microcontroller it is essential that you are aware of the architecture. Data can be stored in many locations:
- ROM (FLASH)
- EEPROM
- RAM
- Registers
Which storage location you use depends on several factors. Typically variables would be stored in RAM, constants in FLASH. However, commonly data structures are copied from FLASH to RAM at startup so even constants use valuable RAM space. If RAM is scarce, you may be able to keep constants in FLASH. The AVR family of microcontrollers uses the
PROGMEM directive to achieve this. You save RAM at the cost of execution speed.
For temporary variables e.g.loop counters it may be advantageous to explicitly assign them to registers instead of RAM as register access is usually faster than RAM access. Another directive
REGISTER tells the compiler that the variable should be placed in a register although there is no guarantee that it is really assigned to a register. If all available registers are used by other data, the compiler will use a RAM location instead.
Reading an Writing to EEPROM has the advantage that data is kept save even during power outages. But you cannot simply write to an EEPROm, you need to use an EEPROM programming routine.Again, that is usually taken care of by suitable libraries.