Skip to content
BetterDL

Read during write

Also called: read-during-write behavior, simultaneous read and write, read while writing, write-then-read

What a register file's read port shows when it reads the register being written in the same cycle: the old value, until the write takes effect at the edge.

Read during write describes a register file cycle in which a read port reads the same register that the write port is writing.

The rule follows from how the parts work:

  • Reading is combinational: the read MUX shows whatever the register's flip-flops hold right now.
  • Writing changes the flip-flops only at the rising edge.

So during the cycle, before the edge, the read port shows the old value. After the edge, it shows the new one.

Why it matters in a CPU: suppose one instruction writes R1 and the very next one reads R1. If the read happens in the same cycle as the write, the second instruction would get a stale value. Pipelined processors handle this with tricks such as writing in the first half of the cycle and reading in the second, or a bypass (forwarding) path that sends the new value straight to the reader.

In this course, assume the simple behavior: a read sees the value stored before the edge.

Worked example

Example

Reading R2 while writing it

R2 holds 0011. In one cycle, W = 1, the write address is 2 and the write data is 1000, while a read port is addressed to R2.

  1. 1.

    During the cycle, R2's flip-flops still hold 0011, so the read port outputs 0011.

  2. 2.

    At the rising edge, R2 loads 1000.

  3. 3.

    After the edge, the read port outputs 1000.

Common mistakes

  • Expecting the read port to show the new data as soon as it is placed on the write lines.

  • Thinking the read port is clocked. It is combinational; only the write waits for the edge.

Practice Read during write

Interactive questions with instant feedback and a worked solution for every wrong answer.

Learn it step by step

Read during write is taught in Registers and Basic CPU / Computer Architecture.