写入CPU寄存器实际上是如何工作的?
当写入寄存器时,例如 mov ax, 1
,它会覆盖之前可能拥有的值。
现在我想知道的是,我可以将多大的数字/字符串输入寄存器,并且另一个应用程序可以覆盖我的应用程序的寄存器值吗?我的意思是,寄存器是在进程之间共享的还是它们接收自己的沙箱/虚拟寄存器?
我对 Intel x86(-64) Core CPU 和 Windows 感兴趣。
When writing to a register, say, like mov ax, 1
, it overwrites the value it may have had earlier.
Now what I wonder is that how big figures/strings can I feed into a register, and that can another application overwrite my app's register values? I mean, are the registers shared among processes or do they receive their own sandboxed/virtual registers?
I am interesting in Intel x86(-64) Core CPUs and Windows.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
单个核心上一次仅调度一个线程。核心是寄存器。
当新的线程被调度时,首先保存寄存器,然后恢复该线程之前保存的寄存器。这包括程序计数器寄存器,它指向下一条要执行的指令。
寄存器(来自内存):
AX、BX、CX、DX 为 16 位,分为字节(AH、AL、BH、BL)
SI、DI、SP 和 BP 也是 16 位
EAX、EBX、ECX 等是 32 位
我不确定它们在 64 位系统上的名称。我想我看到了 RAX,但我不确定。
还有专用寄存器、浮点寄存器等。
Only one thread is scheduled at a time on a single core. The core is what has the registers.
When a new thread is scheduled, the registers are first saved, and the previously-saved registers of the thread are restored. This includes the Program Counter register, which points to the next instruction to execute.
Registers (from memory):
AX, BX, CX, DX are 16 bits, broken into bytes (AH, AL, BH, BL)
SI, DI, SP and BP are also 16 bits
EAX, EBX, ECX etc. are 32 bits
I'm not sure what they're called on a 64-bit system. I think I saw RAX, but I'm not sure.
There are also special-purpose registers, floating-point registers, etc.
1) 寄存器的大小取决于(以明确定义的方式)您为它们使用的名称。例如,
eax
为 32 位宽,ax
为 16 位宽,ah
/al
为 8 位宽。如果您使用的是 64 位系统,则rax
是 64 位宽。这些寄存器大小的确切限制在某种程度上取决于您如何解释这些值(特别是您是否将它们视为有符号或无符号)。不过,规模才是最重要的。
2)操作系统内核将在其他进程或内核运行时保存您的进程的寄存器。当您不运行时,寄存器确实会采用其他值,但这都是透明的——当您的进程正在运行时,寄存器不会在您的控制下发生变化。
1) The size of registers depends (in well-defined ways) on what names you're using for them. For instance,
eax
is 32 bits wide,ax
is 16 bits, andah
/al
are 8 bits. If you're on a 64-bit system,rax
is 64 bits wide.The exact limits of these register sizes will depend somewhat on how you're interpreting the values (in particular, whether you're treating them as signed or unsigned). The size is what fundamentally matters, though.
2) The operating system kernel will save your process's registers while other processes, or the kernel, are running. The registers do take on other values while you're not running, but it's all transparent -- while your process is running, registers won't change out from under you.