In the VC environment, the assembly code is called.
Programming Environment: VC6 and MASM 6.11
The main program is as follows:
Masm_C.cpp:Defines the entry point for the console application.
//
<?xml:namespace prefix = o ns = "Urn:schemas-microsoft-com:office:office"/>
#include <stdio.h>
extern "C" int _cdecl Add (int a);
void Main ()
{
int a = 1;
printf ("Before add (a) a =%d/n", a);
A = Add (a); Add implements a simple addition to a sub-function, which is implemented using a compilation
printf ("After add (a) a =%d/n", a);
Return
}
Its assembly code is:
; Add.asm
.386
Public _add
_text segment byte Public ' code '
Assume Cs:_text
_add proc Near
Push EBP
MOV Ebp,esp
mov eax,[ebp+8]; here ebp+8 is the value of the passed parameter a
inc EAX; add eax as a return value
Pop EBP
Ret
_add ENDP
_text Ends
End
This section of assembly language is compiled with ML but not connected
D:/MASM611/BIN>ML/C/coff Add.asm
Microsoft (R) Macro assembler Version 6.11
Copyright (C) Microsoft Corp 1981-1993. All rights reserved.
Assembling:add.asm
Generate Add.obj.
The next step is to link CPP and ASM together. Copy the add.obj to the Masm_c directory, and project-----setting------link to add add.obj to the project options in link, separated from the other lib spaces. Passed after compilation.
The result is:
Before add (a) a = 1
After add (a) a = 2
Press any key to continue