1

In Assembly, we commonly use instructions like mov and ld and others to load values into registers. However, why does it just work? For example, if a program is writing a value into the eax register, and another program reads from that, why doesn't it read the value the other program wrote? Does the CPU or OS or something like that provide a set of registers for each running program maybe?

  • See also [time slice](https://en.wikipedia.org/wiki/Preemption_(computing)#Time_slice). Handling out time slices of the CPU is an operating system feature that virtualizes the compute power of the CPU. – Erik Eidt Feb 22 '21 at 23:23

1 Answers1

2

Does the CPU or OS or something like that provide a set of registers for each running program maybe?

Yes. Each process, or each thread, or each task, has its own register set. When the OS preempts a task it saves all registers in a task-specific memory area. Then to resume the same task or another task, the target task's register values are restored from that task's memory area.

ecm
  • 2,583
  • 4
  • 21
  • 29