
Originally Posted by
Brian Park
As stated by the others, the compiler translates between the "source" language (code), and the "object language (code)". Assemblers also do that. The specific difference between the 2 is the nature of the languages.
The source (input) language (structure/syntax) of the compiler is created/defined completely independently of the object language. For example, the C language has no relation to the internal structure of the computer it programs (such as the number of registers, or the memory buss format: Harvord architecture, Von-Nuemann architecture, etc.) So a language like C is a "universal" language, in that compilers can be had to enable running a given C program on any computer possessing sufficient memory capacity/speed for the task, and once written and debugged to run on one computer, can (at least in theory) be compiled on a different compiler to run on another computer without modification.
The assembly language is structured after the architecture of the processor it is to provide code for. The assembler "assembles" the source code to "machine code", the 1's and 0's that are loaded into the memory. Basically there is a one-to-one correspondence between each line of assembly and a single machine instruction. If a computer with a different structure is to be programmed, a different assembly language/assembler is needed. The advantage of assembly is the ability to optimize the performance of the machine (often by speed factors of 100, and smaller code by factors of 1000). Also, the timing of C-code is hard to control/predict, while assembly can code precise timing functions, but is more difficult to write. For example, on a free-form lens grinder, C running on a PC could calculate the curves, and assembly running on a microcontroller would control the actual cutting of the lens curve by the stepper/servo motors.
Assembly routines requiring only 2000 bytes can do some rather awesome things, in the day and age where programs are measured in megabytes.
Many programs are written as combinations of both; assembly for the intensive parts of the code, carefully hand-tuned for speed, and C for the less speed intensive/more difficult to write parts.
A third type of "code converter" is the interpreter. This does not strictly "convert" the code at all. Instead, the code is stored in the computer exactly as written, and an "interpreter" is running, processing each line of code in turn. So the source code is not really "running"; it is a data stream feeding the interpreter. The early Basics that ran on PC's (such as Quickbasic) were interpreters. Although,they run about 100 to 1000 times slower than assembly, they are more bugproof (the interpreter is running and checking the code for correctness continuously. If an infinite loop or a math overflow occurs, the interpreter flags it.) They are useful when you want to calculate something with a quickly whipped out program. Presently, they have fallen out of use because "the common person no longer programs". They resort to "apps" such as Matlab and spreadsheets for calculations. But Basic is handy when a calculation is required that does not fit an app or one is not willing to pay a fortune for an app for a simple calculation. An example is a converter to take some sort of a CAD file, and convert it into a form that will be accepted by a non-compatible machine, say to lay out a lens edging cam from an eyeglass frame. Put eyeglass frame on scanner face down. Scan to BMP file. import BMP into CAD program, and draw around the eyewires with CAD elements. Basic program digests the CAD file, and provides a G-code (standard milling machine driver file) to cut the cam on a milling machine. Perhaps the "patternless lens edger" died, and the new one is not compatible with the old expensive CAD software. So a Basic program patches the new and the old.
An emulator program makes the object code written for one computer run on another. An example is the "maim" code (you arcade fanatics probably know about this), which accepts the original object code for the video games, such as Packman, and allows them to run on the PC, verses the "old clunker" computers they originally run on. Each and every instruction cycle is perfectly replicated. The emulator, like the compiler, runs 10 to 100 times slower (on a given computer) than assembly, but are useful when an old system dies, there is a lot of investment in the software, and the newer computers are so much faster.
My main area of expertise is on the "small end" of the code spectrum (assembly and Basic).
Bookmarks