This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Assembly access of variables defined in C

Hello,

 

I was porting from the TI compiler to the  IAR compiler for TMS570LS20216.

I had a variable in C and wanted to access it from assembly

TI compiler

UInt32 var_pattern;

__asm("VAR_PATTERN_A:    .field      var_pattern, 32");

void xyz(void)

{

    __asm("    LDR R3,VAR_PATTERN_A");

 

}

 

IAR Compiler

When i try i am getting the relocation error.

 

I found the following section in IAR C/C++ Development Guide but i was not able to get much information on solving it.

Possible solutions
In this case, the distance from the instruction in getchar to __read is too long for the
branch instruction.
Possible solutions include ensuring that the two .text sections are allocated closer to
each other or using some other calling mechanism that can reach the required distance.
It is also possible that the referring function tried to refer to the wrong target and that
this caused the range error.
Different range errors have different solutions. Usually, the solution is a variant of the
ones presented above, in other words modifying either the code or the section
placement.

 

 

Can you please let me know how i can do the same using the IAR compiler.

 

With Best Regards,

Renjith George

  • Hi, according to ARM architecture reference manual,

    the memory address you will access is calculated from the pc and an immediate address by default.

    so, as you wrote,  __asm("    LDR R3,VAR_PATTERN_A");

    the memory location this instruction will access is at   pc + VAR_PATTERN_A,  maybe this is not what you expect.

    so, a base address needs to be supplied in corresponding instruction

    like instruction  "LDR, Rt, Rn, #imm",

    #imm is the immediate offset from base address,

    Rn contains the base address.

     

    Hope this could help you even a little.

    Good luck.

     

    Shawn

  • Hello,

     

    i examined how the global variables are accesed when using IAR linker

        __asm(" LDR R2, DataTable22_1");

    __asm("  ??DataTable22_1:     0x08000f08      DC32    stack_pattern ");

     

    But when i tried using the same in assembly it gave the following error -

    "C:\2_S\M_B\TS\SFiles\TSB\IAR630\d_drv.c",650  Error[Og005]: 
              Unknown symbol in inline assembly: "??DataTable22_1"

     

    Please let me know why it generates an error when i tried reproducing the same what it does internally when  dealing with a C global variable.

     

    Thanks in advance,

    Renjith George