An instruction such as add r2, r2, r3 exists as a number in memory.It is not an instruction, it is not decoded to a bit pattern; it is already a bit pattern.
Let's drop the ARM for a moment and talk about a PDP11, and to celebrate the moment, let's also talk in octal.
It's a two address architecture, so your example looks like this:
And it is assembled (compiled) into the number 060302. The PDP11 had such a simple machine code that you could read it easily in many cases. Here the 06 means add, the 03 means R3 and the 02 means R2.
That bit pattern 060302 is just a number, it is indistinguishable from data, say the decimal number 24770, or the Unicode character 惂. The only
thing that distinguishes it as an instruction is that the computer executes it.
Let's get perverse.
Code: Select all
We can imagine location zero holds an add instruction. It adds ... something to R3. 27 says take register 7 and look at the address it points to. Once you have that value, increment register R7.
Register R7 just happens to be the program counter, and it is currently pointing at location 00002. So we add the value 060327 to R3, and then increment the program counter so it is now looking at location 00004, just in time to execute the next instruction, which is a Branch If Equal (as determined by the leading 001) to this location plus octal 337.
But we can look at those numbers in a different way. Instead of starting at location zero, let's jump directly to location 2. We know what 060327 does; it adds R3 to whatever comes next, in this case location 00004, which contains 1337.
Either scenario is equally likely, neither of them are right or wrong. In the first case location 2 was data and location 3 was program, in the second case it was the other way round.
You may complain that my program would have been written as
and therefore the immediate value is program, not data. However the computer does not know what I wrote, and to it register R7 is just another register. I could have written
Code: Select all
ADD [R7]+, R3
and produced exactly the same memory contents. And if I had written
you would have had no difficulty in saying that whatever register R5 pointed to was data.
PS. In the case of the PDP-11 there is no microcode to confuse you; it was all TTL logic chips -- quad NAND gates and so forth. Microcode is not at issue in this question, and if it exists it is stored in a totally distinct ROM inside the CPU that is not shown on the Von Neumann diagram. Back in 1980 I didn't encounter the concept until 1st year degree level.