Search code examples
visual-studioassemblycpu-registershardware

How come the CPU register values shown in Visual Studio Debugger don't change when I use another program (eg. Windows Calculator)


I'm learning assembly and some low-level computing stuff as a fun learning exercise. If VS Studio is showing me all my CPU's available registers in Debug > Registers, then how come when I do calculations on my computer, outside of the program I'm debugging in VS Studio, then the data shown in the registers doesn't change? Am I correct in assuming that registers are needed for any sort of calculation or operation done by the computer? Is VS Studio then only emulating my CPU's registers, and if not, then what's really going on?


Solution

  • You only see the registers for the current thread. When Windows changes context to another thread or process, or handles an interrupt, the current registers are saved, and the registers of the thread being switched to are restored. So the registers in your thread are not affected by running other programs (with exceptions of debugger type programs).


    In addition each process has it's on virtual address space. It is possible for a multi-process program to setup a shared physical memory space between the processes, but each process may be using a different virtual address for the same shared physical memory.


    Certain types of I/O controllers need to use physical memory for transfers. The virtual memory is locked, then translated into a list of physical addresses and lengths, corresponding to the 4096 byte pages used for virtual memory. Once the I/O is completed, the virtual memory is unlocked.

    https://learn.microsoft.com/en-us/windows-hardware/drivers/kernel/using-mdls