Modifying Array Entries in Inline Assembly: SOLVED

Hello,

I am trying to add entries to an array using inline assembly and then send the array out through the Native USB port on an Arduino Due

Currently I have a sensor connected to an Arduino Due that passes bytes of data that I am collecting.
I would like to place the bytes into the array using inline assembly code rather than using C code.

I have a working test code in C and I used the assembly dump from it to build a test version in assembly, but for some reason, it does not work.

C version:

uint32_t FIFO[512];

int cnt1 = 0;
int cnt2 = 0;

void setup() {
SerialUSB.begin(250000);
}

void loop() {
while(1)
{
  FIFO[cnt1] = 1;
  cnt1++;
  if (cnt1 == 512)
  {
    cnt1 = 0;
  }
  FIFO[cnt1] = 2;
  cnt1++;
  if (cnt1 == 512)
  {
    cnt1 = 0;
  }
  SerialUSB.println(FIFO[cnt2]);
  cnt2++;
  if (cnt2 == 512)
  {
    cnt2 = 0;
  }
  SerialUSB.println(FIFO[cnt2]);
  cnt2++;
  if (cnt2 == 512)
  {
    cnt2 = 0;
  }
}
}

Inline Assembly version:

uint32_t FIFO[512];
volatile uint32_t *addPointer = &FIFO[0];


int cnt = 0;

void setup() {  
SerialUSB.begin(250000);
}

void loop() {
  __asm__ volatile( "MOV R9, #0\n\t");
  __asm__ volatile( "LDR R8, [%0]\n\t" ::"r"(&FIFO)); //I believe this is where the problem is
while(1)
{  
  __asm__ volatile( "MOV R10, #1\n\t");
  __asm__ volatile( "STR.W R10, [R8, R9, LSL #2]\n\t");
  __asm__ volatile( "ADD R9, #1\n\t");  
  __asm__ volatile( "CMP.W R9, #512\n\t");
  __asm__ volatile( "ITE EQ\n\t");
  __asm__ volatile( "MOVEQ R9, #0\n\t");
  __asm__ volatile( "NOPNE\n\t");
   
  __asm__ volatile( "MOV R10, #2\n\t");
  __asm__ volatile( "STR.W R10, [R8, R9, LSL #2]\n\t");
  __asm__ volatile( "ADD R9, #1\n\t");
  __asm__ volatile( "CMP.W R9, #512\n\t");
  __asm__ volatile( "ITE EQ\n\t");
  __asm__ volatile( "MOVEQ R9, #0\n\t");
  __asm__ volatile( "NOPNE\n\t");


  SerialUSB.println(FIFO[cnt]);
  cnt++;
  if(cnt == 512)
  {
    cnt = 0;
  }

  SerialUSB.println(FIFO[cnt]);
  cnt++;
  if(cnt == 512)
  {
    cnt = 0;
  }  
}
}

I believe that the problem with the code is finding the correct memory address for the first entry spot of FIFO, but I have no idea where that memory address is or how to find it.

Thanks so much for your time

EDIT: See reply #2 for solution

I would like to place the bytes into the array using inline assembly code rather than using C code.

Why? By the time the compiler gets done, I seriously doubt that your assembler code will be any faster.

volatile uint32_t *addPointer = &FIFO[0];

As opposed to just pointing to FIFO?

By convention, all capital letter names are reserved for constants. Writing to a constant doesn't make sense.

Thanks for the advice, I have changed the name of the array to Fifo now.

Also, I simplified the assembly code to the following and I have been getting the following error although I believe this is the correct syntax for what I want to do:

Error: cannot represent T32_OFFSET_IMM relocation in this object file format

Assembly Code:

uint32_t Fifo[512];
volatile uint32_t *addPointer = &Fifo[0];

void setup() {
SerialUSB.begin(250000);
}

void loop() {
  __asm__ volatile( "LDR R6, [%0]\n\t" ::"r"(addPointer));
  __asm__ volatile( "MOV R8, #1\n\t");
  __asm__ volatile( "STR R8, R6\n\t");

  SerialUSB.println(Fifo[0]);
}

I understand that I won't get too much extra efficiency out of this, but I would like to at least understand why it is not working.

Solution:
See below
Changes:
place '&' in front of addPointer in inline assembly
place [] around R6 in last line of inline assembly

Working Code:

uint32_t Fifo[512];
volatile uint32_t *addPointer = &Fifo[0];

void setup() {
SerialUSB.begin(250000);
}

void loop() {
  __asm__ volatile( "LDR R6, [%0]\n\t" ::"r"(&addPointer));
  __asm__ volatile( "MOV R8, #1\n\t");
  __asm__ volatile( "STR R8, [R6]\n\t");

  SerialUSB.println(Fifo[0]);
}