Hi,
I am writing a C program using VS2008 for easy debugging, but unfortunately I am running into access violation writing exception. When I executed step by step, I found that fscanf works for reading first few lines of the input text file, but throws access violation exception at a point. It would be great if someone can tell me what might fix this. I have been trying to fix this for long now and would really appreciate some help. The wierd part is it works on linux but I need VS2008 for debugging..
Code:
int address = 0;
int function_unit = 0;
int dest = 0;
int src1 =0;
int src2 =0;
void ifetch_decode_unit()
{
if(cache_miss_flag==0 && count<10000)
{
fscanf(f1,"%x%d%d%d%d",&address,&function_unit,&dest,&src1,&src2);
number++;
int index = 0x000fe0;
int tag = 0xfff000;
index_entry = ((address&index)>>5);
tag_entry = ((address&tag)>>12);
if(cache[index_entry][0]==tag_entry)
{
cache_miss_flag = 0;
}
else
{
cache_miss_flag = 1;
cache[index_entry][0] = tag_entry;
}
}
if(cache_miss_flag>0)
{
cache_miss_flag++;
if(cache_miss_flag== 11)
{
cache_miss_flag = 0;
}
}
if(cache_miss_flag == 0 && count<=10000)
{
if(fetched_instructions<=N)
{
//printf("\nNumber of fetched instructions at each step:\t%d\t%x",fetched_instructions,address);
pipe.ifetchqueue[fetched_instructions].address = address;
pipe.ifetchqueue[fetched_instructions].function_unit = function_unit;
pipe.ifetchqueue[fetched_instructions].src1 = src1;
pipe.ifetchqueue[fetched_instructions].src2 = src2;
pipe.ifetchqueue[fetched_instructions].dest = dest;
pipe.ifetchqueue[fetched_instructions].instruction_tag = number;
fetched_instructions++;
}
}
}
void main()
{
f1 = fopen("full_trace_barnes.txt","r");
if(f1 == NULL)
{
printf("\n Unable to open the file. Aborting");
}
while(count<=10000)
{
count++;
scheduling_type0();
dispatch();
ifetch_decode_unit();
printqueues();
cycle++;
}
if(count==10000)
fclose(f1);
}