Course contentsShow
← Embedded Systems & Computer Architecture
Lesson 57 of 9361. Foundations of Digital Logic and Computer ArchitectureFree lesson

Handling Memory Access and Write-Back Paths

You will implement the logic required to interface the data memory with the register file for load and store operations.

In this lesson, you will learn how to route data between your data memory and your register file to complete load and store instructions.

The Bridge Between Memory and Registers

So far, we have built a processor that can perform calculations in the ALU and store values in the Register File. Now, we must connect these components to the Data Memory. This path handles two critical tasks: moving data from the Register File into memory (Store) and pulling data from memory into the Register File (Load).

The Load-Store Data Path

To interface these units, we look at three specific signals: MemRead, MemWrite, and the result coming back from the Data Memory.

  1. Store Operations: We send the data from the Register File into the Write Data port of the Data Memory. We set MemWrite to high to trigger the save.
  2. Load Operations: We send an address (calculated by the ALU) to the Data Memory’s Address port. We set MemRead to high, and the memory outputs the requested data.

The Write-Back Multiplexer

The "Write-Back" phase is where we decide what value actually gets stored in the Register File. Since our processor can perform both ALU operations (adding numbers) and memory operations (loading numbers), the Register File has a "fork in the road." We use a multiplexer to choose the source:

// Simplified logic for the Write-Back Mux
always @(*) begin
    if (MemToReg == 1'b1)
        WriteData = ReadDataFromMemory; // From Load instruction
    else
        WriteData = ALUResult;          // From ALU operation
end

By using the MemToReg control signal, the processor chooses between the output of the ALU or the output of the Data Memory. This ensures that when you execute a Load instruction, the data arrives safely at the destination register, and when you perform an Add instruction, the ALU result is stored instead. This path completes the loop, allowing your processor to keep data moving from storage to computation and back again.

Key Takeaway: The Write-Back path uses a multiplexer controlled by the processor to decide whether the Register File receives data from the ALU or directly from Data Memory.