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

📄 mips.cpp

📁 mini mips 小型mips软件
💻 CPP
字号:
// mips.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
#include <sstream>
#include <string>
#include <iomanip>
#include "Manager.h"
#include "AsmManager.h"
#include "BinaryManager.h"
using namespace std;

Manager *manager = NULL;

string helptext[]={
	"openasm+汇编代码文件名:读入一个文件里面写了汇编代码。",
	"openbinary+二进制代码文件名:读入一个文件里面写了机器码。",
	"showstatus:显示所有的寄存器(包括通用寄存器,浮点寄存器,PC,EPC等)的值。",
	"showtext:显示打开文件的代码(包括地址,汇编代码,机器码)",
	"execute:运行代码",
	"step+步数(不写默认为1):分步操作",
	"exit:退出程序"
};

string ToLower(string s){
	string ret;
	for (unsigned i = 0; i < s.length(); ++i) ret += tolower(s[i]);
	return ret;
}

void PrintVStr(vector<string>& s){
	for (int i = 0; i < s.size(); ++i) cout << s[i] << endl;
}

void split(string &s, vector<string>& coms){
	istringstream is(s);
	coms.clear();
	string t;
	while (is >> t){
		coms.push_back(t);
	}
	if (!t.empty()) coms[0] = ToLower(coms[0]);
}

void help(vector<string> &coms){
	for (int i = 0; i < 7; ++i) cout << helptext[i] << endl;
}

void openasm(vector<string> &coms){
	if (manager != NULL){
		delete manager;
		manager = NULL;
	}
	cout << "Loading..." << endl;
	manager = new AsmManager(coms[1].c_str());
	cout << "Translate..." << endl;
	manager->Translate();
	manager->SaveCode();
}

void showtext(vector<string> &coms){
	if (manager == NULL){
		cout << "No file opened!\n" <<endl;
		return;
	}
	vector<string> s;
	manager->GetTextCodes(s);
	PrintVStr(s);
}

void showstatus(vector<string> &coms){
	if (manager == NULL){
		cout << "No file opened!\n" <<endl;
		return;
	}
	vector<string> s;
	manager->ShowStatus(s);
	PrintVStr(s);
}

void openbinary(vector<string> &coms){
	if (manager != NULL){
		delete manager;
		manager = NULL;
	}
	cout << "Loading..." << endl;
	manager = new BinaryManager(coms[1].c_str());
	cout << "Translate..." << endl;
	manager->Translate();
	manager->SaveCode();
}

void step(vector<string> &coms){
	int step = 1;
	if (coms.size() > 1){
		istringstream is(coms[1]);
		is >> step;
	}
	manager->StepRun(step);
}

int main(int argc, _TCHAR* argv[])
{
	string com;
	vector<string> coms;
	while (true){
		cout << endl << "Mini MIPS>";
		getline(cin, com);
		split(com, coms);
		if (coms.empty()) continue;
		if (coms[0] == "help")		{ help(coms); continue;}
		if (coms[0] == "openasm")	{ openasm(coms); continue;}
		if (coms[0] == "execute")	{ manager->Execute();continue;}
		if (coms[0] == "showtext")	{ showtext(coms); continue;}
		if (coms[0] == "showstatus"){ showstatus(coms); continue;}
		if (coms[0] == "openbinary"){ openbinary(coms); continue;}
		if (coms[0] == "step")		{ step(coms); continue;}
		if (coms[0] == "exit") break;
	}
	return 0;
}

⌨️ 快捷键说明

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