tags:

views:

390

answers:

4

The C language was used to write UNIX to achieve portability -- the same C language program compiled using different compilers produces different machine instructions. How come Windows OS is able to run on both Intel and AMD processors?

+2  A: 

As you suspect, the main stream Intel and AMD processors have the same instruction set.

Windows does not run on ARM or PowerPC chips, for example, because it is somewhat dependant on the underlying instruction set.

However, most of Windows is written in C++ (as far as I know), which should be portable to other architectures. Windows NT even ran on PowerPC and other architectures.

Magnus Hoff
And look at the Linux kernel for an operating system that runs on many architectures, even with different instruction sets. While the C code is portable, a lot of assembler has to be changed for each target.
Nick Meyer
The XBox 360 uses a modified Windows 2000 kernel, running on a PPC architecture. I am pretty sure that Windows is probably as portable as other operating systems out there, there is just not a strong incentive for Microsoft to actually provide other versions to the public (for, like, two customers, or so).
Joey
This answer is mostly true, except in the case of SIMD instruction sets. Things start diverging when you once you mix in 3DNow!, SSE1/2/3, etc. but this is also why x86 compilers generally don't support these instruction sets.
hythlodayr
In the mid nineties there was a version of Windows that ran on PowerPC, MIPS and Alpha processors as well as x86. They gradually went away between NT3.1 and Win2000. There may still be a version that runs on the Itanium. NT was written with portability in mind -- there's a nice book called Show Stopper about the development -- but I suspect that you couldn't just rebuild Win7 for, say, PPC now.
Stephen Darlington
+2  A: 

AMD are Intel compatible, otherwise they would never have gained a foothold in the market place.

They are effectively clone compatible.

Ryan

Ryan ONeill
A: 

AMD and Intel use the same instruction set.

When you install windows on an AMD processor or an Intel processor, it doesn't "compile" code on the machine.

I remember many people being confused on this subject back during college. They believe that a "setup" means that it is compiling code on your machine. It isn't. Most if not all Windows application outside of the free realms, are given to you by binary.

As for portability, that isn't neccessarily 100% true. While C is highly portable, in many cases writing for a specific OS or system will result in the code only being able to compile/executed on that box. For example, certain Unix machines handle files and directories differently so it might not be 100% portable.

Daniel
+7  A: 

AMD and Intel processors(*) have a large set of instructions in common, so it is possible for a compiler or assembler to write binary code which runs "the same" on both.

However, different processor families even from one manufacturer have their own sets of instructions, usually referred to as "extensions" or whatever. Ignoring the x87 co-processor, the first time I remember this being a marketing point was when everything suddenly went "with MMX(TM) technology". Binary code expected to run on any processor either needs to avoid extensions, or to detect the CPU type before using them.

Intel's Itanium 64-bit architecture was completely different from AMD's x86-64 architecture, so for a while their 64bit offerings were non-compatible (and Itanium was nothing like x86, whereas x86-64 extended the instruction set by adding 64bit instructions). Intel blinked first and adopted x86-64, although there are still a few differences: http://en.wikipedia.org/wiki/X86-64#Differences_between_AMD64_and_Intel_64

Windows probably uses the common x86 or x86-64 instruction set for almost all code. I wouldn't be surprised if various drivers and codecs are shipped in multiple versions, and the correct one selected once the CPU has been interrogated.

(*) Actually, Intel make or have made various kinds of processors, including ARM (Intel's ARM processors were called XScale, but I think they've sold that business). And AMD make other processors too. But we know which Intel/AMD processors you mean :-)

Steve Jessop
+1. Internally, AMD and Intel generally handle these common instructions quite differently: some instructions may execute much slower on one architecture than on the other.
Eric Bainville
Yes, good point. "Runs the same" comes with fine print.
Steve Jessop
Exactly right and such is the case with Linux. I'm a Linux kernel hacker and if you've ever recompiled your own Linux kernel, you'll notice you can target a plethora of CPU types and, of course, picking the wrong type and installing it amounts in a core dump or hung system. Nice write up by onebyone on this one!!!
Eric M
Intel also made the RISC i860 roughly simultaneously with the rise of the x86 series... obviously we know which one survived and which didn't :)
ephemient
Intel and AMD CPUs may have different behaviors even on common instructions. As a specific example, in real-mode, running EIP past 0xffffffff will generate an exception on Intel, but will silently wrap to 0x00000000 on AMD -- at least as far as my memory serves.
ephemient
That might qualify as a "well don't do that, then" situation. I'm not an assembly programmer, so I can't imagine why you might want to :-)
Steve Jessop