简体   繁体   中英

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. I thought maybe a PC can have sets of registers, like 100 sets so every program can use a register without interrupting other programs. 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. 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.

But typically there are many more "processes" executing on a computer than there are "CPUs" to run them. 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. 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. (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.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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