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: Dave Korn <dave dot korn at artimi dot com>, binutils at sourceware dot org
- Date: Tue, 08 May 2007 16:09:22 +0100
- Subject: Re: Gnu assembler question for ARM
- References: <908496.48903.qm@web31012.mail.mud.yahoo.com>
Hi Andrea,
Apart from that, I find strange that there is almost no documentation nor examples online.
Definitely. The problem is that writing documentation is often the last
task completed in a project, especially ones that are undergoing
continuous development.
> I wonder if this feature should not be explained better...
Maybe you would like to extend the documentation ? We are always will
to accept contributions that add to the manuals and tutorials.
I still have some unresolved questions (for example, how to nicely nest structs, how to sizeof), and an example would really help me. For example, what would be the best (cleaner) way to use vector struct defined as following?
The guys have already told you about the .struct directive and you have
come across the problem of structure padding, so for the record let me
return to my suggestion of using gcc and combined C+assembler to resolve
this problem. For example with your nested structures example you could
use this code to initialise the fields in a vector whose address is
provided to a function foo:
-------------------------------------------------------------------------
struct point
{
int x;
int y;
int z;
};
struct vector
{
struct point v0;
struct point v1;
};
#define offset_of_v0_x_in_struct_vector __builtin_offsetof (struct
vector, v0.x)
#define offset_of_v1_y_in_struct_vector __builtin_offsetof (struct
vector, v1.y)
void
foo (struct vector * ptr)
{
asm ("\
mov r1, #1\n\t\
str r1, [%[ptr], %[v0_x_offset]]\n\t\
mov r1, #2\n\t\
str r1, [%[ptr], %[v1_y_offset]]"
:
: [ptr] "r" (ptr),
[v0_x_offset] "i" (offset_of_v0_x_in_struct_vector),
[v1_y_offset] "i" (offset_of_v1_y_in_struct_vector),
"m" (ptr)
: "r1");
}
-------------------------------------------------------------------------
(I am only initialising two fields of the vector structure in the above
example, v0.x and v1.y, but I am sure that you get the idea).
Of course this example is silly, it would be much easier to just code
the initialization in C. But, it demonstrates how you can use gcc to
compute compile time constants for the offsets of various fields inside
(nested) structures and then use them inside assembler statements. A
real assembler program would have a much bigger asm("...") section.
Cheers
Nick