Article ID: 104618
Article Last Modified on 4/24/2006
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, * EAXThe samples below include one C file and two different assembly files. The two assembly files demonstrate how to pass a variable in small model for MS-DOS and in flat model for Windows NT. Link only the appropriate assembly module to the C module.
// Filename: CMAIN.C
// Compile options needed: /c
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
char MasmSub (char);
#ifdef __cplusplus
}
#endif
main ()
{
char var = 'a';
printf ("%c\n", var);
printf ("%c", MasmSub(var));
}
; Filename: MASMSUB.ASM ; Assemble options needed for MASM: /MX ; Assemble options needed for ML: /c /Cx .MODEL small, C .286 .CODE MasmSub PROC, \ cVar:BYTE mov al, cVar ; Load the char into AL. add al, 25 ; Because the function returns a char (a 1-byte ret ; value), C will get the return value from AL. MasmSub ENDP END
; Filename: MASMSUB.ASM ; Assemble options needed for ML: /c /Cx /coff .386 .MODEL flat, C .CODE MasmSub PROC, \ cVar:BYTE mov al, cVar ; Load the char into AL. add al, 25 ; Because the function returns a char (a 1-byte ret ; value), C will get the return value from AL. MasmSub ENDP ENDThe following is the output of the program:
a z
Keywords: kbhowtomaster kblangc kbcode KB104618