Compiler Memory Allocation

BobTPH

Joined Jun 5, 2013
11,515
I think, In AT89S52, when we have global or static variables in the program, they should have fixed memory locations, and the linker will assign locations for them at link time.
Yes, that is correct. And the compiler also tells the linker what locations in the program code must be fixed up with the addresses assigned by the linker.
 

Thread Starter

Kittu20

Joined Oct 12, 2022
511
Yes, that is correct. And the compiler also tells the linker what locations in the program code must be fixed up with the addresses assigned by the linker.
I also think memory allocate for local variable when program run on hardware.

Specifically, I want to understand dynamic memory allocation, which occurs at runtime on the actual hardware. Does dynamic memory allocation happen when the processor executes the malloc function? I think it happens
 

BobTPH

Joined Jun 5, 2013
11,515
also think memory allocate for local variable when program run on hardware.
Local variables are either assigned to registers by the complier, sometimes more than one to the same register, or they are placed on the stack. Do you have any concept of what a stack frame is and how it works? That is necessary to understand local variable allocation.

Note that, when a function is called recursively, there are multiple copies of the local variables.
 

Papabravo

Joined Feb 24, 2006
22,082
I think, In AT89S52, when we have global or static variables in the program, they should have fixed memory locations, and the linker will assign locations for them at link time.
Variables would be in the program space ONLY if they were constants. There is no instruction that is able to modify the program memory space. The MOVC instruction is only capable of reading from program memory space. It uses the signal PSEN* (Program Store Enable*) to read data on to the data bus. The MOVX instruction will use RD* or WR* to read or write data respectively from RAM. Having three control signals effectively doubles the available memory space from 64K to 128K, but half of that space is READ ONLY.
 
Top