Microsoft KB Archive/62626

= Passing a Pointer to a Structure from C to Assembly =

Article ID: 62626

Article Last Modified on 10/17/2003

-

APPLIES TO


 * Microsoft Macro Assembler 5.1 Standard Edition
 * Microsoft Macro Assembler 5.1a
 * Microsoft Macro Assembler 6.0 Standard Edition
 * Microsoft Macro Assembler 6.0a
 * Microsoft Macro Assembler 6.0b

-



This article was previously published under Q62626



SUMMARY
The code sample below illustrates how to pass a structure from a C module to an assembly module. This code makes it possible to access the structure fields within the assembly module using the &quot;.&quot; field operator.

Within the assembly module a structure is declared. This structure is used as a template by the assembler to resolve accessing the fields of the structure. The structure may be given any label name.



MORE INFORMATION
The following is an example. Note that the syntax for accessing structure members will be different with MASM 6.0 and later.

Sample Code:
/* Compile options needed: none


 * 1) include 

struct node {  int IntVar; char Array[5]; };

struct node var; extern void IncStruc( struct node * );

void main {  var.Array[0] = 'H'; var.Array[2] = 'I'; var.IntVar = 0x0b12; IncStruc( &var );

/* Incremented values on returning to C */

printf( &quot;var.IntVar is now %x\n&quot;, var.IntVar ); printf( &quot;var.Array[0] is now %c\n&quot;, var.Array[0] ); printf( &quot;var.Array[2] is now %c\n&quot;, var.Array[2] ); }

--


 * Assemble options needed: none


 * OPTION OLDSTRUCTS     ; for MASM 5.1 behavior from MASM 6.0

.model small, c

delta STRUC IntVar DW ? Array DB 5 dup (?) delta ENDS

.code

IncStruc PROC PUSH  BP         MOV    BP, SP

MOV   bx, [bp+4] INC   [bx].IntVar INC   [bx].Array INC   [bx+2].Array

POP   bp         RET IncStruc ENDP

END The output is as follows:   var.IntVar is now b13 var.Array[0] is now I  var.Array[2] is now J

Additional query words: kbinf 5.10 5.10a 6.00 6.00a 6.00b

Keywords: KB62626

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.