diff --git a/cache.c b/cache.c index fa725be..e4a2264 100644 --- a/cache.c +++ b/cache.c @@ -74,12 +74,18 @@ int cread(unsigned int cmf, unsigned int* hex_addr, bool* hit, bool* replace) { if (cache[line]->tag == tag) { // hit - *replace = true; + *hit = true; cache[line]->hit_count++; ret_val = cache[line]->block[block_offset]; } else { // miss - *hit = true; + if (cache[line]->tag == EMPTY) { + open_line = line; + } else { + replace_line = line; + *replace = true; + } + cache[line]->tag = tag; cache[line]->hit_count = 1;