5

I have searched around to get the answers for these questions. but not much luck.

  1. Is it possible to run 32-bit code in a machine with 64-bit processor?

    The answer seems to be yes. but there is a debate on performance issues, since 32-bits are left unused on the processor.

  2. Now my question is vice-versa, Is it possible to run 64-bit code in a machine with 32-bit processor?

    from my little understanding, the answer is NO, because the code designed to run on 64-bit will be using 64-process registars but the 32-bit machine offers only 32.

On the otherhand, I found this link. According this, it is possible to compile 64-bit code on a 32-bit machine. But I am not clear on how this is done plus if compiling on a 32-bit machine will also guarantee execution on the same.

Thanks for helping out

Community
  • 1
  • 1
brain storm
  • 30,124
  • 69
  • 225
  • 393
  • 5
    "According this, it is possible to compile 64-bit code on a 32-bit machine." - yes, it's perfectly possible. It's called cross-compilation. But that has nothing to do with what code/executables a 32-bit machine can run. –  Jan 13 '14 at 19:28
  • 5
    Pedantically speaking: Both 32-bit and 64-bit machines are turing machines. So they can run emulate each other... – Mysticial Jan 13 '14 at 19:29
  • @Mysticial: what does that exactly mean? not clear what you mean here.. – brain storm Jan 13 '14 at 19:32
  • @user1988876 QEMU can emulate a 64-bit processor on a 32-bit host architecture - see http://stackoverflow.com/a/56332/2864740 (but few end-users are likely willing to run a parallel OS) – user2864740 Jan 13 '14 at 19:34

1 Answers1

12

Is it possible to run 32-bit code in a machine with 64-bit processor?

Yes. This is handled in Windows via WOW64, for example.

Now my question is vice-versa, Is it possible to run 64-bit code in a machine with 32-bit processor?

No. 64bit code would require a 64 bit instruction set, which won't be available on a 32 bit processor.

According this, it is possible to compile 64-bit code on a 32-bit machine.

You can compile code for other architectures, but not execute it. This lets you build code for different platforms than the currently executing platform, but executing it will not work.

Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
  • awesome! but then the last part would guarantee, `write once, run anywhere` rather than `write once, compile anywhere`. – brain storm Jan 13 '14 at 19:31
  • 1
    @user1988876 If you're thinking in terms of Java (or other "managed" style languages), you compile to an intermediate toolset, which then can execute "anywhere" (with the appropriate execution platform) - in Java case, you compile to java byte code, which can be run on any JVM (in theory). – Reed Copsey Jan 13 '14 at 19:32
  • @user1988876 I also didn't get into possible executing via emulators: http://en.wikipedia.org/wiki/Emulator I suspect this isn't what you were after, though. – Reed Copsey Jan 13 '14 at 19:33
  • 2
    lets say, I compile my code for 32-bit machines and 64-bit machines from my 32-bit computer. I can ship this compiled code to outside world. Those with 32-bit PC download 32-bit executable and others the 64-bit one. so here,`write Once, run anywhere` could be done..is something not correct with my understanding here? – brain storm Jan 13 '14 at 19:36
  • @user1988876 Yes, that could be possible (though shipping *untested* code would be unethical IMO) – Reed Copsey Jan 13 '14 at 19:39
  • Thanks. would it be correct to say `compilation is architecture independent`? – brain storm Jan 13 '14 at 19:40
  • @user1988876 Compilation *can be* architecture independent. It completely depends on the compiler. Compilation is just transforming data from one form to another, which could (in theory) happen on any platform/architecture/etc. – Reed Copsey Jan 13 '14 at 19:46