Do you have a question? Post it now! No Registration Necessary
Subject
- Posted on
specify constant with gcc-as for ARM?
- 03-12-2006
March 12, 2006, 8:55 pm

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!

Re: specify constant with gcc-as for ARM?

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
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!
Philipp.

Re: specify constant with gcc-as for ARM?

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
Tauno Voipio
tauno voipio (at) iki fi
Site Timeline
- » [ANN] KLone-DevKit released
- — Next thread in » Embedded Linux
-
- » uClinux on x86 disabled MMU
- — Previous thread in » Embedded Linux
-
- » Crosscompiling for ARM: reloc type R_ARM_ABS32 is not supported for PIC - ...
- — Newest thread in » Embedded Linux
-
- » Das Ende der Akkuprobleme in Sicht!
- — The site's Newest Thread. Posted in » Electronics (German)
-
- » Replacement for 741
- — The site's Last Updated Thread. Posted in » Electronics Design
-