?? 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 + -