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$
1
  • $\begingroup$ Do permissions/memory virtualisation count as "read and write"? $\endgroup$ Jun 28, 2017 at 14:16

1 Answer 1

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 and acknowledge that you have read and understand our privacy policy and code of conduct.

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