Command counter?

If I understand this correctly, the program counter points to the address of the executable command, and in most cases you add four to the program counter to go to the next instruction address. But say you have a program counter pointing to a word (like word 15) in your memory and you want to go to the next instruction, do you suppose adding 4 directly to 15 to get the next instruction? Any explanation would be appreciated.

+5
source share
2 answers

This thing is called an instruction pointer. As soon as the processor decodes the current instruction, it finds how many bytes it takes and knows how much to add to the current value of the instruction pointer in order to go to the next command, so that when the current command is executed, the processor knows what to do next.

So, for example, the processor starts with a pointer to a pointer that stores the value 15, as in your example - it looks like what happens with this address, it happens that the instruction takes 5 bytes, no problem - it adds 5 to the current value, and this gives 20, and so the instruction pointer now stores the value 20, and then the processor executes the current instruction.

+6
source

- CPU , . , (, , ..). , , - . : , , " ".

+2

All Articles