源代码及注释:
#include <iostream>
using namespace std;
extern "C" int Addplus(int, int);
void main() {
int a, b, c;
cout << "请输入加法数a和b的值:";
cin >> a >> b;
c = Addplus(a, b);
cout << "C语言模块加法结果为:" << a + b << endl;
cout <<"汇编模块加法结果为:"<< c << endl;
}
;汇编模块 汇编模块 汇编模块 汇编模块 汇编模块
.686
.model flat,c;包含一个语言说明符和一个栈距离。 falt(使用平坦内存模式)
;.stack 1024 ;申请一段堆栈空间
.code
public Addplus
Addplus proc uses esi, variables1:dword ,variables2:dword ;入口参数,采用了值传递的方式
mov eax,0
mov esi,variables1 ;把variables1的值给源变址寄存器esi
mov eax,esi; eax = eax + esi
mov esi,variables2 ;把variables2的值给源变址寄存器esi
add eax,esi; eax = eax + esi
ret;ret(从过程返回)指令将处理器转回到该过程被调用的程序点上。
Addplus endp
end
程序运行结果: