here is a code i wrote to create the symtab of a sic/xe .asm file….
#include<iostream>
#include<fstream>
#include<iomanip>
#include"aviasm.h"
using namespace std;
void aviasm::crsymtab()
{
ofstream outs("symtab.txt",ios::out);//creating the symtab
ofstream outi("intermfile.txt",ios::out);//creating the intermediate file
ifstream in("asmfile.txt",ios::in);//opening the asmfile which i have already written
in.seekg(0,ios::beg);
char c;
string str[3];
string subset;
long locctr=0;
int i=0;
while((c=in.get())!=EOF)
{
in.putback(c);
while((c=in.get())!='\n')
{
in.putback(c); //putting back the first encountered letter
in>>str[i++]; //the asm file has three or less fields in every row
}
if(str[0].size()!=0 && str[1].size()!=0 && str[2].size()!=0)//if all 3 are there
{
if(str[1]=="start")
{
outi<<hex<<locctr;
outs<<str[1]<<" "<<locctr<<"\n";
outs<<resetiosflags(ios::hex);
outi<<" "<<str[0]<<" "<<str[1]<<" "<<str[2]<<"\n";
locctr=stol(str[2],0,16);
}//str[1]=start
}//end of all the three fields
}
in.close();
outi.close();
outs.close();
}//end of crsymtab
…..here is a sample sic/xe .asm file…..note that in the above code i have not included the entire coded because the problem occurs even if i comment out the entire portion of the code except the above…the problem that occurs is whenever i run the code:
-
A message box with:
'Unhandled exception at 0x00ba7046 in aviasm.exe: 0xC0000005:appears and my program enters
Access violation writing location 0xcccccccc.'
debugging mode…also a file namediosfwd(std::char_traits<char>)appears with an
arrow at the line
_Left=_Right;of the following function:static void __CLRCALL_OR_CDECL assign(_Elem& _Left, const _Elem& _Right)
{ // assign an element
_Left = _Right;
} -
Also, I output a few words to the console at the start and end of the block
str[1]="start"to check whether this function was working…although both lines were
working and I am also sure that input is being successfully taken by the program from
the asm file(I have checked this),no lines are being output to intermfile and symtab…plz help??
You should run your program inside a debugger. If you are using Windows, then MSVC provides a debug environment. If you are using Linux, compile your program with
-g, and run the gdb debugger:gdb ./myprog. You would immediately discover that on this line:ihas a value of 4, which exceeds the size of thestrarray.