Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to understand volatile and non-volatile registers?

CPU registers can be classified as volatile and non-volatile by calling convension, how does does the meaning of word volatile implies the classification?

like image 620
Thomson Avatar asked Aug 14 '15 04:08

Thomson


People also ask

What is difference between volatile and non-volatile?

In a volatile memory, the process can both read and write. It means that the process would have direct access to the data and information within it. In a non-volatile memory, the process can only read. It means that the processor won't have direct access to the data and information within.

Are registers volatile or non-volatile?

They are volatile. So the second and forth options can be avoided.

What does it mean for a register to be volatile?

Volatile registers' content may change over a subroutine call. A non-volatile register is a type of register with contents that must be preserved over subroutine calls.

What do you understand by volatile memory?

Volatile memory is a type of memory that maintains its data only while the device is powered. If the power is interrupted for any reason, the data is lost.


2 Answers

From http://www.techopedia.com/definition/8591/non-volatile-register

Volatile registers' content may change over a subroutine call.

A non-volatile register is a type of register with contents that must be preserved over subroutine calls. Whenever the value of a nonvolatile register is changed by the routine, the old value has to be saved on the stack prior to changing the register and that value has to be restored before returning. A register is similar to a variable, except that there is a fixed number of registers. Every register is a unique location in the CPU in which a single value is saved. A register is the one and only place where mathematical functions, such as addition, multiplication, subtraction, etc., can be carried out. Registers often hold pointers that refer to the memory. Moving values between memory and registers is a common phenomenon.

like image 169
Achint Avatar answered Sep 22 '22 00:09

Achint


In other words volatile registers are caller saved registers, as opposed to callee saved. See https://docs.microsoft.com/en-us/cpp/build/x64-calling-convention?view=vs-2019#callercallee-saved-registers

like image 41
Jacek Tomaka Avatar answered Sep 24 '22 00:09

Jacek Tomaka