How do I lookup a value in a table?

0

In Go assembly on arm64, I have created a table of values

DATA table<>+0(SB)/4, 0x00000001
DATA table<>+4(SB)/4, 0x00000002
DATA table<>+8(SB)/4, 0x00000003
DATA table<>+12(SB)/4, 0x00000004

But what I want to be able to do is load up a value into a register from this table, but based on a variable.

If I had a constant I could do

MOVD table<>+4(SB), R1

so R1=0x00000002

but how can I do it with a variable? Something like...

MOVD $4, R0
MOVD table<>+R0(SB), R1

Or better yet, can I get the address and load a vector directly?

I guess the answer in normal are is ADR, but when I try that in go

ADR table<>(SB), R0

I just get

asm: illegal combination: 00280 [...] ADR table<>(SB), R9 ADDR NONE NONE REG, 3 7

Which is maybe the least useful error message I've ever seen.

Okay, so ADR works if I do PC relative addressing, but that's obviously not right.

go
assembly
arm
arm64
asked on Stack Overflow Jan 22, 2021 by AnthonyM • edited Jan 22, 2021 by Flimzy

1 Answer

1

Turns out it's really easy, you just put a $ before the variable

MOVD $table<>+0(SB), R0
answered on Stack Overflow Jan 22, 2021 by AnthonyM

User contributions licensed under CC BY-SA 3.0