This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: Gnu assembler question for ARM
- From: Ciaccia <ciacciax at yahoo dot com>
- To: Nick Clifton <nickc at redhat dot com>
- Cc: Paul Brook <paul at codesourcery dot com>, binutils at sourceware dot org
- Date: Fri, 4 May 2007 04:33:19 -0700 (PDT)
- Subject: Re: Gnu assembler question for ARM
> > 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;
>
> [...]
> 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.
Hi Nick,
I think my question was not clear. My problem is not "how to find" the offsets, but rather "configure them once" so that I don't have to write the offsets in assembler. For example, let assume my function receives a pointer to a A struct as parameter and I want to write some data to it. The following C function
----------------------------------------
void fill(struct a *ptr)
{
a->field1= 1;
a->field2= (char)2;
a->field3= 3;
}
----------------------------------------
could be rewritten in (arm) ASM as following:
----------------------------------------
fill:
mov r1, #1
str r1, [r0, #0] @ store 1 in field1
mov r1, #2
strb r1, [r0, #4] @ store 2 in field2
mov r1, #3
str r1, [r0, #8] @ store 3 in field3
mov pc, lr
----------------------------------------
What I don't like are the #0, #4 and #8 in the store instruction. I would like to have something like this:
----------------------------------------
@this is pseudocode, it's not expected to work
#define field1 0
#define field2 (field1 + 4)
#define field3 (field2 + 4)
fill:
mov r1, #1
str r1, [r0, #field1] @ store 1 in field1
mov r1, #2
strb r1, [r0, #field2] @ store 2 in field2
mov r1, #3
str r1, [r0, #field3] @ store 3 in field3
mov pc, lr
----------------------------------------
How could I get that?
Thanks again
Andrea
____________________________________________________________________________________
Be a PS3 game guru.
Get your game face on with the latest PS3 news and previews at Yahoo! Games.
http://videogames.yahoo.com/platform?platform=120121