Reputation: 97
I have trouble with some inline assembly code. I'm trying to load items from local static array into registers on ARM platform. Unfortunately I have no idea how to tell GCC that it should pass pointer on array to register. This register will be used for indirect acess to array.
// should return argv[1]
int test() {
int argv[4] = {4, 3, 2, 1};
int out;
__asm__ volatile (
"ldr r0, %[ARGV]" "\n\t"
"mov r1, #4" "\n\t"
"ldr r2, [r0, r1]" "\n\t"
"mov %[OUT], r2"
: [OUT] "=r" (out)
: [ARGV] "m" (argv) // <==== i don't know which constraint put here :/
: "r0", "r1", "r2"
);
return out;
}
Now the GCC throw error and I have no idea how to fix it:
Assembler messages:
Error: invalid offset, value too big (0xFFFFFFFC)
Thx
EDIT: I have compiled it with Android NDK (arm-linux-androideabi-g++)
Upvotes: 1
Views: 3549
Reputation: 2776
You don't need to move ARGV or OUT to/from registers, that is what the register constraints handle for you.
"mov r1, #4\n\t"
"ldr %[OUT], [%[ARGV], r1]\n\t"
: [OUT] "=r" (out)
: [ARGV] "r" (argv)
: "r1"
note: this code does have problems when compiled with too high optimization settings. ( i don't know how to solve that, except: use -O0 )
Upvotes: 2
Reputation: 25569
I think it should work like this:
[ARGV] "r" (argv)
That says "load the address of the array into a register".
Upvotes: 1