CPU 如何使用有限数量的寄存器一次运行多个应用程序?

How does CPUs runs Multiple Applications at a Time with a limited number of Registers?

好吧,这让我很困惑,每个关于汇编的教程都说 CPU 中内置的寄存器数量较少,那么如果我创建一个使用寄存器进行计算的程序,如下所示:

global _start 

section .text

_start:

reStrt:  ; Label, Restart...

MOV ah, 0 ; Initialise ah to 0

INC ah ; ah++ [OR] ah=1

JMP reStrt ; Unconditional jump to label "reStrt"

组装和链接此代码后,Subsystem:CONSOLE,我将启动它,然后将看到永不退出的程序。

要关闭它,我们必须按控制台 window 的 [X] 按钮,同时在该程序 运行 并使用寄存器 ah 增加 1 和减少 1,我再次启动该应用程序,现在同一程序 运行 同时 运行 2 次。

但这怎么可能呢?如果 AH 寄存器是 CPU 中的一个,那么两个程序如何共享该寄存器但不与另一个程序共享一个值? B'因为我什至没有创建一个变量(标签)来将值存储在内存(RAM)中。另外,如果有数百个寄存器,但一个应用程序被限制为每个寄存器使用一个副本,那么我怎么能说我的计算机可以处理多少进程?

context switches (in particular, when running some other process), the operating system kernel is saving the process state (notably inside its scheduler for preemptive multi-tasking), notably the registers, somewhere in memory

通过在内存中保存至少一些寄存器,硬件能够经常处理 interrupts

如果你用过Linux or some other free software operating system, you'll be able to study its source code and find all these details. See e.g. the Linux Assembly HowTo

请阅读更多有关 operating systems and computer architecture (including instruction set 体系结构的信息)。去图书馆,你会发现很多关于这些主题的书。