2
$\begingroup$

Is every instruction ultimately all read or write instructions? So, how I imagine this is that every place where something can be stored can be either in a read or write state, including the CPU registers.

How this is controlled is by the control unit. Every instruction goes through the control unit which is connected to the control bus and flips memory locations (computer memory addresses) to either read or write state.

I understand that there is much more too this depending on what information the control bus can carry, but is this general overview correct in how data is moved about?

$\endgroup$
  • $\begingroup$ Do permissions/memory virtualisation count as "read and write"? $\endgroup$ – Aidan Connelly Jun 28 '17 at 14:16
6
$\begingroup$

Ultimately, the state of the machine must change after executing every single instruction: if it did not, then the machine would be stuck in an infinite loop of executing the same instruction again and again. So, in that sense, some value in memory or in a register to be changed after each instruction is executed. At a minimum, this would be advancing the program counter.

If you want to count that as a "write" instruction then, yes, every instruction is a write instruction. However, then we would be in the situation that the phrase "write instruction" would mean exactly the same thing as "instruction", so it wouldn't be a useful piece of terminology. OK, so perhaps we want to define a write instruction to be one that directly alters a register or the main memory, where, by "directly alters", I'm excluding the automatic increment of the program counter. Well, OK, but that's not very useful, either, since every instruction I can think of does that, apart from a no-op. That wouldn't be a useful definition, either.

So, typically, "write instruction" is understood to mean an instruction that writes a value to some location in the main memory. Clearly not all instructions do that: for example, typical arithmetic instructions operate only on the registers. Similar arguments can be made for reading.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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