Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Unit 4 — Associative Memory (Content Addressable Memory)

Lesson 46 of 49 in the free Computer Organization and Architecture notes on Siksha Sarovar, written by Rohit Jangra.

Associative Memory

Associative memory (Content Addressable Memory, CAM) is a memory unit accessed by the content of the data rather than by its address. All words are searched in parallel, in a single memory cycle.
   Ordinary RAM :   "give me the word at address 1024"
   Associative  :   "which word contains the value 4F2A?"

1. Organization

   Components:

   A (Argument register) : holds the data being searched for
   K (Key register)      : a MASK — a 1 selects the corresponding bit of A
                           for comparison; a 0 makes that bit a "don't care"
   Memory array          : m words of n bits, each with its own comparison logic
   M (Match register)    : m bits — bit i is set if word i matched
   Every CELL of the array contains:
      - a storage flip-flop
      - a comparison circuit (XNOR + masking)

   That is why associative memory costs several times more per bit
   than ordinary RAM: each bit needs its own comparator.

2. The Match Logic

   For word i, bit j:

      Match(i,j) = A(j) . F(i,j) + A(j)' . F(i,j)'      (XNOR = "equal")

   Including the key mask:

      Term(i,j) = Match(i,j) + K(j)'
      (if K(j) = 0, that bit position is IGNORED — always "matches")

   The whole word matches only if EVERY bit position agrees:

      M(i) = Term(i,1) . Term(i,2) . ... . Term(i,n)

3. Worked Search Example

   A (argument) = 101 111100
   K (key)      = 111 000000        <- compare only the first THREE bits

   Word 1       = 100 111100        first 3 bits = 100  ->  NO match
   Word 2       = 101 000001        first 3 bits = 101  ->  MATCH
   Word 3       = 101 111100        first 3 bits = 101  ->  MATCH
   Word 4       = 011 111100        first 3 bits = 011  ->  NO match

   Match register M = 0 1 1 0
   Notice: word 2 matched even though its lower bits differ completely —
   because the key masked those positions out. This masking ability is
   what makes associative memory useful for TAG comparison.

4. Read and Write Operations

   READ:
      1. Load A and K.
      2. All words compare in parallel -> M is set.
      3. If exactly one bit of M is set, read that word.
      4. If SEVERAL bits are set, a PRIORITY circuit (Unit II!) selects
         one at a time; the software reads them in sequence.

   WRITE:
      Option 1 : write to a specified address (like ordinary RAM),
                 used to load the memory initially.
      Option 2 : TAG bits mark which words are occupied; a write goes
                 to the first free word found by a priority encoder.
      Option 3 : overwrite the matched word (update in place).

5. Applications

ApplicationHow associative search is used
Cache memory (fully associative)Compare the tag against every cache line simultaneously
TLB (Translation Lookaside Buffer)Look up a virtual page number among all cached translations in one cycle
Network routersLongest-prefix match on IP addresses at line rate (TCAM)
Database search enginesFind records matching a key without scanning
Pattern recognitionCompare an input pattern against stored templates
Data compressionDictionary lookup in LZ-family algorithms
Virus scannersMatch against a signature database

6. Ternary CAM (TCAM)

   A normal CAM cell stores 0 or 1.
   A TERNARY CAM cell stores 0, 1, or X (don't care) PER CELL —
   the mask is stored with the data instead of in a global key register.

   This is what allows a router to store entries like:

      192.168.1.0/24   ->   stored as  11000000 10101000 00000001 XXXXXXXX

   and match any address in that subnet in ONE cycle.

7. Associative Memory vs Random Access Memory

BasisRAMAssociative memory (CAM)
Accessed byAddressContent
Search timeO(n) if you must scan for a valueO(1) — one cycle regardless of size
Hardware per bit1 storage cellStorage cell + comparator
CostLowVery high (4–10× RAM)
PowerLowHigh (every cell switches on every search)
CapacityLarge (GB)Small (KB)
Typical useMain memoryCache tags, TLB, routing tables

8. Why Associative Memory Is Small

   Every bit needs its own comparator, so:
      - area per bit is 4-10x larger than RAM
      - EVERY cell in the array switches on EVERY search
        -> power consumption scales with the whole array, not with
           the one word you wanted

   For a 1 MB fully associative structure the power would be prohibitive.
   This is exactly why real caches are SET-ASSOCIATIVE rather than fully
   associative — they compare only 2, 4 or 8 tags instead of thousands.

That trade-off is the entire subject of the next lesson.

Summary

   Associative memory = searched by CONTENT, all words in parallel
   Registers: A (argument), K (key/mask), M (match)
   Match logic: XNOR per bit, masked by K, ANDed across the word
   Search time O(1) regardless of size
   Costly in area and power -> used only for cache tags, TLBs and TCAMs