-1

I googled it but could not find anything, I am new to assembly, I have a symbol definition which I think equal of #define statements of C.

FIRST       EQU         0x20000480

In __main, I want to load this 0x20000480 value into R1 register, So I have the following code,

LDR         R1, FIRST

This gives an error of

main.s(65): error: A1150E: Bad symbol, not defined or external

If I insert a "=" in front of the FIRST,

LDR         R1, =FIRST

Then it builds fine.

Can anybody explain the use of "=" operator(if it is an operator) here?

muyustan
  • 1,555
  • 1
  • 11
  • 23
  • 2
    `LDR R1, FIRST` is an actual instruction that loads from memory, `LDR R1, =FIRST` is a pseduoinstruction that will be implemented by the assembler and loads the address. – Jester Nov 01 '20 at 12:14
  • So you are trying to program in assembly language without definitive documentation of the syntax that the assembler uses right at your finger tips? As if assembly language programming weren't hard enough. – andy mango Nov 01 '20 at 16:00
  • Assembly is specific to the tool (not target). Not all handle this pseudo instruction equally if they support it at all. Note this topc has been covered here many times. Please look first before asking. – old_timer Nov 01 '20 at 16:34
  • @andymango Maybe it's just me, but ARM assembly was the easiest one. And the OP seems to be using Keil or ARM Development Studio given the `EQU` directive. It took a while for me, too to get used to GCC assembly syntax. – Jake 'Alquimista' LEE Nov 01 '20 at 17:35
  • 2
    @old_timer Newbies typically don't even know the right keyword when searching. Let's be not so harsh. – Jake 'Alquimista' LEE Nov 01 '20 at 17:38
  • @Jake'Alquimista'LEE thank you, I had really tried several times googling it to find. – muyustan Nov 02 '20 at 19:47

1 Answers1

2

The "=" indicates a possible literal pool access. The ldr instruction is a pseudo instruction in this case that translates to one of mov, mvn, or ldr [pc, #offset]

source code:

ldr     r0, =0xff
ldr     r1, =0xffffffff
ldr     r2, =0xf00000ff

disassembly:

mov     r0, #0xff
mvn     r1, #0x00
ldr     r2, [pc, #offset]

0xff can be expressed by the 12bits of space as well as 0 (~0xffffffff) and thus it translates to mov and mvn respectively.
http://www.davespace.co.uk/arm/introduction-to-arm/immediates.html

On the other hand, because it's not the case with 0xf00000ff, a literal pool access is due in form of a pc relative load.

On armv7 however, you can load the register with any 32bit value thanks to the movw and movt instructions which is preferable over a memory access

movw    r2, #0xffff // ANY 16bit value
movt    r2, #0xf000 // ANY 16bit value to the upper part without corrupting the lower one
Jake 'Alquimista' LEE
  • 6,197
  • 2
  • 17
  • 25