The Write-Back Phase

Read time: 13 minutes (3383 words)

The last phase in instruction processing involves saving any results generated during the other phases, and making sure the machine is ready for the next instruction. Seems simple enough. However, there are several situations that need to be handled.

As usual, the acturl parts and wiring required can be determined by an analysis of the instructions we are attempting to process.

What to Write Where

The output s available at the end of the Execute phase provide all the data needed to safely place any results back in the appropriate location. We might as well start with a short synopsis of where those data can be stored:

  • Registers
    • Rd - the usual “destination” register
  • Data Memory
    • Address may have been calculated
  • PC
    • Branch instructions calculated the new PC

Memory Storage

Normally, the RAM in a system is very large. IN our tiny AVR chip, the amount of RAM is very limited, reflecting the fact that we normally do not need to store a lot of data when controlling hardware.

THe RAM module is pretty simple, consisting of a single memory address register, and two data registers, one for incoming data (write), and one for outgoung data (read). We also need read/write signals, which are generated in the control unit.

We need to be able to write data produced by the ALU into memory, or store a constant generated by the decode unit. Once again, that means we need to place a multiplexor in the data path leading into the memory unit for writes.

Another source of data to write into memory is data stored in a register. Rather than write this result directly into the data memory, the ALU result is stored back in a register. To get it to memory, we use a simple data transfer instruction, and the operand is the address to be used for the store.

In fact, the only results passed from the ALU to data memeory are addresses. The ALU can calculate a new address, for instance in a relative branch.

There are a few registrs in the ALY that need special treatment. The top siz registers act as three 16-bit registers. These are commonly used for indirect addressing. That is, they hold an address, and the instruction refers to the data stored at that address in RAM. The AVR supports a few 16-bit instructions, and those results must land in one of these top-three registers.

Memory Reads

If we are reading from memory, we need to provide a path from the output side of the memory unit back to the register memory. Perhaps it makes sense to treat those registers as special cases, .

Register Store

Most of the basic ALU operationsproduce a result to be stored in the registers. To accomplish this, we need ot make sure that we send the destination register number, obtained during decode, through all stages so the Writeback phase can send that address back to the register bank, to be used to indicate where the value is to be stored.

There are at least three different data items that may need to be written into a register:

  • Data from another register
  • Results of an ALU calculation
  • Memory data read from RAM

Once agian, w prodvide a multiplexor to decide which of these three possible sources will be written back into the registers. The address to be used must have been [assed along from the decoder, so it can now be used to properly store the result.

This overview is just a glimpse at the writeback phase. All we needed to add to our system here, are a few simple multiplexors,a nd make sure hat needed data reaches this stage before we need it to select the destination register.