specify constant with gcc-as for ARM?

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View


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

    dcd   #0x12345678

   more code...

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

Thanks a lot!

Re: specify constant with gcc-as for ARM?
Quoted text here. Click to load it

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:


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
We've slightly trimmed the long signature. Click to see the full one.
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!


Re: specify constant with gcc-as for ARM?
Quoted text here. Click to load it

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

Site Timeline