Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the difference between x64 and x86 in linux

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly shows you "what are the differences between x64 and x86 in linux". The content is simple and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "what are the differences between x64 and x86 in linux".

Differences: 1, register allocation is different, x64 has 16 registers, x86 has only 8 registers; 2, assembly instructions are different; 3, function calls are different; 4, parameter transfer is different; 5, stack frame is different, x64 has no stack frame pointer, and x86 uses ebp as stack frame pointer; 6, the operation speed of x64 is higher than x86.

The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.

Differences between Linux x86 (32-bit) and x64 (64-bit)

0x01: different register allocation

(1) there are 16 registers for 64 bits and only 8 registers for 32 bits. But the first eight of the 32 bits have different names, e _, and the first eight of the 64 bits use r instead of e, that is, r _. The name of the register starting with e can still be applied directly to the lower 32 bits of the corresponding register, while the remaining register names are from R8 to R15, with the length specified by d, w, b, respectively.

(2) 32-bit uses stack frame as the storage location of passed parameters, while 64-bit uses registers, using rdi,rsi,rdx,rcx,r8,r9 as the 1st-6th parameter and rax as the return value.

(3) 64 bit has no stack frame pointer, 32 bit uses ebp as stack frame pointer, 64 bit cancels this setting, and rbp is used as a general register.

(4) 64-bit supports some forms of PC-related addressing, while 32-bit addressing is only used in jmp.

0x02: (added) differences in assembly instructions

Mov, push, and pop extend the mov and pushq of the movq series, as well as popq to operate quad word.

Add:

(1) movabsq is not a 32-bit extension, but a purely new instruction. Used to store a 64-bit literal value directly into a 64-bit register. Because movq can only store 32-bit values, such an instruction has been added

(2) the 64-bit assembly code may add a rep before the ret. The rep here has no practical significance, just for the reason of the AMD processor, to avoid that the place where the jmp arrives is directly ret, which will make the processor run faster.

0x03: differences in function calls

(1) the parameters of xroom64 are passed through the register (see above)

Callq stores an 8-bit return address on the stack

(2) many functions no longer have stack frames, and only those that cannot put all local variables in the register will allocate space on the stack.

(3) the function can get up to 128 bytes of space on the stack. This allows the function to store information on the stack without changing the stack pointer (that is, it can use 128byte space below rsp in advance, which is called red zone, which is available all the time in x86-64).

(4) there is no stack frame pointer, and now the position of the stack is related to the stack pointer. Most functions allocate all the required stack space at the beginning of the call, and then keep the stack pointer unchanged

(5) some registers are designed as caller-stored registers, which must store them when their values need to be changed and restore them later.

0x04: differences in parameter passing

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

(2) the remaining registers are passed as before (only related to rsp, ebp is no longer used as a stack frame pointer, and the seventh parameter starts with rsp, the eighth from rsp+8, and so on)

(3) during the call, the rsp moves down 8 bits (storing the return address), and the register parameter has no effect. The seventh and later parameters are now the seventh starting from rsp+8, the eighth starting from rsp+16, and so on.

0x05: different stack frames

In many cases, stack frames are no longer needed, for example, when no other functions are called and the registers are sufficient to store parameters, then you only need to store the return address.

Situations where stack frames are required:

(1) there are too many local variables and not enough registers

(2) some local variables are arrays or structures.

(3) the function uses the address operator to calculate the address of a local variable.

(4) the function must pass some parameters to another function with the stack.

(5) the function needs to save the state of some registers stored by the callee (to facilitate recovery).

But now the stack frame is often of a fixed size, which is set at the beginning of the function call, and the top pointer of the stack remains unchanged throughout the call, so that the corresponding value can be manipulated by adding an offset to it, so EBP no longer needs to be used as a stack frame pointer. Although many times we think that there is no "stack frame", every function call must have a return address on the stack, we can also think that this address is a "stack frame", because it also saves the state of the caller.

0x06: operation speed is different

The data width of 64-bit cpu is 64-bit, and the 64-bit instruction set can run 64-bit data instructions, which means that the processor can extract 64-bit data at a time, twice as much as 32-bit, and theoretically double the performance.

These are all the contents of this article entitled "what are the differences between x64 and x86 in linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report