??? 05/16/05 12:59 Modified: 05/16/05 13:05 Read: times |
#93492 - C, memory, and address spaces Responding to: ???'s previous message |
Sachin B.a said:
Hi,
I agree that I can write the a value in the specified memory location. 8051 is harward arch based. Data and code memory spce are separate. if I assign a value to a memory location..how the compiler will come to know that it has to store that value in data memory. since that address will be there in code memory also. please clarify me... -sachin The compiler typically makes assumptions for you unless you tell it otherwise. For example, in Keil, consdider this declaration: char x;In the absence of a memory-space specific declaration, the compiler will assume that this is a variable declaration for storage in memory, and will probably store it in data or xdata, depending on the settings for your project (such as memory model). Unless you specify the location of the variable with the _at_ keyword, the exact location of the variable will usually be determined by the toolchain's overlay analysis, which basically uses the same space in memory for multiple variables, so long as they can be proven to be not used simultaneously. Now, continuing the Keil example, imagine that you have a declaration for a pointer: char *xptr;Once again, the compiler assumes that the pointer itself is a variable declaration for storage in memory, and will decide upon a location for it just like it did for the earlier declaration. But, the new pointer could be used to point to data in a variety of locations, including data, xdata, and code memory spaces. Why is this possible? Because the pointer is a generic pointer. It is stored using three bytes, one of which represents the memory type, and the other two of which represent the actual offset in that particular memory region. If you do not need the versatility of being able to have the pointer point to data in any address space, you can use a memory-specific pointer, which will both require less space for the pointer itself, and results in code that executes faster. --Sasha Jevtic |
Topic | Author | Date |
Writing into Data memory of 8051 in C | 01/01/70 00:00 | |
Writing into Data memory of 8051 in C | 01/01/70 00:00 | |
Writing into Data memory of 8051 in C | 01/01/70 00:00 | |
Writing into Data memory of 8051 in C | 01/01/70 00:00 | |
its very clever | 01/01/70 00:00 | |
SDCC | 01/01/70 00:00 | |
writing a value in data memory 8051 | 01/01/70 00:00 | |
8051 harvard arch. then how its possible | 01/01/70 00:00 | |
C, memory, and address spaces | 01/01/70 00:00 | |
its even simpler![]() | 01/01/70 00:00 |