Microsoft KB Archive/61590

= Passing a long* from a C Module to an Assembly Module =

Article ID: 61590

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 Q61590



SUMMARY
The following code demonstrates passing a LONG INT (4 bytes) via a far pointer (4 bytes) to an assembly routine that accesses the LONG integer.

Each integer is incremented in the assembly routine and its new value returned to the calling C program.



Sample Code
/* Compile options needed: /AL


 * 1) include 
 * 2) include 
 * 3) include 

extern void IncLongs( long *, long * );

void main {  long *n1,*n2;               /* 4 byte pointers  */

long int t1 = 9999999L;    /* 4 byte variables */ long int t2 = 2256789L;

n1 = &t1; n2 = &t2;

/* initial values */ printf( &quot;The values are %ld and  %ld\n &quot;, *n1, *n2 );

printf( &quot;Incrementing values...\n&quot; ); IncLongs( n1, n2 );

/* values returned by the assembly routine */ printf( &quot;The values are %ld and  %ld\n &quot;, *n1, *n2 ); }

=
===========================================


 * Assemble options needed: none

.model large, c        .data .code IncLongs PROC far arg1:dword, arg2:dword PUSH es                ; save registers PUSH si        LES si,arg1             ; load in es:si the seg:offset of n1         INC word ptr es:[si] JNC doarg2 INC word ptr es:[si+2] ; if carry, increment high word of n1

doarg2: LES si,arg2            ; load in es:si the seg:offset of n2         INC word ptr es:[si] JNC finis INC word ptr es:[si+2] ; if carry, increment high word of n2

finis: POP si                 ; restore registers POP es        MOV sp,bp RET IncLongs ENDP

END

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

Keywords: KB61590

-

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

© Microsoft Corporation. All rights reserved.