Understanding cpu registers

I'm very beginner in assembly language and trying to understand how these all work. My question may seem very dumb but anyway, it's not quite clear to me.

Consider the following simple program:

section .text global _start _start: mov eax, [text] mov [val], eax mov ecx, val mov eax, 4 mov edx, 7 mov ebx, 1 int 0x80 mov eax, 1 int 0x80 segment .bss val resb 2 segment .data text db "Th" len equ $- text

Here we update values in registers and print it out with system call. But I'm wondering what if OS (I'm using Ubuntu 16.04) schedules some process on the same core. It means the process updates CPU registers in its own way. How does OS linux handle it? I mean each process has its own consistent registers value and not affected by some another process?


When the kernel is running, it keeps somewhere (in kernel memory) a backup of the register contents of the current task (on many processors, there might be some machine instruction or hardware mechanism to help that).

When the kernel runs the scheduler and it choose to run some task, that register state is restored. Notice that Linux has preemptive scheduling. Read about context switching and interrupts and CPU modes. Try several times cat /proc/interrupts in a terminal. See proc(5) for more about /proc/. Read more about x86-64.

When that task asks (e.g. via some system call) to run, the kernel starts by backing up the register contents.

Read Operating Systems : Three Easy Pieces (freely downloadable book).

Each process has, from the point of view of user-space code, its register content, its set of file descriptors, its virtual address space etc... (and the kernel, including its scheduler, is managing all that). For multi-threaded processes, every thread has its register content (but they share some state - notably virtual address space, file descriptors, etc... - with other threads in the same process).


Upon switching between processes on the same core, the OS saves the registers of the previous process. That is called context-switching (you may search for more details). Then the OS restores the registers of the next process.


  • “Screen scrape” with Jsoup with element who has ID
  • React Native debug with Visual Studio Code not working
  • Load testing a Java/Mysql application, where to begin?
  • How to build CUDA JIT caches for all available kernels in TensorFlow programmatically?
  • Why is it valid to define a type as pointer to an undefined struct in C?
  • Why doesn't setTimeout(.., 0) execute immediately?
  • How to make curl available in Docker image based java:8-jdk-alpine and keep the image clean?
  • query to return a single row with the multiple items in separate columns within the row
  • CUDA Debugging - VS on windows workstation, GPUs on Linux server?
  • What is ./.local/share/Trash (Unix) [closed]
  • Vigenere cipher not working
  • What is this strange character in chrome's resource css viewer?
  • How to repeat sections of a SQL query across UNIONs? (DRY in SQL)
  • Building Qt project for C++11 standard
  • Magento site down due to mysql error General error: 1030 Got error -1 from storage engine
  • Python pickle not one-to-one: different pickles give same object
  • Angular2 component view does not update on value change via method
  • Object and struct member access and address offset calculation
  • CakePHP ACL tutorial initDB function warnings
  • How can I sort a a table with VBA with given text condition?
  • Admob requires api-13 or later can I not deploy on old API-8 phones?
  • Obtain ObjectIdHex value from mgo query
  • Does CUDA 5 support STL or THRUST inside the device code?
  • Join two tables and save into third-sql
  • When should I choose bucket sort over other sorting algorithms?
  • Convert array of 8 bytes to signed long in C++
  • How do you troubleshoot character encoding problems?
  • Apache 2.4 - remove | delete | uninstall
  • Invalid access key error using credentials redeemed from an amazon open id token
  • Cannot Parse HTML Data Using Android / JSOUP
  • SetUp method failed while running tests from teamcity
  • retrieve vertices with no linked edge in arangodb
  • using conditional logic : check if record exists; if it does, update it, if not, create it
  • Python: how to group similar lists together in a list of lists?
  • How do you join a server to an Active Directory (domain)?
  • How do I configure my settings file to work with unit tests?
  • Add sale price programmatically to product variations
  • Recursive/Hierarchical Query Using Postgres
  • Running Map reduces the dimensions of the matrices
  • How do I use LINQ to get all the Items that have a particular SubItem?