specify constant with gcc-as for ARM? - Embedded

This is a discussion on specify constant with gcc-as for ARM? - Embedded ; Hello! I am currently diving into assembly programming on the ARM family of processors. I have quite some experience in 680x0 assembly and with the ARM Reference Manual I have almost all I need. The only thing I couldn't figure ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: specify constant with gcc-as for ARM?

  1. specify constant with gcc-as for ARM?


    Hello!

    I am currently diving into assembly programming on the ARM family of
    processors. I have quite some experience in 680x0 assembly and with the
    ARM Reference Manual I have almost all I need. The only thing I
    couldn't figure out is how to produce a constant in the .text section
    of the code for constants longer than the immediate values that can be
    specified inside an opcode. I tried something like this:

    ldr r0, myconst
    b continue

    myconst:
    dcd #0x12345678

    continue:
    more code...

    What is the way to do this with arm-linux-as?

    Thanks a lot!


  2. Re: specify constant with gcc-as for ARM?

    grond@cs.tu-berlin.de wrote:
    > Hello!
    >
    > I am currently diving into assembly programming on the ARM family of
    > processors. I have quite some experience in 680x0 assembly and with the
    > ARM Reference Manual I have almost all I need. The only thing I
    > couldn't figure out is how to produce a constant in the .text section
    > of the code for constants longer than the immediate values that can be
    > specified inside an opcode. I tried something like this:
    >
    > ldr r0, myconst
    > b continue
    >
    > myconst:
    > dcd #0x12345678
    >
    > continue:
    > more code...
    >
    > What is the way to do this with arm-linux-as?
    >
    > Thanks a lot!



    The trick is called a literal:

    ldr r0,=0x12345678

    and if the module is longer than 4 kbytes from the literal,
    it needs the literal pool directive in the code outside of
    program flow. With GNU assembler it's simply:

    .lpool

    The distance limit comes from the processor addressing
    structure. In Thumb mode it's shorter, but long enough
    for all sensible code pieces.

    ---

    Your method works, if it's written:

    ldr r0,myconst
    b continue

    myconst: .word 0x12345678

    continue:

    ---

    HTH

    --

    Tauno Voipio
    tauno voipio (at) iki fi

  3. Re: specify constant with gcc-as for ARM?


    So I could just use constants using the =0x12345678 and the assembler
    will find a place to put the constant and will produce code that loads
    the constant? Only if the code is larger than 4kB (one code page?) I
    need to tell it where to put the constants by giving the .lpool
    directive. That's simple...

    Thank you very much!

    Philipp.


  4. Re: specify constant with gcc-as for ARM?

    grond@cs.tu-berlin.de wrote:
    > So I could just use constants using the =0x12345678 and the assembler
    > will find a place to put the constant and will produce code that loads
    > the constant? Only if the code is larger than 4kB (one code page?) I
    > need to tell it where to put the constants by giving the .lpool
    > directive. That's simple...



    Roughly so. The determining factor is how far the PC-relative
    addressing reaches from the literal, so the limit is to have
    either .lpool or .end before 4 kbytes are generated since the
    first literal reference.

    Of course, the constant can be any expression solvable by
    the assembler, it's not limited to hex numbers only.

    If you're using Thumb mode, the addressing reach is shorter.
    Check the ARM ARM (Arcihtecture Reference Manual) for details.

    --

    Tauno Voipio
    tauno voipio (at) iki fi

+ Reply to Thread