








One register can have four identities: RAX -> EAX -> AX -> AL. EAX is the lower byte of RAX, AX is the lower byte of EAX and AL is still the lowest 8 bytes.
[!NOTE]
Writing the lower 32 bits of a register would clear the higher 32 bits of it.(mov eax, 1would clear the higher 32 bits ofrax)
This is due to Intel’s backward compatability decision, making it impossible to change the names of the registers in their cpu. As a result, they could only extend the names of these registers while reserving the old ones.
RSP, representing stack pointer, points to the top of the current stack.
RBP, representing base pointer, is used for creating stack frame.(Not common for modern compilers)
RIP, representing instruction pointer, stores the address of the instruction to be executed next.
For a standard function call, 6 of its parameters goes into RDI, RSI, RDX, RCX, R8, R9 in order.
long f(long a, long b, long c, long d, long e, long f);, the corresponding register for each of the parameters is:a -> RDIb -> RSIc -> RDXd -> RCXe -> R8f -> R9Parameters after the sixth goes to the stack.
[!NOTE]
Floating point parameters have their own special registers.
RAX. If it’s too big to be stored inside one register, use RAX + RDX.Sometimes the execution of a funcion might overwrite the value in other registers set by the caller, though the values inside them might still be required for subsequent process. There are two conventions to resolve this problem.
In System V AMD64 ABI:
RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11 are caller-saved.RBX, RBP, R12, R13, R14, R15 are callee-saved.RSP is 16-byte aligned. However, the caller would push the return address on the stack when calling, so situation becomes %rsp % 16 == 8 when the callee arrives.Similiar to System V AMD64 ABI, puting the first four parameters to RCX, RDX, R8, R9 in order while the rest goes on to the stack.
Return values are usually stored in RAX. If it’s too big to be stored inside one register, use RAX + RDX.
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。