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

2022-07-09 10:36:50

源代码及注释:

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

extern"C" intAddplus(int, int);//告诉C程序int Addplus(int, int)为一段C语言代码 (值传递)voidmain(){
	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(使用平坦内存模式);.stack1024;申请一段堆栈空间.codepublic 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

程序运行结果:

在这里插入图片描述

  • 作者:DongMaoup
  • 原文链接:https://blog.csdn.net/DongMaoup/article/details/120989173
    更新时间:2022-07-09 10:36:50