Use pointer parameters and dereference the argument. The following example increments the x, y, and z values in a POINTS structure.
main.c
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
int x, y, z;
} POINTS;
void IncrementPoints( POINTS * ptrPoints ) __attribute__((stdcall));
int main ( void )
{
POINTS * here;
here = (POINTS *) malloc( sizeof( POINTS ) );
here->x = 1;
here->y = 2;
here->z = 3;
fprintf( stdout, "x: %ld\ny: %ld\nz: %ld\n",
here->x, here->y, here->z );
IncrementPoints( here );
fprintf( stdout, "x: %ld\ny: %ld\nz: %ld\n",
here->x, here->y, here->z );
free( here );
return( 0 );
}
incpts.asm
BITS 32
STRUC POINTS
.x RESD 1
.y RESD 1
.z RESD 1
ENDSTRUC
SECTION .text
Global IncrementPoints
IncrementPoints:
STRUC IP_ARGS
.ptrPoints RESD 1
ENDSTRUC
Push Ebp
Mov Ebp, Esp
Push Esi
Mov Esi, [Ebp + 8 + IP_ARGS.ptrPoints]
Inc DWORD [Esi + POINTS.x]
Inc DWORD [Esi + POINTS.y]
Inc DWORD [Esi + POINTS.z]
Xor Eax, Eax
Pop Esi
Leave
Ret
Build and Run with:
nasm -f elf incpts.asm -o incpts.o
gcc -o test main.c incpts.o
./test
A few things to note are; a) I use stdcall convention whenever I write assembly, so you'll notice the __attribute__ declaration to ensure that it uses stdcall, if you use a different convention then you will need to change that. b) I decided to allocate the 'here' structure on the heap, if you want to use a local stack based variable (ie POINTS here) just call the procedure using 'IncrementPoints( &heap);' instead and all should work fine.
Regards,
Bryant Keller