Passing a long* from a C Module to an Assembly ModuleLast reviewed: January 6, 1995Article ID: Q61590 |
The information in this article applies to:
SUMMARYThe 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.
MORE INFORMATION
Sample Code
/* Compile options needed: /AL */ #include <stdio.h> #include <process.h> #include <conio.h>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( "The values are %ld and %ld\n ", *n1, *n2 ); printf( "Incrementing values...\n" ); IncLongs( n1, n2 ); /* values returned by the assembly routine */ printf( "The values are %ld and %ld\n ", *n1, *n2 );}
; Assemble options needed: none
.model large, c .data .codeIncLongs 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 n1doarg2: 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 n2finis: POP si ; restore registers POP es MOV sp,bp RETIncLongs ENDP
END |
Additional reference words: 5.10 5.10a 6.00 6.00a 6.00b
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |