Answered step by step
Verified Expert Solution
Question
1 Approved Answer
What approach should I take to do this in python or c? You'll write a program to simulate the behavior of a hardware memory cache.
What approach should I take to do this in python or c?
You'll write a program to simulate the behavior of a hardware memory cache. 1.1 Memory hierarchy Model memory as an array of bytes. Each memory access will read or write one word (four bytes). Check that each address is aligned on a four-byte boundary, and assert if it isn't. Also check that each memory access is in range, and assert if it isn't. So for example if memory [56] = 45 and memory [57] = 12 and memory [58] = 3 and memory [59] = 7, then the word referenced by address 56 would be 45 + 256 * (12 + 256 * (3 + 256 * 7)) = 117640237 (assume a little-endian system). When a range of values is loaded into the cache, the number of bytes loaded will thus be a multiple of four. 1.3 Parameters Your simulator should let you specify these parameters: the size of a memory address, in bits the size of the cache, in bytes this size cache block, in bytes the associativity of the cache whether the cache is a write-back or write-through cache Do not hardcode any of these valuesthey should be configurable. Use a variable or a #define to represent each of them. But, assume a write-allocate cache: on a write miss, the block containing the memory address in question is first brought into the cache. 1.5 Functions Create two functions: one to read a word from memory, and one to write a word to memory. For example: in C, my functions would look like this: Word readWord(unsigned int address); void writeWord (unsigned int address, Word word); Word is a typedef to an int. In Python, I might do this: readWord (address) writeWord(address, word) where readWord returns the value read from the specified address. Again, check each address for four-bit alignment and for range 0Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started