3
\$\begingroup\$

A small byte-addressable embedded computer system, with a word length of 32 bits, has a main memory consisting of 4 KBytes. It also has a small data cache capable of holding eight 32-bit words, where each cache line contains only two words. Consider a direct-mapped cache.

Answer

Since the cache is direct-mapped, the size of the set is 256 bits (?) = 32 byte and therefore it takes 5 bits to address the memory, so the number of bits that are not the tag is 5 (?) = 27 bits are used for the tag (?)

Since a line is 2 words = 64 bits (?) = 8 byte then the offset takes 3 bytes and therefore the block takes 2 bytes (?).

Is it true?

\$\endgroup\$
2
  • 1
    \$\begingroup\$ In your last paragraph, you're confusing bytes and bits, but in general, that looks right. \$\endgroup\$
    – Dave Tweed
    Commented Sep 5, 2013 at 12:01
  • \$\begingroup\$ @DaveTweed Thanks, I'm going to go thru it again to get it all right. \$\endgroup\$ Commented Sep 5, 2013 at 12:14

1 Answer 1

3
\$\begingroup\$

An address in a cached system has up to three parts: tag, set and offset.

Since the given system is byte addressable, and a cache line is two words (eight bytes), the offset portion of the address requires 3 bits.

A direct mapped cache has no set association. Or, if you will, it may be regarded as collection of sets, each of which holds only one block. So no set -> block associative lookup is required, and the set field of the address can be called a block field. This field directly determines the block to which the address maps, hence the "direct mappped" designation. The tag is used to determine whether a given block in the cache is a "hit" for the address, or holds data for some other address. (Whereas under set association, the tag is used to search through a set of blocks for a hit: the set elements are associated with addresses via the tag field.

The cache has four blocks, because it holds eight words, but pairs of words are considered blocks. So the set/block part of the address requires two bits.

The remainder are tag bits. Since memory space is 4 Kb wide (let us assume there is no virtual memory), addresses are 12 bits wide, and so there are 12 - 3 - 2 = 7 tag bits.

Note that if the set size were 256 bits, it would make the cache fully associative rather than direct mapped: a situation in which the entire cache is one big set of blocks, and so there is no set field in an address, only a tag and offset. The tag is used to search the entire cache for a hit. Under set association, the additional set field restricts the search to an indexed set, which just holds a single block under the direct mapped cache.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.