mirror of
https://github.com/Comp211-SP24/lab-05-Rushilwiz.git
synced 2025-04-09 14:50:19 -04:00
forgot to clang
This commit is contained in:
parent
69c47204ae
commit
f4a9616adc
20
cache.c
20
cache.c
|
@ -68,7 +68,8 @@ int cread(unsigned int cmf, unsigned int* hex_addr, bool* hit, bool* replace) {
|
||||||
|
|
||||||
if ((cmf == DM) && ((*hex_addr) < exp2(addr_bits))) {
|
if ((cmf == DM) && ((*hex_addr) < exp2(addr_bits))) {
|
||||||
tag = bit_select(*hex_addr, addr_bits - 1, addr_bits - NUM_TAG_BITS_DM);
|
tag = bit_select(*hex_addr, addr_bits - 1, addr_bits - NUM_TAG_BITS_DM);
|
||||||
line = bit_select(*hex_addr, addr_bits - NUM_TAG_BITS_DM - 1, NUM_BLOCK_OFFSET_BITS);
|
line = bit_select(*hex_addr, addr_bits - NUM_TAG_BITS_DM - 1,
|
||||||
|
NUM_BLOCK_OFFSET_BITS);
|
||||||
block_offset = bit_select(*hex_addr, NUM_BLOCK_OFFSET_BITS - 1, 0);
|
block_offset = bit_select(*hex_addr, NUM_BLOCK_OFFSET_BITS - 1, 0);
|
||||||
|
|
||||||
if (cache[line]->tag == tag) {
|
if (cache[line]->tag == tag) {
|
||||||
|
@ -82,10 +83,12 @@ int cread(unsigned int cmf, unsigned int* hex_addr, bool* hit, bool* replace) {
|
||||||
cache[line]->tag = tag;
|
cache[line]->tag = tag;
|
||||||
cache[line]->hit_count = 1;
|
cache[line]->hit_count = 1;
|
||||||
|
|
||||||
unsigned int mem_index = block_location[*hex_addr >> NUM_BLOCK_OFFSET_BITS];
|
unsigned int mem_index =
|
||||||
|
block_location[*hex_addr >> NUM_BLOCK_OFFSET_BITS];
|
||||||
|
|
||||||
|
memcpy(cache[line]->block, phy_memory + mem_index,
|
||||||
|
sizeof(unsigned int) * (int)exp2(NUM_BLOCK_OFFSET_BITS));
|
||||||
|
|
||||||
memcpy(cache[line]->block, phy_memory + mem_index, sizeof(unsigned int) * (int)exp2(NUM_BLOCK_OFFSET_BITS));
|
|
||||||
|
|
||||||
ret_val = cache[line]->block[block_offset];
|
ret_val = cache[line]->block[block_offset];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,16 +103,17 @@ int cread(unsigned int cmf, unsigned int* hex_addr, bool* hit, bool* replace) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_binary(unsigned char num) {
|
void print_binary(unsigned char num) {
|
||||||
// Start from the most significant bit (MSB) and move to the least significant bit (LSB)
|
// Start from the most significant bit (MSB) and move to the least
|
||||||
|
// significant bit (LSB)
|
||||||
for (int i = 7; i >= 0; i--) {
|
for (int i = 7; i >= 0; i--) {
|
||||||
// Use bitwise AND to isolate the specific bit and shift right to get 1 or 0
|
// Use bitwise AND to isolate the specific bit and shift right to get 1
|
||||||
|
// or 0
|
||||||
int bit = (num >> i) & 1;
|
int bit = (num >> i) & 1;
|
||||||
printf("%d", bit);
|
printf("%d", bit);
|
||||||
}
|
}
|
||||||
printf("\n"); // Newline after printing the binary number
|
printf("\n"); // Newline after printing the binary number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void cprint() {
|
void cprint() {
|
||||||
unsigned int line;
|
unsigned int line;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user