9

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?

1

6 Answers 6

13

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)
2
  • My question might go a bit off the question I asked but can we make a computer that is totally based on cache?So that it may be a zero state machine.
    – user46959
    Commented Nov 10, 2010 at 18:25
  • 2
    At the very least a CPU needs an Instruction Pointer register so that it knows what it's trying to run. So, no. Commented Nov 10, 2010 at 18:28
3

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).

1

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 ...).

1
  • Right. The CPU dpesn't fetch opcodes (instructions) from registers; but many instructions (take ADD for example, which adds two numbers and stores the result somewhere) can either get their data from a register, or a memory location.
    – LawrenceC
    Commented Nov 14, 2010 at 13:26
1

So I guess what you're wondering is, since it's all just stored bytes, why single some of them out as registers, and call the rest cache?

Well, it's been a while since I programmed on the PIC but if I remember correctly the PIC does not distinguish between "memory" and "registers", and calls all of its memory "registers"; they all share an address space. Some of these are special purpose, for things like IO ports, but most are general purpose.

Is this a good idea? Well it's obviously not a terrible one because the PIC is a reasonably successful microcontroller. But you can see that this would have limitations when you start scaling up to add more memory and a faster clock. (I am not an EE so take this with a grain of salt). The advantage to singling out a few particular registers is that they can be connected to fewer things: all the wires attaching to a circuit add capacitive loading which slows it down. On a modern machine with kilobytes of cache that would be a lot of loading for something you want to access basically every instruction. I imagine there might also cost advantages because you could make the registers out of wide, fast transistors, and then scale down for the cache which doesn't need to be as fast.

0

A register holds instructions or data that the processor is working on or will be working on shortly. They form part of the processor and are capable of holding only one item at a time.

A cache memory is an area in the computer where codes and instructions are stored.

1
  • As the accepted answer from 4 years ago says: cache just sits between the cpu and main ram, which is where instructions and data are stored.
    – psusi
    Commented Mar 20, 2014 at 0:21
0

Cache has a content-addressable nature -- a given row (at least conceptually) contains both data and address as dynamic values, so that the row will recognize its own address and respond, vs having to be addressed with a specific externally-generated hard-wired address.

It is this content-addressable nature that defines something as "cache".

(Of course in practice cache is often implemented with relatively conventional "hard-wired address" RAM, and an address translation unit on the side, but it's not really a "cache" until you combine the two.)

You must log in to answer this question.