汇编和C语言混合编译程序:加法函数的实现

源代码及注释:

//C语言模块 C语言模块 C语言模块 C语言模块 C语言模块 
#include <iostream>
using namespace std;

extern "C" int Addplus(int, int); //告诉C程序int Addplus(int, int)为一段C语言代码 (值传递)
void main() {
	int a, b, c;
	cout << "请输入加法数a和b的值:";
	cin >> a >> b;
	c = Addplus(a, b); //汇编模块返回c = eax
	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 
	

程序运行结果:

在这里插入图片描述

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值