Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What registers are preserved through a linux x86-64 function call

I believe I understand how the linux x86-64 ABI uses registers and stack to pass parameters to a function (cf. previous ABI discussion). What I'm confused about is if/what registers are expected to be preserved across a function call. That is, what registers are guarenteed not to get clobbered?

like image 999
boneheadgeek Avatar asked Aug 02 '13 19:08

boneheadgeek


People also ask

What is preserved across a call in registers?

“Preserved across procedure calls” means that the value stored in the register will not be changed by a pro- cedure. It is safe to assume that the value in the register after the procedure call is the same as the value in the register before the call.

How many registers may be used to pass function parameters in x86 64 and what are they?

On x86-64 Linux, the first six function arguments are passed in registers %rdi , %rsi , %rdx , %rcx , %r8 , and %r9 , respectively. The seventh and subsequent arguments are passed on the stack, about which more below. The return value is passed in register %rax .

What are x86 registers?

The main tools to write programs in x86 assembly are the processor registers. The registers are like variables built in the processor. Using registers instead of memory to store values makes the process faster and cleaner.


1 Answers

Here's the complete table of registers and their use from the documentation [PDF Link]:

table from docs

r12, r13, r14, r15, rbx, rsp, rbp are the callee-saved registers - they have a "Yes" in the "Preserved across function calls" column.

like image 123
Carl Norum Avatar answered Sep 22 '22 04:09

Carl Norum