Question

4way LRU MIPS that mark the hits Code for MIPS Mars

4way LRU MIPS that mark the hits

memory. Use the following sequence to test your algorithm: 1,2,3,4,2,5,6,2,7,8,2,4,9,2,12,13,5,2,8,15

Code for MIPS Mars

media%2F5f3%2F5f3d4804-fecb-4fec-8246-e0

media%2F5f3%2F5f3d4804-fecb-4fec-8246-e0

0 0
Add a comment Improve this question Transcribed image text
Answer #1

iven sthing MIPS 5-2 Pages frama 52-6-4 franc 3 2 3 amc2 5 aine 3 frame 내 No 내

Code for implementation of this LRU MIPS

C language code

#include <stdio.h>

int findLRU(int time[],int n){

    int i,min=time[0],pos = 0;

    for(i=1;i<n;++i){

      if (time[i]<min){

         min=time[i];

         pos=i;

       }

     }

return pos;

}

int main (){

int nf,np,frames[10],pages[30],counter=0,time[10],flag1,flag2,i,j,pos,faults=0;

printf ("enter num of frames");

scanf("%d",&nf);

printf("enter num of pages");

scanf("%d",&np);

printf ("enter the string");

for(i=0;i<np;++i)

    scanf("%d",&pages[i]);

for(i=0;i<nf;++i)

    frames[i]=-1;

for(i=0;i<np;++i){

flag1=flag2=0;

for(j=0;j<nf;++j){

      if(frames[j]==pages[i]){

        counter++;

        time[j]=counter;

       flag1=flag2 =1;

       break;

      }

   }

   if (flag1==0){

       for(j=0;j<nf;++j){

          if (frames[j]==-1){

          counter++;

          faults++;

          frames[j]=pages[i];

          time[j]=counter;

          flag2=1;

          break;

       }

    }

}

if (flag2 == 0){

     pos=findLRU(time,nf);

     counter++;

     faults++;

     frames[pos]=pages[i];

     time[pos]=counter;

     }

   printf("\n");

   for(j=0;j<nf;++j)

       printf("%d\t",frames[j]);

   }

}

printf("\n total number of page faults =%d",faults);

return 0;

}

Add a comment
Know the answer?
Add Answer to:
4way LRU MIPS that mark the hits Code for MIPS Mars
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT