hi, my MCU is C8051F330 from silicon labs, it has 8Kbytes of flash and 768 bytes of ram memory my compiler is keil, I d'like to know whether keil is allocating space memory for my data in tne ram or in the flash memory. and how kan I chose to write in the ram or in the flash. P.S:I'm coding in C language. thx :)
The short answer is probably "RAM".
The 8051 has a number of different address spaces. "Data" memory is the 128 (or 256) bytes in the processor core. "Xdata" memory is the large memory space outside of this memory, accessible via the DPTR and the MOVX instruction. The actual program is kept in "code" memory, which is a separate address space using different signals on the core.
Many designs map the code memory into the xdata space as well, so that you can write the code memory. This is useful for upgrading the program in the field.
If your flash is mapped into the xdata space, then that exists along with (probably) 512 bytes of that RAM. The data sheet will tell you the address ranges. Keil will typically allocate memory from the lowest addresses upward. If you want a variable to reside in the flash address space, then you can use linker directives or the _at_ extension to fix the address of the variable.
Note that flash memory also usually requires some sort of little dance in the code to unlock it and overwrite a byte of memory. A simple assignment instruction won't do. You might have built-in flash access routines in your part, or the data sheet might document the programming sequence that you have to follow, whether that's touching a register or creating certain patterns on the address and data busses. Storing data in flash isn't quite as simple as just declaring variables in that address range. Reading flash is usually a straightforward microprocessor memory read instruction; writing it usually involves calling a function to copy some values to a destination address.
Most likely, the flash memory in your part is intended for storing the program, not data. Read the data sheet carefully, and see how many independent sectors of flash memory you have. With flash, you typically erase an entire "sector" at one time. You'll normally have more than one sector so you can execute from one while erasing another.
If you use a sector for data, then you'll lose the entire contents of the sector when you erase the flash to update one variable. "Erasing" flash means setting all the bits to 1. "Programming" flash means setting some bits to 0. You can't set individual bits in a flash array to 1 without erasing them all. So to set the value of one variable more than once, you need to be prepared to restore all the others, too. (Flash memory generally is used with more complex data structures or a file system to handle updates to data, rather than just acting as a RAM array.)