I am reading this book "Computer Architecture and Organization" by Subrata Ghosal because I'm curious about how data is "stored" in the CPU register.
When I say "data is stored", I imagine something that allows me to:
- Write data to it
- As long as I don't rewrite, reading from it will return the last written data
And the book claims that the computer register allows that capability.
According to the book, a register can be made up of many clocked D flip flops, which are in turn can be made up of an S-R latch:
The D flip flop works like this:
- When CLK is 0, Q doesn't change
- When CLK is 1, D determines Q
Now a 4-bit register can be made up of 4 D flip flops:
I imagine this register is inside a RUNNING computer, then the CLK will alternate between 1 and 0 at specific interval. So my question involves this situation:
- Supposed at point t0 in time: CLK is 1, I store in the third D flip flop the value 1 by setting the input to this flip flop to 1. Immediately after this, if I read from this flip flop, I will receive 1.
- t1: CLK is 0: If I retrieve Q3, the value returned will be 1 -> I successfully retrieve the value I stored in this flip flop previously at t0.
- t2: CLK is 1: Because now CLK is 1, Q3 will be depended on input of this flip flop. If at this point, the input is 1, then the value retrieved will be 0. But there's no guarantee that at this point, the input to this flip flop is 1. If the input is 0, I'll retrieve 0, which is not the value I previously stored at t0.
So it seems in order to retrieve the correct value I "stored" at a previous point in time, a necessary condition is that the correct input to the flip flop must also happen but there's nothing to guarantee that. This doesn't sound like "storing data" to me.
I must have misunderstood something but couldn't figure it out.