Question: Design and implement a software simulation of a cache memory subsystem. You can use C++, Java, or python. This will be a simulation of the
Design and implement a software simulation of a cache memory subsystem. You can use C++, Java, or python. This will be a simulation of the way that a real cache works. Your "main memory" will be a 2K array. You can make it an array of integers or shorts (16-bits), but because it is simulating a byte-addressable memory, you won't be putting any value larger than 0xFF (255 decimal or 11111111 binary) in it. You will provide for these two areas by defining an array for main memory and a structure/class/record (or array of these) for the cache. For example, short Main_mem[2048]; So, in effect, your Main_mem array will be the "pretend" main memory area, your cache structure/class which you define will be the "pretend" cache, your program will pretend to be the intelligence of the memory sub-system, and requests that you type in will be the equivalent of a processor making requests of the memory subsystem. You will implement a direct-mapped, write-back cache. The block size will be 16 bytes and you'll have 16 slots.
1.You MUST initialize your main memory (MM) in such a way that you'll be able to know whether you have the original value or not and also such that you'll be able to tell one byte from another. To achieve this, I want you to assign the value 0 to MM[0], 1 to MM[1], and so on until 0xFF to MM[0xFF]. 0xFF is the biggest value you can put in a byte, so then you should resume putting 0, 1, 2, and so on into MM elements x100, x101, and x102 (MM[x100] = 0, MM[x101] = 1, and MM[x102] = 2) until youve initialized the entire main memory array (MM[0x7FF] = 0xFF).
2.Do not use the modulo function to extract the appropriate fields from the addresses. Use bitwise operations and shifts instead since they are much closer to what happens in hardware.
3. You will need to support three types of requests from the screen once you have initialized your "main memory" and "cache" : Read byte, Write byte, and Display cache. You MUST show whether it was a cache hit or miss and (on reads) what value you read out of the cache.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
