3 Replies - 623 Views - Last Post: 09 April 2010 - 11:54 PM Rate Topic: -----

#1 Guest_Arun*


Reputation:

Access violation writing exception

Posted 09 April 2010 - 12:03 PM

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..


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);
}



Is This A Good Question/Topic? 0

Replies To: Access violation writing exception

#2 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: Access violation writing exception

Posted 09 April 2010 - 05:38 PM

Can you post the input file?
Was This Post Helpful? 0
  • +
  • -

#3 bodom658  Icon User is offline

  • Villiage Idiom
  • member icon

Reputation: 113
  • View blog
  • Posts: 1,123
  • Joined: 22-February 08

Re: Access violation writing exception

Posted 09 April 2010 - 06:11 PM

Segmentation Fault...

Make sure your index and tag pointers are right.

Is there a reason you have to set these hex values manually?
Was This Post Helpful? 0
  • +
  • -

#4 PlasticineGuy  Icon User is offline

  • mov dword[esp+eax],0
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,436
  • Joined: 03-January 10

Re: Access violation writing exception

Posted 09 April 2010 - 11:54 PM

If you only need Visual Studio for its debugger, have you considered a separate debugger?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1