VB6 beginners tutorial - Learn VB6

Advanced VB6 tutorial - Learn Advanced VB6

VB .NET - Learn Visual Basic .NET

Systems Analysis - System analysis and Design tutorial for Software Engineering

You are here: Visual Basic > Advanced VB6 tutorial > Chapter 20

Native Code

If you are familiar with other language compilers—such as Microsoft Visual C++, Borland Turbo Pascal, or any of the various assembly language compilers available for a given processor chip—you know that a language compiler turns a programmer’s source code into native machine code that is linked into an executable program file.

Before version 5 of VB, the Visual Basic compiler did not generate the machine code common to other compilers. Instead, it could only create something called pseudocode, commonly abbreviated to P-Code.

To understand how P-Code differs from machine code, let’s take a look at the difference between programs based on interpreted languages and programs based on compiled languages.

At some level, every computer program can be said to consist of nothing but the source code used to write it. Programmers write statements in a high-level language (such as Visual Basic, COBOL, or C++). If you assemble a series of these statements that collectively are supposed to do something useful, you have a computer program. Before the computer can do anything with a program, however, these high-level language statements must be translated into something the computer can understand: machine code.

Machine code instructions govern the most fundamental tasks performed by a CPU. For Intel chips, those basic operations include things such as data transfer, arithmetic, bit manipulation, string manipulation, control transfer, and flag control. The format of an instruction falls into two parts; One part identifies the operation code, while the other identifies the address in the computer’s memory at which the data to be used in the operation is stored.

Machine code varies with each processor, however. The Motorola chips used in Apple computers, for example, don’t respond to the same set of instructions used by the Intel chips found in computers that run Microsoft Windows. For a given program to run on a computer, it must be converted into the machine code appropriate for that computer. The code used by a particular processor chip is also known as its native machine code.

Until a program is translated from the language used by the programmer into native code, the computer can’t do anything with the program. The difference between an interpreted program and a compiled program is the point at which this translation occurs.

With a compiled program, the process of producing an executable file from your source code takes two basic steps. The first step is the compile step. If you choose to compile to native code, the compiler produces a series of intermediate files from your source code. These intermediate files are commonly called object files, and many compilers (including the VB compiler) give these intermediate files an extension of OBJ.

Even though they consist of machine code, the object files themselves can’t be used directly by your computer. Because your computer relies on an operating system (for example, Microsoft Windows 9x or Windows NT), another step—called the link step—is necessary to produce an EXE file. During the link step, the object files produced by the compiler are linked together with some startup code that tells your operating system where to load your program into memory. The result is written to disk in a form that your computer can use.


<< Previous | Contents | Next >>

Home | About Us | Privacy Policy | Contact Us

Copyright © | All Rights Reserved