Page 46 - Introduction to Programming with Java: A Problem Solving Approach
P. 46
12 Chapter 1 Introduction to Computers and Programming
to worry about syntax details. After implementing a pseudocode solution, it’s relatively easy to convert the
pseudocode to source code.
1.5 Compiling Source Code into Object Code
After writing a program, you’ll want to have a computer perform the tasks specified by the program. Getting that to work is normally a two-step process: (1) Perform a compile command. (2) Perform a run command. When you perform a compile command, you tell the computer to translate the program’s source code to code that the computer can run. When you perform a run command, you tell the computer to run the trans- lated code and perform the tasks specified by the code. In this section, we describe the translation process.
The computer contains a special program called a compiler that’s in charge of the translation process. If you submit source code to a compiler, the compiler translates it to code that the computer can run. More
2
formally, the compiler compiles the source code and produces object code as the result. Object code is a
set of binary-format instructions that can be directly run by a computer to solve a problem. An object-code instruction is made up of all 0’s and 1’s because computers understand only 0’s and 1’s. Here’s an example of an object-code instruction:
0100001111101010
This particular object-code instruction is referred to as a 16-bit instruction because each of the 0’s and
1’s is called a bit, and there are 16 of them. Each object-code instruction is in charge of only a simple com-
puter task. For example, one object-code instruction might be in charge of copying a single number from
Apago PDF Enhancer
some place in main memory to some place in the CPU. There’s no need for general-purpose computer pro- grammers to understand the details of how object code works. That’s the computer’s job, not the program- mer’s job.
Programmers sometimes refer to object code as machine code. Object code is called machine code be- cause it’s written in binary and that’s what a computer “machine” understands.
1.6 Portability
In Section 1.2’s “Auxiliary Memory” subsection, we said that auxiliary memory is more portable than main memory because it can be moved from one computer to another fairly easily. In that context, portability referred to hardware. Portability can also refer to software. A piece of software is portable if it can be used on many different types of computers.
Portability Problem with Object Code
Object code is not very portable. As you now know, object code is comprised of binary-format instructions. Those binary-format instructions are intimately tied to a particular type of computer. If you have object code that was created on a type X computer, then that object code can run only on a type X computer. Like-
2 Most compilers produce object code, but not all. As you’ll see in the next section, Java compilers produce an intermediate form of instructions. At a later time, that intermediate form of instructions is translated into object code.