The difference between Linux x86 and x64

0x01: different register allocation

 

(1) 16 64-bit registers, 32-bit only 8. 32 but has the first eight different nomenclature, namely E _, 8 and 64 prior to use instead of E r, i.e. r _. the beginning of the e register name may be directly applied to still lower 32 bits of the corresponding registers, and the remaining register names are from r8 - r15, which is lower respectively d, w, b specified length;
(2) the use of 32-bit stack frame passed as a parameter save location, and the use of 64-bit registers, respectively rdi, rsi, rdx, rcx, r8, r9 1-6 as a parameter, as a return value RAX;
(3) the stack frame 64 is not pointer 32 used as the stack frame pointer ebp, 64 cancel this setting, RBP used as general registers;
(4) 64 to support some form of a PC-relative addressing, while 32-bit only when it is jmp We will use this type of addressing;

0x02 :( new) assembly instructions are different

 

mov, push, pop extends movq mov series and used to operate the popq pushq and quad word.

supplement:

(1) movabsq than 32-bit extension, pure new instructions. For a 64-bit literal direct deposit into a 64-bit register. Because movq only the 32-bit value stored, it added such a directive

(2) 64-bit assembly code might add that rep before ret, rep here has no real meaning, but for reasons of AMD processors, avoid places reached by direct jmp is ret, this will make the processor run more faster

0x03: different function calls

(1) x_64 parameters are passed in registers (supra);
return address callq stored in a stack in the 8;
(2) no longer has many functions stack frame, not only all the local variables in the register will space allocated on the stack;
(3) function to obtain up to 128 bytes of stack space. Such function can be changed without the stack pointer store information on the stack (that is, the space may be advanced by 128 bytes rsp below, this space is called the red zone, the x86-64, the time available );
(4) no longer have a frame pointer, stack current stack pointer and the position related. Most of the functions at the beginning of the call to allocate all the required stack space, then keep the stack pointer does not change;
(5) a number of registers is designed to be the caller - storage registers, these must be changed when they store their values and then restore them.

0x04: different parameters passed

(1) six registers used to pass parameters (see above);

(2) the rest of the way as previously register transfer (but associated with the rsp, not as a stack frame pointer EBP, and the start of the seven parameters from rsp, rsp + 8 starts eighth, and so on);

(3) When calling, RSP 8 is moved downward (return address is stored), no effect parameter register, and the first seven parameters it is now after the seventh rsp + 8 starts, rsp + 16 begin eighth and so on;


0x05: different stack frame

In many cases no longer require a frame, as in no other function calls, and register enough to store parameters, then you only need to store the return address.
Circumstances require stack frames:

Too much (1) the local variables, registers not;
(2) some of the local variable is an array or structure;
(3) using the function address to calculate the address-operator of a local variable;
(4) a number of functions must be transmitted with a stack Further parameters to a function;
(5) function by the need to save some storage state callee register (so as to recover);

But now the stack frame is often fixed size, it is set at the beginning of a function call, the duration of the call, the stack pointer remains unchanged, so on which can be coupled with the corresponding offset value operation, so there is no need EBP as the stack frame pointer. Although many times we think that there is no "stack frame", but each function call must have a return address is pushed onto the stack, we can also think that this address is a "stack frame" as it also saves the state of the caller.

Original link: https: //blog.csdn.net/qq_29343201/article/details/51278798

Guess you like

Origin www.cnblogs.com/ncu-flyingfox/p/11291086.html