A Simple Method for Calling C functions in assembly language

Source: Internet
Author: User

A Simple Method for Calling C functions in assembly language

First, I chose the compiler: VC ++ and MASM for this experiment.
Create a c file and write down the following content.
Int CADD (int A, int B)
{
Return A + B;
}
Use VC ++ to compile it into an OBJ file.
Then create an ASMProgram, Add the obtained OBJ file, and write down the following content.

. 386
. Model flat, stdcall
Option Casemap: None

Include windows. inc
Include user32.inc
Includelib user32.lib
Include kernel32.inc
Includelib kernel32.lib

CADD proto C: DWORD,: DWORD; declare external function CADD

. Code
Start:
Invoke CADD, 1, 2
Invoke exitprocess, null
End start

Compile and run the program successfully.
You can also use this method to call functions in other languages.

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.