tags:

views:

266

answers:

7

I need some help to describe, in technical words, why a 64-bit application prompts a "Not a valid Win32 application" in Windows 32-bit on a 32-bit machine? Any MSDN reference is greatly appreciate it (I couldn't google a reliable source). I know it shouldn't run, but I have no good explanation for this.

A: 

Because they're fundamentally different. You wouldnt expect a Frenchman to understand Mandarin Chinese, so why would you expect a 32bit CPU to understand 64bit code?

Visage
These are technical terms?
amdfan
-1 for not using the requested technical terms
Russ
+14  A: 

A 32 bit OS runs in 32-bit protected mode. A 64 bit OS runs in long mode (i.e. 64-bit protected mode). 64 bit instructions (used by 64 bit programs) are only available when the CPU is in long mode; so you can't execute them in 32-bit protected mode, in which a 32 bit OS runs.

(The above statement applies to x86 architecture)

By the way, the reason for "Not a valid Win32 application" error message is that 64 bit executables are stored in PE32+ format while 32 bit executables are stored in PE32 format. PE32+ files are not valid executables for 32 bit Windows. It cannot understand that format.

Mehrdad Afshari
Does that statement also applies for 32-bit machines with 32-bit OS. I think I didn't state that when I first asked the question. Great answer (for me). :)
Shikiyo
From your question, I assumed x64 vs. x86. Definitely for the general answer, you should first exactly define a what you consider a 32/64 bit OS/program.
Mehrdad Afshari
Regarding your question about 32 bit OS: yes, a similar thing applies to running 32 bit applications in a 16 bit OS on x86 architecture.
Mehrdad Afshari
A: 

A 64-bit application requires a 64-bit CPU because it makes use of 64-bit instructions. And a 32-bit OS will put your CPU into 32-bit mode, which disables said instructions.

Why would you expect it to work? You're compiling your program to take advantage of features that don't exist on a 32-bit system.

jalf
I'm not expecting it to work. But I want to know, and explain "why".
Shikiyo
A: 

A 64-bit architecture is built to invoke hardware CPU instructions that aren't supported by a 32-bit CPU, which your CPU is emulating in order to run a 32-bit OS.

mquander
+8  A: 

To expand on what others have said in a more low-level and detailed way:

When a program is compiled, the instructions are written for a specific processor instruction set. What we see as "x = y + z" usually amounts to something along the lines of copying one value into a register, passing the add command with the memory location of the other value, etc.

Specific to this one question, a 64 bit application is expecting 64 bits of address space to work with. When you pass a command to the processor in a 32 bit system, it works on those 32 bits of data at once.

The point of it all? You can't address more than 4 gigabytes (232) of memory on a 32 bit system without creativity. Some tasks that would take multiple operations (say, dealing with simple math on numbers > 4 billion unsigned) can be done in a single operation. Bigger, faster, but requires breaking compatibility with older systems.

Autocracy
Thanks. Is there a way to mark two answers as correct? :)
Shikiyo
No, you have to pick one. Just consider me a really helpful supplement.
Autocracy
A: 

As it would be theorically possible to run in some kind of emulation mode for the instruction set, you get into troubles as soon as your application needs more memory than 32 bits can address.

Jem
A: 

The primary reason why 64-bit apps don't run on 32-bit OSes has to do with the registers being used in the underlying assembly (presuming IA-32 here) language. In 32-bit operating systems and programs, the CPU registers are capable of handle a maximum of 32 bits of data (DWORDS) in the registers. In 64-bit OSes, the registers must handle double the bits (64) and hence the QWORD data size in assembly. Compiling for x86 (32 bit) means the compiler is limiting the registers to handling 32 bits of data max. Compiling for x64 means the compiler is allowing the registers to handle up to 64 bits of data. Stepping down from QWORDs (64) to DWORDs (32) means you end up losing half the information stored in the registers. You're most likely getting the error because the underlying compiled machine code is trying to move more than 32 bits of data into a register which the 32-bit operating system can't handle since the maximum size of its registers are 32 bits.