Call the C language library function in the assembler, and convert h to Inc.

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.