Work out the widths of tag, index and offset for one cache, and then split three addresses.
Hardware context: A direct-mapped read cache of four lines with blocks of four words, in front of a slow memory, as test code. Designing and checking the hit path and the reset of a cache
A direct-mapped cache serves addresses of 32 bits, which count bytes. It has 64 lines. Each line holds a block of 8 words, and a word is 4 bytes. Work out the three fields of an address, and then use them on the addresses below.
This worksheet uses named constants. The first three entries show how to record your decisions.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
question | 8 | input of each check |
Full specification
Enter widths in bits, and field values as plain numbers. For a yes-or-no entry, enter 1 for yes and 2 for no.
| Entry | Your decision |
|---|---|
| OFFSET_BITS | How many bits has the offset? |
| INDEX_BITS | How many bits has the index? |
| TAG_BITS | How many bits has the tag? |
| WORD_SELECT_BITS | How many bits of the offset pick the word inside the block? |
| A_INDEX | Address A is 0x00001b64. What is its index? |
| A_WORD | Which word of the block does address A pick? |
| A_TAG | What is the tag of address A? |
| B_WORD | Address B is 0x00001b7c. It has the same tag and index as A. Which word does it pick? |
| C_TAG | Address C is 0x00002364. What is its tag? |
| C_REPLACES_A | The cache holds the block of A. Then C is read. Does C push the block of A out? Enter 1 for yes, 2 for no. |
| TAG_VARIANT | Now the cache has LINES lines, a power of two from 1 to 1024, and the same blocks of 32 bytes. Give the width of the tag in bits. |
Examples
Example 1
OFFSET BITS- Input
How many bits has the offset?
- Output
matches = 1
A block is 8 words of 4 bytes: 32 bytes. Thirty-two is two to the power of five.
Example 2
INDEX BITS- Input
How many bits has the index?
- Output
matches = 1
Sixty-four lines need six bits.
Example 3
TAG BITS- Input
How many bits has the tag?
- Output
matches = 1
The rest: 32 less 5 less 6.
Constraints and Contract
- Keep the parameter and named constants. Use the numeric codes and units on this page.
- For TAG_VARIANT, enter a constant expression using LINES. Only this entry changes with the parameter. The supported integer range is 1 through 1024, inclusive.
Hints
Hint 1
Count the bytes of a block. That many need how many bits?
Hint 2
Count the lines. That many need how many bits?
Hint 3
Write the address in binary and cut the offset off, then the index. The rest is the tag.
What the grader checks: Each check compares the full eight-bit answer. Parameter trials change one condition and keep the other decisions fixed.
11 checks on Icarus Verilog · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain your source only; samples require the simulation service. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 2 problems on this path