Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are rbp and rsp called general purpose registers?

According to Intel in x64 the following registers are called general purpose registers (RAX, RBX, RCX, RDX, RBP, RSI, RDI, RSP and R8-R15) https://software.intel.com/en-us/articles/introduction-to-x64-assembly.

In the following article, it's written that RBP and RSP are special purpose registers (RBP point to the base of the current stack frame and RSP point to the top of the current stack frame). https://www.recurse.com/blog/7-understanding-c-by-learning-assembly

Now I have two contradictory statements. The Intel statement should be the trusted one, but what is correct and why is RBP and RSP called general purpose at all ?

Thanks for any help.

like image 650
Dennis Avatar asked Apr 10 '16 12:04

Dennis


People also ask

What is RBP and RSP registers?

The first lines of the function main refers to rbp and rsp ; these are special purpose registers. rbp is the base pointer, which points to the base of the current stack frame, and rsp is the stack pointer, which points to the top of the current stack frame.

What do you mean by general purpose register?

General-purpose registers are used to store temporary data within the microprocessor. There are 8 general-purpose registers in the 8086 microprocessor. 1. AX: This is the accumulator. It is of 16 bits and is divided into two 8-bit registers AH and AL to also perform 8-bit instructions.

What are general purpose and special purpose registers?

Special purpose registers hold the status of a program. These registers are designated for a special purpose. Some of these registers are stack pointer, program counter etc. General purpose registers hold the temporary data while performing different operations. Some of these registers are accumulator, BX etc.

What are the general purpose registers in assembly language?

The four general purpose registers are the AX, BX, CX, and DX registers. AX - accumulator, and preferred for most operations. BX - base register, typically used to hold the address of a procedure or variable. CX - count register, typically used for looping.


1 Answers

General purpose means all of these registers might be used with any instructions doing computation with general purpose registers while, for example, you cannot do whatever you want with the instruction pointer (RIP) or the flags register (RFLAGS).

Some of these registers were envisioned to be used for specific use, and commonly are. The most critical ones are the RSP and RBP.

Should you need to use them for your own purpose, you should save their contents before storing something else inside, and restore them to their original value when done.

like image 127
jlliagre Avatar answered Oct 06 '22 00:10

jlliagre