15.04.2018 Views

programming-for-dummies

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Figuring Out Programming 21<br />

Converting source code with<br />

an assembler or compiler<br />

An editor lets you type and save program commands (source code) in a file.<br />

Unless you’ve written a program completely in machine language, your source<br />

code might as well have been written in Swahili because processors don’t<br />

understand any language other than machine language.<br />

So to convert your source code into machine language commands, you have<br />

to use an assembler (if you wrote your program commands in assembly language)<br />

or a compiler (if you wrote your program commands in the C language<br />

or a high-level language, like BASIC).<br />

Book I<br />

Chapter 1<br />

Getting Started<br />

Programming a<br />

Computer<br />

After converting your source code into equivalent machine language commands,<br />

an assembler or compiler saves these machine language commands<br />

in a separate file, often called an executable file, or just an EXE file. When you<br />

buy a program, such as a video game or an antivirus program, you’re really<br />

buying an executable file. Without an assembler or a compiler, you can’t<br />

create your program.<br />

Compilers translate source code into machine language, which is the native<br />

language of a specific processor. But what if you want your program to run<br />

on different processors? To do this, you have to compile your program into<br />

machine language <strong>for</strong> each different processor. You wind up with one executable<br />

file <strong>for</strong> each processor, such as an executable file <strong>for</strong> an Intel Core<br />

Duo 2 processor and a separate executable file <strong>for</strong> a PowerPC processor.<br />

Many Macintosh programs advertise themselves as a Universal Binary — the<br />

program actually consists of two executable files smashed into a single file:<br />

✦ One executable file contains machine language code <strong>for</strong> the PowerPC<br />

processor (used in older Macintosh computers).<br />

✦ The second executable file contains machine language code <strong>for</strong> the Intel<br />

processor (used in new Macintosh computers).<br />

Most compilers work only on one specific operating system and processor.<br />

So a Windows compiler can only create programs that run under the<br />

Windows operating system. Likewise, a Linux compiler can only create programs<br />

that run under the Linux operating system.<br />

If you write a program that runs under Windows, you can re-compile it to run<br />

under Linux. Un<strong>for</strong>tunately, you may have to modify your program slightly<br />

(or a lot) to make it run under Linux.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!