snippetMinor
Why can't a compiler create universal N-bit code (e.g. 32-bit, 64-bit, etc.)
Viewed 0 times
whycanbitcreateuniversalcompilercodeetc
Problem
It is my understanding from what I have read that you need to compile separate executables for 32 bit and 64 bit machines. So if I compile a C program for example I need to compile 2 different binaries for 32-bit and 64-bit machines.
However, it seems like intuitively a compiler should just be able to compile down to instructions that say "allocate N bits of space" and similar for other related instructions rather than "give me 32-bits of space" or "give me 64 bits of space"?
Why is this not the case (looking for some intuition at a high level)?
However, it seems like intuitively a compiler should just be able to compile down to instructions that say "allocate N bits of space" and similar for other related instructions rather than "give me 32-bits of space" or "give me 64 bits of space"?
Why is this not the case (looking for some intuition at a high level)?
Solution
The instruction set for a 32-bit processor is different from the instruction set for a 64-bit processor. The 64-bit instructions can't be executed on a 32-bit processor. So, the program really does need to be compiled to something different: if you take a program compiled for a 64-bit processor, and try to run it on a 32-bit processor, the processor won't run it, because it doesn't understand the new 64-bit instructions.
Context
StackExchange Computer Science Q#91924, answer score: 7
Revisions (0)
No revisions yet.