Game Development Reference
In-Depth Information
Modern Macs and PCs generally have an x86 CPU; the XBox 360 has a Xenon
CPU; and the PS3 has a Cell CPU. All of these brains are slightly different but
share the same basic purpose—to run the programs programmers write. Pro-
grams are just lists of instructions. The instructions a particular CPU under-
stands are called machine code. Machine code for one CPU is unlikely to be
understood by a different type of CPU.
Compilers take human-readable source code, written in a language like C
þþ
or C, and compile it into machine code. For example, the PlayStation 3 C
þþ
compiler compiles source code into machine code that can run on the Cell CPU.
To run the same C þþ code on the Xbox 360 Xenon CPU, it must be compiled
again using the Xbox 360 C
complier. C# doesn't work like this. C# compiles
down to an assembly language called the common intermediate language or CIL.
CIL is then run on a virtual machine that generates the machine code for the
particular system. In the PlayStation 3 case that would mean to run C# on the
PlayStation, it would need a virtual machine that could take CIL code and out-
put machine code that the Cell CPU understands. This difference between lan-
guages using virtual machines and languages that compile directly to machine
code is shown in Figure 1.1.
þþ
C#s virtual machine, the CLR, has many advantages. The biggest advantage is
you only need write the code once and it will run on every CPU that supports the
Figure 1.1
Virtual machines and directly compiled code.
 
Search WWH ::




Custom Search