简体   繁体   中英

x86 and x64 share instruction set?

I don't know how 32bit application can run on a 64bit OS.

My understanding is 32bit/64bit refers to register size. An instruction set should be different as they have different sizes of register.

But I know there is x86-64 instruction set that is the 64bit version of the x86 instruction set.

  1. Is the reason we can run 32bit application on 64bit OS is because of the x86-64?

  2. If so, why are 32bit applications sometimes not compatible in 64bit windows? Why do we need WOW64? (Sometimes we are asked to choose which version to install.)

  3. Does x64 instruction set have any other instruction set except x86-64? Some people told me x64 is just to extend memory range and the instruction set they have is identical. Is this correct?

Is the reason we can run 32bit application on 64bit OS is because of the x86-64?

Yes for the most part. But let me briefly explain that 32bit/64bit does not necessarily actually refer to register size because the question would be which register (type) are you talking about? More accurately, the 32bit/64bit refer to the width of the address bus (ie how much memory can be addressed) or in other words the size of a pointer in C. Then, in turn the 32/64bit would (indirectly) refer to the word size aka the size of the basic 'integer' type of the machine. Anyway, the 32bit/64bit has to do more with addressable memory but is also related to word size (sizeof(int)) and in turn register size. So, back to the question. Alot of 32Bit binaries can still run on 64bit systems. Yes, because the "new" x86-64 only extends the original x86 ISA (with more instructions of course). Therefore, your old 32bit binary (which consists of x86 instructions) may still be runnable in the new system.

If so, why are 32bit applications sometimes not compatible in 64bit windows? Why do we need WOW64? (Sometimes we are asked to choose which version to install.)

Yes, there are a number of cases where old x86 32bit binary/application won't be runnable in a new 64bit system. For example, your binary may contain one or more instructions that (for some reason) are no longer supported (see this for examples). Or, If your binary/application specifically requires the use of a 32bit library that does not exist in your new system. In that case, your system will complain that you can't run this 32bit application.

Does x64 instruction set have any other instruction set except x86-64? Some people told me x64 is just to extend memory range and the instruction set they have is identical. Is this correct?

First, the Intel64, AMD64, x86-64, x64 all pretty much (more or less) refer to the same thing! Yes, the x86-64 instruction set is HUGE and receives extensions on a regular basis (think MMX, SSE, AVX....etc). Each extension is a like a mini instruction set. Look up x86 instruction set on Wikipedia you should get a ton of info.

x86 processors have multiple modes that support different variants of the basic x86 instruction set. They all support 16-bit "real mode" that implements the original 8086 segmented memory model that could only address 1MB. IIRC, they can also support the 286 addressing mode that's a variant of the segmented memory model. They support 386 protected mode, which extends the registers to 32 bits. Up to this point, they basically implement the same instruction set (ISA), but with some additional instruction prefixes and the ability to change default interpretation of instruction word sizes (arithmetic and memory instructions can default to either 16 or 32 bit, and then a prefix will select the non-default meaning). This is called "legacy mode."

The 64-bit extension (x86-64 or x64) isn't fully backward compatible. A number of single-byte instruction opcodes were reassigned to represent the new "REX" prefix that allows wider (64-bit) registers to be specified and a larger number of registers to be specified. To use this instruction set, the processor runs in yet another mode called "long mode."

Now, when you have a 64-bit operating system kernel running in 64-bit mode, and the OS context switches to a user process, it can change modes at the same time. So you can stay in 64-bit mode to run a 64-bit process, or you can switch to a legacy 32-bit mode to run a 32-bit process. When the 32-bit process makes an operating system call, the CPU automatically switches back to 64-bit mode to run kernel code The 64-bit kernel has to be specifically designed to take advantage of this mode switching capability.

Check out https://en.wikipedia.org/wiki/X86-64#Operating_modes for more details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM