:)
my project consists of me making my own two pass assembler for my systems programming class. i have finished pass 1, my code complies and everything, but, when i try to make it read an input file, it states that it is never found. i dont know what to do to make it work. any help would be appreciated. here is the part of the code that should "read my input file" and print out an "intermediate" file with the corresponding information.
if my exlanation of my problem is unclear, please let me know.
thanks.
infile.open(file);
outfile.open("intermediatefile.txt");
if (infile.is_open())
{
test = infile.peek();
if (test == '.') //check if line starts with a comment
{
infile.ignore(255,'\n');
}
else
{
getline(infile,line); //get line form intermediate file
stringstream ss(line);
if (isspace(test))
{
i = 1;
}
for (int k=0; k < 3; k++)
{
arg[k] = " ";
}
while ( ss >> buf && i < 3 )
{
arg[i] = buf;
i++;
}
}
if( arg[1] == "START") //check if the 2nd word in the intermediate file is START
{
istringstream iStream(arg[2]);
iStream >> hex >> STL; //convert to hex
LCTR= STL; //set LCTR to the hex value of START
outfile<<"\t"<<arg[0]<<"\t"<<arg[1]<<"\t"<<arg[2]<<"\t"; //outfile to intermediate file
outfile<<hex<<LCTR<<endl; //outfile hex value
}
else
{
STL = 0;
LCTR = 0;
outfile << "\t\t: Missing START directive."<< endl;
}
for (int c=0; c < 3; c++)
{
arg[c] = " ";
}
//-------------------READ-FROM-FILE------------------------------
while (arg[1] != "END")
{
i = 0;
test = ' ';
test = infile.peek();
if (test == '.')
{
infile.ignore(255,'\n');
}
else
{
getline(infile,line);
stringstream ss(line);
if (isspace(test))
i = 1;
for (int l=0; l < 3; l++)
{
arg[l] = " ";
}
while ( ss >> buf && i < 3 )
{
arg[i] = buf;
i++;
}
if(arg[1] == "RSUB")
arg[2] = " ";
//------------PRINT-TO-OUTPUT-FILE------------------------------------------------
outfile << arg[0] << "\t";
if(arg[1] == "END")
outfile << arg[1] << "\t";
else
outfile << arg[1] << "\t";
if (arg[2].length() > 7 )
outfile << arg[2]<< "\t";
else
outfile << arg[2] << "\t\t";
//------------------SEARCH-ASSIGN-AND-OUTPUT---------------------------------
if (arg[0] != " ")
{
searchSym(arg[0]); //search for the symbol in symbol table
}
if (!searchOp (arg[1],arg[2]))
{
if (!searchDir (arg[1],arg[2]))
{
cout << "Invalid Instruction" << endl;
}
}
outfile << hex << op[LOC].code << endl; //outfile opcode
}
}
compSym(arg[2]); // varifies END operand
outfile << LCTR - STL << " bytes reserved." << endl; // Prints program length
infile.close();
outfile.close();
}
else
{
cout<<"File does not exist."<<endl;
}
printSymTable();
clearSymTable(); // clears symbol table;
}