Passing a long* from a C Module to an Assembly Module (61590)



The information in this article applies to:

  • Microsoft Macro Assembler (MASM) 5.1
  • Microsoft Macro Assembler (MASM) 5.1a
  • Microsoft Macro Assembler (MASM) 6.0
  • Microsoft Macro Assembler (MASM) 6.0a
  • Microsoft Macro Assembler (MASM) 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.

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
				

Modification Type:MajorLast Reviewed:10/17/2003
Keywords:KB61590