This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

program run from different RAM address (ARM)

I want to write a function (ARM) that will run in a different initial RAM addresses. Part of the program in ASM, and part of C. The problem is that variables declared in the ASM, as seen in C are still in the same address.

EXP:

in asm file:

test_val  dcd     0x5555555
          export  test_val
          BLX     main_c_code


in C file:

extern  int test_val;
void main_c_code(void){
...
  test_val = 0xAAAAAAAA;
...
}

after build everything works, when it loads the applications to address eg 0x1000 (default)
test_val is at addr. eg. 0x1004
but when you want to load applications to address eg 0x2000, Part C test_val still fits the data to addr 0x1004 instead of 0x2004. how to force the compiler to the use of

ADR R0, test_val


instead of

LDR R0, = 0x4

Parents
  • Note that unless you have position-independant code, you can't just change the load address of code.

    One of the steps performed by the linker, is to compute the address of all the different parts of the application. This includes addresses of functions and global variables.

    When the program runs, everything is just memory. "Address of" doesn't really exist. You can of course perform relative address computations. But computations relative to what? If the function is expected to be loaded into RAM, and the variable is n bytes before the function code, then the variable can be seen as having an address relative to the function.

    But the normal way to handle global variables is that they have an absolute address. And the linker fills in that address based on the memory regions you have specified.

Reply
  • Note that unless you have position-independant code, you can't just change the load address of code.

    One of the steps performed by the linker, is to compute the address of all the different parts of the application. This includes addresses of functions and global variables.

    When the program runs, everything is just memory. "Address of" doesn't really exist. You can of course perform relative address computations. But computations relative to what? If the function is expected to be loaded into RAM, and the variable is n bytes before the function code, then the variable can be seen as having an address relative to the function.

    But the normal way to handle global variables is that they have an absolute address. And the linker fills in that address based on the memory regions you have specified.

Children