ASM can't reference a global variable [solved]

Can anyone please tell me what I’m missing here? I want to access a lookup table from inline code:

#include <Arduino.h>

static const int lookup[] = {1, 2, 3};

void setup() {

	asm volatile (
	  "ldi r30, lo8(lookup) \n"
	);
}

void loop() {
}

But the linker tells me:

build/apc_test.o: In function loop': apc_test.cc:12: undefined reference to lookup’
collect2: error: ld returned 1 exit status

The link command was:

/usr/bin/avr-gcc -mmcu=atmega32u4 -Wl,-Os -Wl,–gc-sections -o build/apc_test.elf build/apc_test.o build/libarduino.a -lm

Just a guess but try removing static from the declaration.

Same error without the “static”.

Prefix an underscore.

still won't link:

undefined reference to `_lookup'

BTW I'm using version 4.8.2 of avr-gcc on a gentoo system.

what about that stuff you need at the end with the :-&r : stuff ?

And, lookup is an array name, not a variable.

It’s not my code, I’m trying to implement a program that uses the FHT library.

Here’s an snippet of the original source which causes problems:

asm volatile (
“clr r15 \n” // clear the null register
“ldi r16, “STRINGIFY(FHT_N/8)” \n” // prep loop counter
“mov r14,r16 \n”
“ldi r28, lo8(fht_input) \n” //set to beginning of data space
“ldi r29, hi8(fht_input) \n”

static const int lookup[] asm("lookup") __attribute__ ((used)) = {1, 2, 3};

Use "lookup" in your assembly.

That solved it.

Thank you so much.

Excellent. You are welcome.