forked from Leidenschaft/Computer-Organization
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetline.cpp
More file actions
34 lines (34 loc) · 958 Bytes
/
Copy pathgetline.cpp
File metadata and controls
34 lines (34 loc) · 958 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include "Term.h"
#include <string>
#include <fstream>
using namespace std;
int main(int argc,char *argv[]){
if (argc<2){
cout<<"Please run as: mips.exe filename.in (filename.out)"<<endl;
return 0;
}
ifstream in;
ofstream out;
in.open(argv[1]);
if (argc>2){
out.open(argv[2]);}
else{out.open("code.txt");}
string s;
int line=0;
while (getline(in,s)){
char* p = (char*)s.c_str();
unsigned short mycode=MyAsm(p);
if (mycode<0) {cout<<"Error: Wrong Instruction in line "<<line<<". Program halt."<<endl; return 0;}
//sendOneWord(com,mycode);
if (mycode<4096) out<<"0";
if (mycode<256) out<<"0";
if (mycode<16) out<<"0";
out<<hex<<mycode;
line++;
}
in.close();
out.close();
// system("pause");
return 0;
}