In assembly languages, it is sometimes convenient to call library functions in C language.
First, give a sample program:
. 386
. Model flat, stdcall
Option Casemap: None
; Include definition
Include stdio. inc
Includelib msvcrt. Lib
. Data
Szmsg DB "calls the puts function of C in the assembler! ", 0
. Code
Start:
Invoke puts, offset szmsg
RET
End start
Is it a bit like the hello, World Program in C.
How does stdio. inc come from?
Stdio. Inc is the declaration of the Standard Input and Output C function.
The masm32 package does not exist, and Microsoft does not provide it. This is obtained from stdio. H conversion in VC.
How to convert?
Microsoft provides h2inc, a tool for converting. H files to. inc files, which can be found in the VC directory.
Conversion command:
H2inc/Win32 *. h
An error occurs when stdio. H is directly converted. Make some modifications.
1) add a sentence at the beginning:
# DEFINE _ Win32
2) Comment out # pragma pack (push, 8) and // # pragma pack (POP) in the file
After the conversion is successful, you only need to add
Include stdio. inc
Includelib msvcrt. Lib
You can call the input and output functions in C language.
We recommend that you set the directory where msvcrt. Lib is located to the Lib environment variable, and set the directory where stdio. Inc is located to the include environment variable.
Msvcrt. Lib is the library file of msvcrt. dll or msvcr71.dll (vc7.1 ).
Note the following when using the h2inc conversion header file:
1) The/Win32 parameter must be added, otherwise the conversion will be performed based on the default 16-bit
2) the last line of the H file must have a carriage return.
3) The function type declaration is first converted to the form of @ proto_n, and then declared. If several close files are converted, the several files start from @ proto_0, if you include these files at the same time, the compiler will prompt: symbol type conflict (symbol type conflict ).
Solution:
After conversion, use the all replacement function of the text editor to replace "PROTO _" in different files with different strings.
4) structure and union are also the same as 3.
5) If _ cdecl is not added to the function name in the H file, it will be converted to the default stdcall type.
6) h2inc will not convert programs in the H file, and many c syntaxes are not supported.