I was wondering if you are able to help me with this project. This is my last se
ID: 3765797 • Letter: I
Question
I was wondering if you are able to help me with this project. This is my last semester and I have B in the class and I am looking for an A. Never been good with programming so I could really use some help.
Consider the following list of 32-bit memory references, given as word addresses:
21, 166, 201, 143, 61, 166, 62, 133, 198, 197, 22, 111. We would like to use a program to
compare hit rates for different direct mapped cache configurations.
Write a program that takes three inputs (an array of references, the number of blocks in the
cache, the number of words per cache) and return the one output (the hit rate). Each word is 32-
bit long.
Test your program and submit your result for:
a) Direct-mapped cache with 16 one-word cache
b) Direct-mapped cache with 8 two-word cache
c) Direct-mapped cache with 4 four-word cache
We can use either matlab or c ++ to do this.
Thanks alot!
Explanation / Answer
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#define CACHESIZE 16
struct cache{
unsigned int address;
char state;
};
unsigned int events = 0;
struct cache myCache[CACHESIZE];
enum values { VALID = 0, INVALID, EMPTY };
unsigned int GetAddr (FILE *fp)
{
char c; /* Character read */
unsigned int address;
do {
c = getc (fp); /* Get next character */
if ( c == '#' ) /* Skip the comment */
do {
c = getc (fp);
} while ( c != ' ');
} while (!isxdigit(c) && !feof(fp));
ungetc(c, fp); /* Return the character to the file */
fscanf(fp, "%x ",&address);
return (address);
}
float CacheAccess (unsigned int adress){
static unsigned int hit = 0;
return (hit/(float)events);
}
int main (int argc, const char * argv[]) {
FILE *fp; /* Pointer to the input file */
unsigned int ref;
/* Initialize the cache */
for (int i=0; i < CACHESIZE; i++){
myCache[i].state = INVALID;
myCache[i].address = EMPTY;
}
fp = fopen ("trace(1).txt","r"); /* Open file for read operation */
while (!feof(fp)) {
ref = GetAddr(fp);
CacheAccess(ref);
events++;
}
printf("Hit rate is %d hits and misses", );/* Print the hit rate of the cache */
}
b)
for(i=0;i<N;i++) {
for(j=0;j<N;j++) {
dest[i][j] = 0;
for( k==;k<N;i++) {
dest[i][j] += src1[i][k] * src2[k][j];
}
}
}
int itemsPerCacheLine = CacheLineSize / sizeof(elemType);
for(i=0;i<N;i++) {
for(j=0;j<N;j += itemsPerCacheLine ) {
for(jj=0;jj<itemsPerCacheLine; jj+) {
dest[i][j+jj] = 0;
}
for( k==;k<N;i++) {
for(jj=0;jj<itemsPerCacheLine; jj+) {
dest[i][j+jj] += src1[i][k] * src2[k][j+jj];
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.