When i run my code in keil simulator the variable __heap_base(which is a label in the startup file)does not contain the base of heap(i found the heap base to be 0x20000000) but it always shows 0x00000000. How to make the __heap_base to hold the correct value so that i can increment and decrement the heap base.
After trying some methods what i found out is that even if i store the address 0x20000000 as an unsigned 32 bit integer in a variable i am unable to access the memory location.
#include <stdint.h>
extern uint32_t __heap_base;
uint32_t memallocate(int size)
{
uint32_t temp=__heap_base;
__heap_base=__heap_base+size;
return temp;
}
int maina()
{
int *p=(int*)memallocate(sizeof(int));
*p=5;
return 0;
}
The memory adress 0x20000000 should hold the value 5
User contributions licensed under CC BY-SA 3.0