We are given 32 bit memory address references.

For example:

180, 43,2.

We are asked to find the index "given a direct-mapped cache with two-word blocks and a total size of 8 blocks". Mind you have I have the answers. I am looking to HOW to get those answers.

The index for 180, 43 and 2 are 2, 5 and 1. For other questions, I used the address mod the number of blocks. But modding those three numbers by 8 or 16 is not working.

  • 2
    \$\begingroup\$ I don't understand the wording of your question. Can you provide more detail? \$\endgroup\$ – Majenko Dec 16 '14 at 19:18
  • 1
    \$\begingroup\$ Your question makes little sense. What "index" exactly? The cache block number, the word offset within a block, word offset within whole cache, something else? Without a definition of "index" in this context, this question is meaningless and needs to be closed in its current form. \$\endgroup\$ – Olin Lathrop Dec 16 '14 at 19:24

Based on the known numeric answers, it is presumed that you are asking for the block index in the cache memory that corresponds to each given main memory address. Since there are only 8 blocks in the cache, the values can only go from 0 to 7. Furthermore, each cache block holds 2 words (so each even memory address and its next odd memory address map to the same block).

int(180/2) mod 8 = 2
int( 43/2) mod 8 = 5
int(  2/2) mod 8 = 1

The "mod 8" is because the indexes repeat every 8 ( x mod 8 is always from 0 to 7). The "/2" is because each block can hold 2 addresses. The "int" basically truncates the division, and we don't mind where exactly in the block the address value resides (1st or 2nd word).

Since some readers may be interested in what direct memory cache is, I found this instructional video.

| improve this answer | |
  • \$\begingroup\$ It looks like I knock off the decimal after dividing by two. For example 253: (253/2) mod 8 = 6.5 but my book just says 6. \$\endgroup\$ – munchschair Dec 16 '14 at 20:35

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