Article ID: 104645
Article Last Modified on 7/5/2005
char AL
short, int, near * AX
long, far * DX: High order portion (segment)
AX: Low order portion (offset)
For 32-bit code, such as a Windows NT program, use the following
conventions for returning data to a C program:
char AL short AX long, int, * EAX
// Filename: CMAIN.C
// Compile options needed: /c
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
long MasmSub (long, long);
#ifdef __cplusplus
}
#endif
main ()
{
long var1 = 98304, var2 = 147456;
printf ("%ld + %ld = %ld", var1, var2, MasmSub (var1, var2));
}
; Filename: MASMSUB.ASM ; Assemble options needed for MASM: /MX ; Assemble options needed for ML: /c /Cx .MODEL small, C .286 .CODE MasmSub PROC, \ lVar1:DWORD, \ lVar2:DWORD mov ax, WORD PTR lVar1 ; Load the first long into DX:AX. mov dx, WORD PTR lVar1+2 add ax, WORD PTR lVar2 ; Add the second long to DX:AX adc dx, WORD PTR lVar2+2 ret ; Because the function returns a long (a 4-byte MasmSub ENDP ; value), C will get the return value from DX:AX. END
; Filename: MASMSUB.ASM ; Assemble options needed for ML: /c /Cx /coff .386 .MODEL flat, C .CODE MasmSub PROC, \ lVar1:DWORD, \ lVar2:DWORD mov eax, lVar1 ; Load the first long into EAX. add eax, lVar2 ; Add the second long to EAX. ret ; Because the function returns a long (a 4-byte MasmSub ENDP ; value), C will get the return value from EAX. ENDThe following is the output of the program:
98304 + 147456 = 245760
Additional query words: mixed language
Keywords: kbinfo kblangc KB104645