Difference between cache memory and register?

What is the difference between cache memory and registers?I know them by definition but why do we need the other when we have any one of them?


Solution 1:

Registers are:

  • Few in number (usually less than 32)
  • Limited in size (32, 64, 80, 128 bits)
  • The only things most processors can operate on directly (although x86/x86-64 blurs this a bit)

Cache is:

  • Extant (32kB+)
  • Larger in quanta (512 bytes or more)
  • Not directly accessible for operations (just a pool between the CPU and main store)

Solution 2:

Registers are controllable, you can store and retrieve information from them. There are very few of them (on x86 at least), but very fast. A lot of them have very particular uses (Instruction Pointer, Base Pointer, etc) and should not be used by the user.

Cache is almost completely uncontrollable. You can invalidate it (INVD and WBINVD privileged instructions) but you cannot explicitly store or retrieve information from it. It is also placed between memory and the CPU, so you don't even know whether it's working or not, unless you do timing comparisons. It is intended to be completely transparent in operations. Also, they can be hierarchical and fairly large (comparatively to registers at least).

Solution 3:

to make it simple processor register are much faster than cache memory, and unlike cache memory that store data, the processor register store instructions that manipulate data, by instruction i mean (address , opcode, small chuck of data that we need to operate in ...).