This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

give C struct to assembler...

Note: This was originally posted on 24th November 2011 at http://forums.arm.com

how can I send the offset of a C struct to en assembly code ? For example

In my C code I have

typedef struct
{
  unsigned int a;
  unsigned int b;
} CMyStruct;
I send to an ASM function a pointer of a CMyStruct structure Let suppose that my pointer is into R0

To access to a and b attribute I need to do that.

ldr      r1, [r0, #0] // read a
ldr      r2, [r0, #4] // read b
Is there anyway to not specify #0 and #4 as contant value ? Something like

ldr      r1, [r0, CMyStruct.a] // read a
ldr      r2, [r0, CMyStruct.b] // read b
Thank's Etienne
Parents
  • Note: This was originally posted on 26th November 2011 at http://forums.arm.com


    I'm not sure you can in GCC assembler - I've never seen it attempted directly.

    The obvious workaround is calculate the necessary offsets in C and pass then in to the assembler function as parameters.


    Hum. that's not very efficient because you'll use register for offset instead of constant value. You could then have assembly code slower than C code. glups ;(

    My problem is to be sure that If I change my struct my asm function will be updated too.
    Since I do not find a correct solution, I've add a asm function for every C struct that check that struct size have not changed.
    That's not very good, but that's better that nothing ;)

    I will update this process by making a king of checksum instead of passing struct size.

    Etienne
Reply
  • Note: This was originally posted on 26th November 2011 at http://forums.arm.com


    I'm not sure you can in GCC assembler - I've never seen it attempted directly.

    The obvious workaround is calculate the necessary offsets in C and pass then in to the assembler function as parameters.


    Hum. that's not very efficient because you'll use register for offset instead of constant value. You could then have assembly code slower than C code. glups ;(

    My problem is to be sure that If I change my struct my asm function will be updated too.
    Since I do not find a correct solution, I've add a asm function for every C struct that check that struct size have not changed.
    That's not very good, but that's better that nothing ;)

    I will update this process by making a king of checksum instead of passing struct size.

    Etienne
Children
No data