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

Last reviewed: January 6, 1995
Article ID: Q61590
The information in this article applies to:
  • Microsoft Macro Assembler for MS-DOS, versions 5.1, 5.1a, 6.0, 6.0a, and 6.0b

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.

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
         .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 reference words: 5.10 5.10a 6.00 6.00a 6.00b
KBCategory: kbprg
KBSubCategory: MASMLngIss


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: January 6, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.