Parts of the CPU
The Memory Data Register (MDR) is a register inside the CPU. It stores whatever has just arrived from memory — a piece of data or an instruction — and it also holds on to data that is waiting to be sent out to memory. It always holds the value itself, never the address of the place the value came from: addresses are held in the Memory Address Register (MAR) instead.
Every instruction starts by being fetched from memory. When that read happens the instruction arrives in the MDR, and it stays there while the Control Unit decodes it and the CPU carries it out. Once the fetch has finished, then, the MDR is holding an instruction rather than a piece of data.
Anything travelling between the CPU and RAM passes through the MDR. When the CPU reads from memory, the value stored at that location is copied into the MDR. When the CPU writes to memory, the value is put into the MDR first and then sent on to memory. Nothing gets in or out without passing through this register.
For example, a vending machine's control program needs the price of a snack before it can work out change. The address of that price in memory is placed in the MAR, while the price itself — 85 pence, stored in binary — sits in the MDR as it is copied in from memory. The MDR carries the price; it does not carry the address that says where the price is kept.
OCR GCSE Computer Science · Parts of the CPU