Implementation of mapping techniques

/*
* Title: Implementation of mapping techniques
* Name: Akshay Thakare
* Roll No: 6790
*/

#include
#include

void direct(int m,int c,int b)
{	
	int s=0,w=0,r=0;
	printf("\nFOR DIRECT MAPPING\n");
	printf("Size of cache is %d\n",c);
	printf("No. of blocks in MM : %d\n",m/b);
	printf("No. of blocks in cache : %d\n",c/b);
	while(pow(2,w)!=b)
		w++;
	while(pow(2,s)!=(m/b))
		s++;
	while(pow(2,r)!=(c/b))
		r++;
	printf("TAG   LINE   WORDS\n");
	printf("%d\t%d\t%d\n",s-r,r,w);
}

void associ(int m,int c,int b)
{	
	int s=0,w=0;
	printf("\nFOR ASSOCIATIVE MAPPING\n");
	printf("Size of cache is %d\n",c);
	printf("No. of blocks in MM : %d\n",m/b);
	printf("No. of blocks in cache : %d\n",c/b);
	while(pow(2,w)!=b)
		w++;
	while(pow(2,s)!=(m/b))
		s++;
	printf("TAG   WORDS\n");
	printf("%d\t%d\n",s,w);
}

void set(int m,int c,int b)
{	
	int s=0,w=0,k=0,v=0,d=0;
	printf("\nFOR SET ASSOCIATIVE MAPPING\n");
	printf("Size of cache is %d\n",c);
	printf("No. of blocks in MM : %d\n",m/b);
	printf("No. of blocks in cache : %d\n",c/b);
	printf("Enter value of K : ");
	scanf("%d",&k);
	v=(c/b)/k;
	
	while(pow(2,w)!=b)
		w++;
	while(pow(2,s)!=(m/b))
		s++;
	while(pow(2,d)!=v)
		d++;
	printf("TAG   SET   WORDS\n");
	printf("%d\t%d\t%d\n",s-d,d,w);
}

int main()
{
	int b,m,c;
	printf("Enter size of main memory  ");
	scanf("%d",&m);
	printf("Enter size of cache memory  ");
	scanf("%d",&c);
	printf("Enter size of block  ");
	scanf("%d",&b);
	direct(m,c,b);
	associ(m,c,b);
	set(m,c,b);
}
/*
Output 1
Enter size of main memory  524288
Enter size of cache memory  8192
Enter size of block  128

FOR DIRECT MAPPING
Size of cache is 8192
No. of blocks in MM : 4096
No. of blocks in cache : 64
TAG   LINE   WORDS
6       6       7

FOR ASSOCIATIVE MAPPING
Size of cache is 8192
No. of blocks in MM : 4096
No. of blocks in cache : 64
TAG   WORDS
12      7

FOR SET ASSOCIATIVE MAPPING
Size of cache is 8192
No. of blocks in MM : 4096
No. of blocks in cache : 64
Enter value of K : 16
TAG   SET   WORDS
10      2       7

Output 2
Enter size of main memory  65536
Enter size of cache memory  4096
Enter size of block  16

FOR DIRECT MAPPING
Size of cache is 4096
No. of blocks in MM : 4096
No. of blocks in cache : 256
TAG   LINE   WORDS
4       8       4

FOR ASSOCIATIVE MAPPING
Size of cache is 4096
No. of blocks in MM : 4096
No. of blocks in cache : 256
TAG   WORDS
12      4

FOR SET ASSOCIATIVE MAPPING
Size of cache is 4096
No. of blocks in MM : 4096
No. of blocks in cache : 256
Enter value of K : 4
TAG   SET   WORDS
6       6       4
*/
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s