#include #include #include #include #include #include "Org_MIPS.h" using namespace std; int main() { string registers[ MAXREG ]; string memory[ MAXMEM ]; string binInstruction, hexInstruction, opCode, inFileName; ifstream inFile; ofstream outFile; int PC = 0; for ( int i = 0; i < MAXMEM; i++ ) memory[ i ] = "00000000"; for ( int i = 0; i < MAXREG; i++ ) registers[ i ] = "00000000000000000000000000000000"; cout << "Please enter the name of the file that contains the Hexadecimal Instructions:" << endl; cin >> inFileName; cout << endl; inFile.open( inFileName.c_str() ); outFile.open( "Output.txt" ); while ( !inFile.eof() ) { cout << "We are executiing!!!" << endl << endl; inFile >> hexInstruction; cout << "Hex: " << hexInstruction << endl; outFile << "PC: " << PC << endl; PC++; binInstruction = HexToBin( hexInstruction ); cout << binInstruction << endl << endl; opCode = binInstruction.substr( 0,6 ); if ( opCode == "000000" ) RtypeInstruct( PC, opCode, binInstruction, registers, memory, outFile ); else if ( opCode == "000010" ) JtypeInstruct( PC, opCode, binInstruction, registers, memory, outFile ); else ItypeInstruct( PC, opCode, binInstruction, registers, memory, outFile ); outFile << "MEMORY" << endl; for ( int i = 0; i < MAXMEM; i++ ) { if ( i <= 9 ) { outFile << left << i << ". " << setfill( ' ' ) << setw( 32 ) << memory[ i ] << " DecVal: " << BinToDec( memory[ i ] ) << endl; } else if ( i >= 10 && i <= 99 ) { outFile << left << i << ". " << setfill( ' ' ) << setw( 32 ) << memory[ i ] << " DecVal: " << BinToDec( memory[ i ] ) << endl; } else { outFile << left << i << ". " << setfill( ' ' ) << setw( 32 ) << memory[ i ] << " DecVal: " << BinToDec( memory[ i ] ) << endl; } } outFile << endl << "REGISTERS" << endl; for ( int i = 0; i < MAXREG; i++ ) { if ( i <= 9 ) { outFile << left << i << ". " << setfill( ' ' ) << setw( 32 ) << registers[ i ] << " DecVal: " << BinToDec( registers[ i ] ) << endl; } else { outFile << left << i << ". " << setfill( ' ' ) << setw( 32 ) << registers[ i ] << " DecVal: " << BinToDec( registers[ i ] ) << endl; } } outFile << endl << "*********************************" << endl; cout << endl; system( "pause" ); cout << endl << endl; } inFile.close(); outFile.close(); return 0; }