⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 i_c.cpp

📁 本程序可以对反汇编得到的指令文件进行指令统计
💻 CPP
字号:
#include "iostream.h"
#include "fstream.h"
#include "stdlib.h"
#include "string.h"
#include "i_c.h"

//将指向命令字的字符指针t与链表h_node的各节点的ch值逐一比较,
//找到相同的则将其count值增1,否则向链表中增加新结点
void L_node(char *t,Node *h_node)
{    
	Node *tp;	
	tp=h_node;//tp用于指示链表的当前节点
	while (tp)//当当前节点的下一节点非空时,执行循环
	{
		if (!strcmp((tp->pop_ch()),t))//找到,将其count值增1
		{
			tp->inc_count();
			return;
		}
		else
		//没找到且当前结点不是最后一个结点(最后一个结点作特殊处理,见下),向链表中增加新结点
		{
			if (!(tp->pop_next())) break;
			tp=(tp->pop_next());
		}
	}
    //在最后一个结点找到与t相同的命令字,将该节点的count值增1
	if (!(strcmp((tp->pop_ch()),t))) tp->inc_count();	
	else //未找到,则增加新节点node
	{
		Node *node;
		node=new Node;
		node->set_ch(t);//使t值成为新节点的ch值
		tp->set_next(node);//将新节点插入链表中
	}
}

void main()
{
	Node *h_node,*temp;
	int i;
	float p=0.0;
	char b[200],*t,*filename;//b用于存放指令文件的每一行,t用于存放指令字
	t=new char[4];
	h_node=new Node;
	filename=new char[10];
	cout<<"Input the filename:";
	cin>>filename;//文件filename存储反汇编的指令文件
	ifstream inf(filename);
	if (!inf)//未找到指定文件的处理
	{
		cout<<"Error open file!\n";
		return;
	}
	cout<<"\n反汇编情况如下:\n";
	while (inf.getline(b,200))
	{	
		if (b[0]=='-'||b[26]==':') continue;
		//当遇到非指令字时跳转,如debug开始时的-u和结尾时的-q,以及表示各段的cs:等
        i=0;
		while (b[24+i]>='A' && b[24+i]<='Z') //指令字从每行的24个字符处开始,故从b[24]开始赋值
		{
			t[i]=b[i+24];
			i++;
		}
		t[i]='\0';
		if(!strcmp(t,"DB")) continue;//忽略文件中的DB指令
		cout<<b<<endl;
    	L_node(t,h_node);//函数说明见上
		p++;
    }
	cout<<"\n该文件共有"<<p<<"行指令,";
	inf.close();//关闭文件
	temp=(h_node->pop_next());
	cout<<"各指令字及其使用率如下:\n\n"<<"指令字\t出现次数\t使用率\n";
	while (temp)//当temp非空时,输出有关值
	{
		cout<<(temp->pop_ch())<<"\t   "<<(temp->prt_count())<<"\t\t"<<(temp->prt_count())/p*100<<"%"<<endl;
		temp=(temp->pop_next());
	}
	delete h_node;
	delete []filename;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -