Skip to main content

IAR Embedded Workbench for RH850 3.20.x

The base-relative memory access method

In this section:

The base-relative (brel) access method can access two memory areas of 64 Kbytes, one in RAM and one in ROM. Unlike the near memory, the brel memory areas can be placed anywhere in memory.

There are two linker-generated assembler labels, __iar_static_base$$GP and __iar_static_base$$TP, located in the middle of the brel memory areas. The processor register R4—also known as GP—and the processor register R5 (TP) are initialized to these values.

The assembler code for writing to the brel RAM area is:

         st.w    R1, relgp(x)[GP]

For the brel RAM area, the displacement used is the value of the expression RELGP(x), where x refers to the absolute location of the variable x.

The assembler code for reading from the brel ROM area is:

         ld.w    reltp(y)[TP],R1

It works the same way as the code for the RAM area.

Examples

Address of:

        movea       relgp(MyVar),gp,r1

Reading a global variable:

        ld.b        relgp(MyVar)[gp],r6

Reading a global array using an unknown index:

        add         gp,r1
        ld.b        relgp(MyArr)[r1],r7

Reading a structure using a pointer:

        ld.b        (4)[r6],r1