This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: Gnu assembler question for ARM
- From: Nick Clifton <nickc at redhat dot com>
- To: Ciaccia <ciacciax at yahoo dot com>
- Cc: Paul Brook <paul at codesourcery dot com>, binutils at sourceware dot org
- Date: Fri, 04 May 2007 12:00:03 +0100
- Subject: Re: Gnu assembler question for ARM
- References: <833717.51801.qm@web31005.mail.mud.yahoo.com>
Hi Andrea,
Let's assume my function gets a pointer to a "C"-struct and wants to use its fields. Currently my code references the fields by hard-coding the offsets in the code, which makes the code not very readable and error prone. What is the best way to use records in assembler? I don't want to define them or allocate them in assembler, just access their fields when I receive a reference to them.
Why not let gcc do this for you by using its support for extended inline
assembler ? eg:
% cat struct.c
struct a {
int field1;
char field2;
int field3;
} A;
int main (void)
{
int result;
asm ("mov %[return_value], %[the_field_I_want]"
: [return_value] "=r" (result)
: [the_field_I_want] "r" (A.field3));
return result;
}
% gcc -S -O2 struct.c
% cat struct.s
[...]
.type main, %function
main:
ldr r3, .L3
ldr r0, [r3, #8]
mov r0, r0
bx lr
.align 2
.L3:
.word A
.comm A,12,4
[...]
ie the compiler has worked out for you that "field3" of the "struct a"
structure is at an 8 byte offset from the start of the structure.
Cheers
Nick