5
$\begingroup$

I'm a little confused about the difference of the memory access and the write-back stage in a RISC pipeline.

We learned in class these following assumptions:

arithmetic & logic: IF, OF, EX, WB
load: IF, OF, EX, MA, WB
store: IF, OF, EX, MA
branch: IF, OF, EX

IF=Instruction Fetch, OF=Operand Fetch, EX=Execution, MA=Memory Access, WB=Write-Back

Lets say we have the following code now:

I1: LD R1, 0(R2) ; load R1 from address 0 + R2
I2: ADD R1, R1, #1 ; R1 = R1 + 1
I3: ST 0(R2), R1 ; Store R1 at address 0 + R2

According to what I've learned I1 will pass all five stages, I2 won't have to access the memory, and I3 won't have a write-back.

But then I wonder, how and where does I3 store the value then? Just in the memory? And I2 fetches the value from memory, but needs to write-back to some place other than the memory? So does that mean that write-back is always to the HDD?

I think I'm missing some core concepts here, as to where the operand is fetched from and where it gets stored to.

$\endgroup$
2
  • $\begingroup$ When you said "And I2 fetches the value from memory", did you mean I1? $\endgroup$
    – Pseudonym
    Commented Jan 13, 2014 at 3:47
  • $\begingroup$ I think I'm getting mixed up between memory and registers. $\endgroup$ Commented Jan 13, 2014 at 10:41

3 Answers 3

9
$\begingroup$

In a classic 5-stage RISC pipeline, WB writes a value into a register. If the instruction doesn't write a value into a register (e.g. store), then that stage isn't used.

I1 stores a result into a register (namely R1), so it uses WB.

I2 stores a result into a register (R1) so it uses WB.

I3 does not store a result into a register, so it doesn't use WB.

You basically got it with I3: the store instruction stores to memory, so the "write" is performed inside MA.

Incidentally, on "real" RISC machines, MA tends to be more complex (and multi-cycle) because of multi-level caches and virtual memory. A store instruction may cause a page fault, so in a sense it has a "result" that isn't just the memory access.

$\endgroup$
2
  • 1
    $\begingroup$ This is what I don't understand though. Doesn't store do exactly what the name says? It stores a given result in a register. In this case R1 into 0(R2). I don't get why there is a difference in loading a value into a register, i.e. I1, and storing in a register, i.e. I3. $\endgroup$ Commented Jan 13, 2014 at 10:38
  • 3
    $\begingroup$ If you're using the MIPS/DLX-ish instruction set (which it appears you are), ST stores a result in memory. In this case, the location pointed to by the address 0(R2). In CPU-speak, "store" refers to storing a location in memory. If you were transferring a value in one register into another register, it would be called a "move". $\endgroup$
    – Pseudonym
    Commented Jan 14, 2014 at 5:04
0
$\begingroup$

I did not quite understand your question I am trying to answer.You can ask further if it is not clear.As we know in RISC machine most of the instruction will be performed on registers and memory is addressed only in index mode.I1 will store value in memory address given by R2.I2 will not access memory as it has all sources and destinations as registers.And write back stage is only used for register read and write.

$\endgroup$
0
$\begingroup$

There are also cases a store will have a writeback. For example store-conditional which will return status when accessing a memory location.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.