程序计数器寄存器 [英] Program Counter register

查看:131
本文介绍了程序计数器寄存器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我们不能为程序计数器寄存器创建命令列表,但是我们可以为Windows应用程序创建优先级列表?



I我在谈论CPU注册 - 程序计数器。



谷歌搜索告诉我,没有办法实现程序计数器寄存器。因为它是CPU工作。



但是我们可以用Windows应用程序来做到这一点。我们需要了解流程,交换/退出。这意味着我可以说:在该命令之前执行此命令。那没关系。



当CPU收到命令时,它会将此命令加载到程序计数器。在那之后,它就是那个命令。



这是矛盾的。它是下一个应用程序命令与下一个CPU命令 - 用于注册的区别吗?



你能告诉我更多吗?



谢谢!

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!

推荐答案

程序计数器(或PC)是一个硬件寄存器 - 它是CPU的一部分,你可以正常访问它完全来自高级语言 - 你可以从汇编程序,你只有CPU寄存器来玩,并通过这些寄存器进行大部分内存访问。



无论如何,您都可以将此命令或该命令加载到PC中 - 它保存一个存储器地址,该地址是下一个要执行的机器指令的位置(这与高位指令非常不同)可以用来编写Windows应用程序的级别语言。通常,高级指令会生成许多机器指令而不是一对一的映射。一些单行的C ++代码可以生成数百台机器说明!

在.NET语言中,它甚至更复杂,因为你用C#或VB编写的鳕鱼被转换成一种中间语言,它在第一次执行之前就被转换为本机机器指令 - 所以你真的,真的,不知道PC将会在哪里!



所以是的:下一个应用程序命令与下一个CPU命令 - 非常非常不同 - 注册
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"


你在这里混合一些东西。但首先回答你的问题:是的,下一个应用程序命令与下一个CPU命令 - 用于寄存器不同。这就像比较苹果和橘子。这两件事在两个不同的抽象层次上。



程序计数器是处理器中寄存器的通用术语,其中包含地址下一条要执行的指令。这来自 Von Neumann架构 [ ^ ]。它不包含下一个命令(意思是编程语言中的命令),甚至不包含下一条指令,而是它可以找到的位置。该寄存器在英特尔处理器中被称为指令指针(IP / EIP / RIP)[ ^ ]并且无法直接写入,只能通过跳转/更改分支指令。除非您正在构建自己的处理器或模拟器,否则不清楚实现程序计数器是什么意思。如果您想获得技术,那么现代处理器非常复杂,需要探索很多。英特尔处理器使用微体系结构 [ ^ ]具有多级管道,推测和无序执行等。在这种情况下,第一个和下一个术语变得非常相对。 />


在编程语言级别上,命令按写入顺序执行。编译器可以重新排序说明 [ ^ ]作为优化过程的一部分,但始终不会更改代码的语义。在多处理器系统上,还有一个复杂因素,即对存储器的读写顺序。 内存模型描述了这一点[ ^ ]。最后但并非最不重要的是,操作系统负责安排 [ ^ ]进程和线程,以便您的代码可以在执行过程中停止并放入等待列表。在上下文切换的情况下,下一个命令/指令来自不同的线程,甚至来自不同的进程/应用程序。某些应用程序可以获得更大的时间份额 - 这取决于进程/线程优先级。我想这就是你对windows应用程序的优先级列表的意思。
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.


这篇关于程序计数器寄存器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆