Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are assemblers, compilers, and interpreters

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "what is the assembler, compiler and interpreter". In the daily operation, I believe that many people have doubts about what the assembler, compiler and interpreter are. The editor consulted all kinds of materials and sorted out the simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "what is an assembler, compiler and interpreter"! Next, please follow the editor to study!

What is a program?

First of all, let's take a look at some background. Computers can't do anything by themselves, and any of their behavior needs to be guided by a program. You can think of the program as a very accurate recipe that reads an input and then generates the corresponding output. The steps in the recipe consist of instructions to manipulate the data. It sounds a little complicated, but you may know what the following sentence means:

1 + 2 = 3

The plus sign is "instruction", and the numbers 1 and 2 are data. The mathematical equal sign means that the parts on both sides of the equation are "equivalent", but in most programming languages using the equal sign for variables means "assignment". If the computer executes the above statement, it will store the result of the addition (that is, "3") somewhere in memory.

Computers know how to use numbers for mathematical operations and how to move data in memory structures. Instead of expanding memory here, you just need to know that memory is generally divided into two categories: "fast / small space" and "slow / large space". The CPU register reads and writes very fast, but the space is so small that it is equivalent to a shorthand note. The main memory usually has a lot of space, but the read and write speed is much lower than the register. While the program is running, CPU constantly moves the data it needs from the main memory to the register, and then puts the results back to the main memory.

Assembler

At that time, computers were very expensive, but manpower was cheaper. Programmers spend a lot of time translating handwritten mathematical expressions into instructions that the computer can execute. The original computers had a very bad user interface, and some even had only a toggle switch on the front panel. These switches represent "zeros" and "ones" in a memory "unit". Programmers need to configure a memory unit, select a storage location, and then submit the unit to memory. This is a time-consuming and error-prone process.

Programmers Betty Jean Jennings (left) and Fran Bilas (right) operate the main control panel of ENIAC

Later, an electrical engineer thought his time was precious, so he wrote a program that could convert the input of a "recipe" that people could read into a version that could be read by a computer. This was the original "assembler", which caused a lot of controversy at that time. The owners of these expensive machines do not want to waste computing resources on tasks that people can already do (though slow and error-prone). However, with the passage of time, people gradually find that using assemblers is better than writing machine languages manually in terms of speed and accuracy, and the "actual workload" completed by computers has increased.

Although the assembler is a great improvement over the state of switching bits on the machine panel, this kind of programming is still very professional. The example of addition above looks something like this in assembly language:

01 MOV R0, 102 MOV R1, 203 ADD R0, R1, R204 MOV 64, R005 STO R2, R0

Each line is a computer instruction, preceded by an abbreviation of the instruction and followed by the data the instruction operates on. This small program will first "move" the number 1 to register R0, and then move 2 to register R1. Line 03 adds the values in the R0 and R1 registers and stores the results in the R2 register. Lines 04 and 05 determine where the results should be placed in the main memory (in this case, address 64). Managing where data is stored in memory is one of the most time-consuming and error-prone parts of the programming process.

Compiler

Assemblers are already much better than handwritten computer instructions, but early programmers were eager to write programs in the same way they were used to writing mathematical formulas. This requirement has driven the development of high-level compiled languages, some of which are a thing of the past and others are still in use today. ALGO, for example, is a thing of the past, but languages like Fortran and C are still solving practical problems.

Pedigree Tree of ALGO and Fortran programming languages

These "high-level" languages allow programmers to write programs in a simpler way. In C, our addition program looks like this:

Int x TX = 1 + 2

* statements describe a piece of memory that the program will use. In this example, this block of memory should account for the size of an integer, named x. The second statement is addition, although it is written backwards. A C programmer would say that this is "the result of X being assigned to 1 plus 2". It is important to note that the programmer does not need to decide where to store x in memory, and the task is left to the compiler.

This new program, called a "compiler", can convert programs written in high-level languages into assembly language, and then use an assembler to convert assembly language into machine-readable programs. This combination of programs is often called a "tool chain" because the output of one program directly becomes the input of another.

The advantage of compiling language over assembly language is when migrating from one computer to another computer of different model or brand. In the early days of computers, many companies, including IBM, DEC, Texas Instruments, UNIVAC and Hewlett-Packard, made a lot of different types of computer hardware. These computers don't have much in common except that they all need to be connected to power. They differ greatly in memory and CPU architecture, when it often took years for people to translate programs from one computer into another.

With a high-level language, we just need to migrate the compiler tool chain to a new platform. As long as a compiler is available, programs written in high-level languages can be recompiled on new computers with at most minor modifications. The compilation of high-level languages is a truly revolutionary achievement.

The 1983 release of IBM PC XT is an early example of a decline in hardware prices.

The lives of programmers have improved very well. By contrast, expressing the problems they want to solve in a high-level language makes things a lot easier. Due to the progress of semiconductor technology and the invention of integrated chips, the price of computer hardware has dropped sharply. The speed of the computer is faster and faster, the ability is stronger and stronger, and it is much cheaper. At some point (maybe in the late 1980s), things reversed and programmers became more valuable than the hardware they used.

Interpreter

With the passage of time, a new way of programming emerged. A special program called an interpreter can directly read a program and convert it into computer instructions for immediate execution. Similar to the compiler, the interpreter reads the program and converts it to an intermediate form. But unlike the compiler, the interpreter directly executes this intermediate form of the program. An interpretive language goes through this process every time it executes; the compiler only needs to be compiled once, and then the computer only needs to execute the compiled machine instructions each time.

By the way, this feature is what makes people feel that interpretive programs are running slowly. But the performance of modern computers is so powerful that most people can't tell compiled programs from interpreted programs.

Interpretive programs (sometimes called "scripts") are even more likely to be ported to different hardware platforms. Because the script does not contain any machine-specific instructions, the same version of the program can be run on many different computers without any modification. But of course, the interpreter must be ported to the new machine first.

A popular interpretive language is perl. To fully express our addition problem in perl would look like this:

$x = 1 + 2

Although this program looks similar to the C language version and does not run much differently, it lacks statements to initialize variables. There are actually some other differences (beyond the scope of this article), but you should have noticed that the way we write computer programs is very close to the way mathematicians write mathematical expressions by hand with pen and paper.

Virtual machine

The trendy way of programming is the virtual machine (often referred to as VM). Virtual machines are divided into two categories: system virtual machines and process virtual machines. Both virtual machines provide different levels of abstraction of "real" computing hardware, but they have different scopes. The system virtual machine is software that provides an alternative to physical hardware, while the process virtual machine is designed to execute programs in a "system independent" manner. So in this example, the scope of the process virtual machine (which I will refer to later on refers to this type) is similar to that of the interpreter, because the program is also compiled into an intermediate form, and then the virtual machine executes the intermediate form.

The main difference between a virtual machine and an interpreter is that the virtual machine creates a virtual CPU and a set of virtual instructions. With this layer of abstraction, we can write front-end tools to compile programs in different languages into programs acceptable to the virtual machine. Perhaps the best-known virtual machine is the Java Virtual Machine (JVM). JVM originally supported only the Java language in the 1990s, but now it can run many popular programming languages, including Scala, Jython, JRuby, Clojure, and Kotlin. There are other less common examples that I won't talk about here. I also recently learned that my favorite language, Python, is not an interpretive language, but a language running on a virtual machine!

Virtual machines continue the historical trend that programmers need less and less knowledge of specific computing platforms when using domain-specific programming languages to solve problems.

At this point, the study of "what are assemblers, compilers and interpreters" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report