title: ARM Assembly error: A1898E: Target cannot be relocated. No suitable relocation exists for this instruction
body: <p>I am trying to write simple program to sum up data in array, but I get this error </p>
  
  <pre><code>error: A1898E: Target cannot be relocated. No suitable relocation exists for this instruction
  </code></pre>
  
  <p>Here is my code</p>
  
  <pre><code>    AREA SUMARRAY, CODE, READONLY
      EXPORT __main
      ENTRY
  __main
      LDR r2, LENGTH
      SUB r2, r2, #1 ; r2 contains (LENGTH-1)
      MOV r6, #0 ; r6 sum set to 0
  FOR_INIT MOV r1, #0 ; r1 index I set to 0
      ADR r3, ARRAY ; start r3 with address of A[0]
  FOR_CMP CMP r1, r2 ; compare I and (LENGTH-1)
      BGT END_FOR ; drop out of loop if I &lt; (LENGTH-1)
      LDR r4, [r3],#4 ; load r4 with A[I] then walk r3 down ARRAY
      ADD r6, r6, r4 ; update sum with A[I]
      ADD r1, r1, #1 ; increment I
      B FOR_CMP ; loop back to for-loop check
  END_FOR
      STR r6, SUM ; store result in SUM
  STOP B STOP
      AREA my_data, DATA, READWRITE 
      ALIGN
  SUM DCD 0XFFFFFFFF
  ARRAY DCD 1,5,20,32,13,66,3,5,23,64,112,66,22   
  LENGTH DCD 13
  </code></pre>
  
  <p>Compiler says that problem is in this line </p>
  
  <pre><code>ADR r3, ARRAY ; start r3 with address of A[0]
  </code></pre>
  
  <p>What is wrong with this code ? Could someone explain why this error appears ? 
  And how can I fix it ? </p>
  
  <p>Thanks.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <pre><code>    AREA Sorting, CODE, READONLY
      EXPORT __main
      ENTRY
  __main
      LDR r2, LENGTH
      SUB r2, r2, #1 ; r2 contains (LENGTH-1)
      MOV r6, #0 ; r6 sum set to 0
  FOR_INIT MOV r1, #0 ; r1 index I set to 0
      LDR r3, =ARRAY ; start r3 with address of A[0]
  FOR_CMP CMP r1, r2 ; compare I and (LENGTH-1)
      BGT END_FOR ; drop out of loop if I &lt; (LENGTH-1)
      LDR r4, [r3],#4 ; load r4 with A[I] then walk r3 down ARRAY
      ADD r6, r6, r4 ; update sum with A[I]
      ADD r1, r1, #1 ; increment I
      B FOR_CMP ; loop back to for-loop check
  END_FOR
      STR r6, SUM ; store result in SUM
  STOP B STOP
      LTORG
      AREA my_data, DATA, READWRITE 
      ALIGN
  SUM DCD 0XFFFFFFFF
  ARRAY DCD 1,5,20,32,13,66,3,5,23,64,112,66,22   
  LENGTH DCD 13
  </code></pre>
  
  <p>But in this case I get errors </p>
  
  <pre><code>Error: L6286E: Relocation #REL:0 in sorting.o(SUMARRAY) with respect to LENGTH. Value(0x3fffff18) out of range(0 - 0xfff) for (R_ARM_LDR_PC_G0)
  Error: L6286E: Relocation #REL:1 in sorting.o(SUMARRAY) with respect to SUM. Value(0x3ffffeb4) out of range(0 - 0xfff) for (R_ARM_LDR_PC_G0)
  </code></pre>