The assembly code was adjusted in the VC environment.
Programming environment: VC6 and Masm 6.11
The main program is as follows:
// masm_c.cpp: defines the entry point for the console application.
//
#include
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 simple plus a sub-function, the function is implemented with assembly
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 incoming parameter A
INC EAX; add EAX, as return value
POP EBP
RET
_ADD ENDP
_Text Ends
end
This segment assembly language is compiled with ML but does not connect
D: / masm611 / bin> ml / c / coff add.asm
Microsoft (R) Macro Assembler Version 6.11
Copyright (c) Microsoft Corp 1981-1993. All Rights Reserved.
Ask.ASM
Generate Add.obj.
Next, CPP is dependent on LINK with ASM. Add add.obj to the MASM_C directory, then Project ----- setting ------ link, add add.obj in Link's Project Options to separate the other lib spacers. After passing.
The result is:
Before add (a) a = 1
After Add (a) a = 2
Press any key to continche