简体   繁体   English

2个汇编程序如何使用相同的寄存器

[英]how can 2 assembly programs use the same register

I am learning assembly 8086 and I understand that assembly programs often use registers, how can it be possible that 2 assembly programs that runs on the same time can use the same register without interrupt each other. 我正在学习assembly 8086并且我了解assembly程序经常使用寄存器,那么在同一时间运行的两个assembly程序如何可以使用同一寄存器而不会相互中断。 I thought maybe a PC can have sets of registers, like 100 sets so every program can use a register without interrupting other programs. 我以为一台PC可以有几套寄存器,例如100套,所以每个程序都可以使用一个寄存器而不会中断其他程序。 Well anyway this is just a guess. 好吧,这只是一个猜测。

If the CPU can run more than one thread of execution at a time, then it does have a separate set of registers for each simultaneous thread that it can support. 如果CPU一次可以运行一个以上的执行线程,那么对于每个它可以支持的并发线程,它确实有一组单独的寄存器。 For historical reasons you will often see this described as the computer having more than one CPU , even though nowadays these "CPUs" are all usually on the same physical chip and much more tightly coupled than that would suggest. 出于历史原因,您经常会看到这被描述为具有多个CPU的计算机,尽管如今这些“ CPU”通常都位于同一物理芯片上,并且耦合度比建议的紧密得多。

But typically there are many more "processes" executing on a computer than there are "CPUs" to run them. 但是通常在计算机上执行的“进程”要比运行它们的“ CPU”多得多。 Every time the operating system takes the CPU away from one program and gives it to another one, it saves all the registers for the first program in memory, and restores all the registers for the second program. 每次操作系统将CPU从一个程序中移出并交给另一个程序时,它将第一个程序的所有寄存器保存在内存中,并恢复第二个程序的所有寄存器。 This is called a context switch . 这称为上下文切换

Some CPUs have attempted to accelerate context switching with extra sets of registers, but this turns out not to be as helpful as you'd think and is therefore not very common. 一些CPU尝试使用额外的寄存器集来加速上下文切换,但是事实证明这并没有您想的那么有用,因此并不常见。 (An extra set or partial set of registers dedicated for use by interrupt handlers, however, is quite common. It's also common for the CPU to have a bunch of invisible extra registers used for out-of-order execution , but they're invisible.) (但是,专门供中断处理程序使用的寄存器的额外集或部分集是很常见的。CPU具有一堆不可见的额外寄存器用于乱序执行也是很常见的,但它们是不可见的)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM