1 Replies - 1693 Views - Last Post: 01 October 2016 - 05:46 AM

#1 amar712   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 30-September 16

ARM assembly code error saying undefined reference to `a'

Posted 30 September 2016 - 04:18 PM

I am running ARM assembly code to initialize array a. I get the error saying undefined reference to `a'. I am using gcc to compile Here is the code

.text
.global main
main:
ldr r0, addr_of_a // r1 = *a
mov r1, #0 // Index i
loop: str r1, [r0] // a[i] = i
add r0, r0, r0, lsl #2 // Increment address by 4 bytes
add r1, r1, #1 // r1 = r1 + 1
cmp r1, #100
bne loop
end:
mov r0, r1
bx lr
addr_of_a: .word a

Is This A Good Question/Topic? 0
  • +

Replies To: ARM assembly code error saying undefined reference to `a'

#2 turboscrew   User is offline

  • D.I.C Lover
  • member icon

Reputation: 171
  • View blog
  • Posts: 1,110
  • Joined: 03-April 12

Re: ARM assembly code error saying undefined reference to `a'

Posted 01 October 2016 - 05:46 AM

In the last line you define a word with value of 'a' (a name) that isn't defined anywhere. There should be a value (the address), or you should define the 'a' as the address.

Be careful about when you need the contents of a location and when the address of the location.

Also this:
add r0, r0, r0, lsl #2 // Increment address by 4 bytes
looks weird.

[Edit]
Forgot: If you are using address_of_a as a pointer variable to (array variable) a, where's the a itself?

This post has been edited by turboscrew: 01 October 2016 - 05:50 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1