Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Why can't we create a "command list" for the Program Counter register, but we can create a "priority list" for Windows application?

I'm talking about CPU register - Program Counter.

Google Search told me that there is no way to implement the Program Counter register. Because it's "CPU work".

But we can do that with Windows application. We need to know about "process", "swap in/out". That mean I can say: "Do this command before that command". That's Ok.

When CPU receives my command, it'll load "this command" to Program Counter. After that, it's "that command".

It's contradictory. Is it "next application command" difference from "next CPU command - for register"?

Can you tell me more?

Thanks!
Posted

The Program Counter (or PC) is a hardware register - it's a part of the CPU and you can;t normally access it at all from a high level language - you can from assembler, where you only have the CPU registers to play with and do most of your memory accesses via those registers.

You can;t load "this command" or "that command" into the PC anyway - it holds a memory address which is the location of the next machine instruction to be executed (which is a very different thing from an instruction in a high level language suach as one you might use for writing a Windows application. Typically, high level instructions will generate a number of machine instructions rather than a one - to - one mapping. Some single lines of C++ code can generate hundreds of machine instructions!
In .NET languages it's even more complex, because the cod you write in C# or VB is converted to an intermediate language which is converted to native machine instructions immediately before it is first executed - so you really, really, have no idea where the PC is going to be!

So yes: "next application command" is very, very different from "next CPU command - for register"
 
Share this answer
 
Comments
user8x86 2-Nov-14 11:46am    
Thank Mr. OriginalGriff. You always answer my question!
OriginalGriff 2-Nov-14 11:55am    
You're welcome!
You are mixing few thing up here. But to answer your question first: Yes, "next application command" is different from "next CPU command - for register". It's like comparing apples and oranges. These two things are on two different levels of abstraction.

Program counter is a general term for a register in processor which holds the address of the next instruction to be executed. This comes from Von Neumann architecture[^] of computers. It doesn't hold the next command (meaning a command in your programming language), not even the next instruction, but the location where it can be found. This register is called instruction pointer (IP/EIP/RIP) in Intel processors[^] and cannot be written to directly, it can only be changed via jump/branch instructions. It is not clear what do you mean by implementing program counter unless you are building your own processor or a simulator of one. If you wanna get technical there is lot to explore as modern processors are quite complicated. Intel processors use microarchitecture[^] with multistage pipeline, speculative and out-of-order execution etc. The terms first and next become very relative in this context.

On programming language level, the commands are executed in order in which they are written. Compilers can reorder instructions[^] as part of optimization process but always without changing the semantics of your code. On a multiprocessor systems there is one more complication namely the order of reads and writes to the memory. This is described by the memory model[^] for the given platform. Last but not least the operating system is responsible for scheduling[^] processes and threads so your code can be stopped in the middle of execution and put on wait list. In case of a context switch the next command/instruction comes from a different thread even from different process/application. Some application can get bigger share of time - this is governed by process/thread priority. I guess this is what you meant by "priority list" for windows applications.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900