In-depth understanding of computer systems (3.1)------assembly and machine language

Source: Internet
Author: User

"In-depth understanding of computer Systems" Chapter III-Machine-level representation of the program. The author first explains the relationship between the assembly code and the machine code, expounds the function of the assembly link, then starts from the machine language IA32, describes how to store the data, how to access the data, how to complete the operation and how to jump. Through these steps, we also tell the branch statement, how the Loop statement is done, function call, stack frame structure, and recursion process. Finally, the assembly code generated by the compiler shows that we need to understand the compiler and its optimization capabilities and what the compiler can do for us.

In this blog we will explain the relationship between assembly and machine code. First of all, the following picture is C language, assembly language and translated machine language, we can first have a familiar look.

  

citation to: http://www.jianshu.com/p/c60a9c2131c3

1. Machine language

This series of blog first Hello World How to run, we explained in detail the program's compilation, a C language program is a compiler into the assembler, and then through the assembler into machine code, and finally by the computer execution.

The computer does not directly recognize the C program or Java program that we have written. It can only recognize machine language, and machine language is a set of machine instruction system orders that can be directly identified and executed by a computer using binary code.

An early computer is a machine that can execute machine instructions and perform operations. In our common PC, there is a chip, which is what we often say CPU (central processing unit, centralized processing unit) can complete the functions of the aforementioned computer, but each such microprocessor (CPU) due to the hardware design and internal structure of the different, It needs to be controlled with different levels of pulses to make it work. So each microprocessor has its own set of machine instructions, which is machine language.

Early programming was using machine language. Programmers will use 0, 1 digital programming code to play on paper tape or card, 1 dozen holes, 0 do not punch, and then the program through the tape machine or card machine input computer, to do the operation.

In machine language programming, programmers first memorize all the instruction code and the meaning of the code used by the computer. When you hand-program, programmers have to handle each instruction and each data storage allocation and input and output, but also have to remember in the programming process of each step used in the state of the work unit. This is a very tedious task. The time spent writing programs is often dozens of times times or hundreds of times times the actual running time, and the programmed programs are all 0 and 1 instruction codes, with poor visibility and error-prone.

So what should we do? At this time assembly language was produced.

It is important to note that now in addition to the computer manufacturers of professionals, generally do not need to learn machine language.

2. Assembly language

Assembly language is the main body of assembly instructions. The difference between the assembly instruction and the machine instruction is that the instruction is represented, and the assembly instruction is the writing format which the machine instruction is easy to remember .

For example, the following will send the contents of the register BX to AX:

Operation: The contents of the register BX are sent to ax 1000100111011000              machine instruction mov ax,bx                    assembly Instructions

We can clearly see the difference from the above two instructions, and it is easy to remember that the assembly instructions are relative to the machine instructions.

Some people may ask, we use assembly language to write programs, but the computer only know the machine instructions, then what to do? We need a tool that converts assembly language to machine instructions, which we call compilers. The programmer writes out the source code in assembly language, compiles it into machine code with the assembler compiler, and finally the computer executes it.

  

Assembly language is a direct-oriented processor (PROCESSOR) programming languages. The processor is operating under the control of the instruction, and each instruction that the processor can recognize is called a machine instruction. Each processor has its own set of instructions that it can identify, called instruction sets. When the processor executes the instruction, it takes different actions according to different instructions and accomplishes different functions, which can change its internal working state and control the working state of other peripheral circuits.

Another feature of assembly language is that the object it operates is not specific data, but registers or memory, that is, it is directly and register and memory to deal with, which is why assembly language is faster than other languages, but it also makes programming more complex, Since the data is stored in registers or memory, there must be a way of addressing, that is, how to find the required data. For example, we can not use the data directly like the high-level language, but first we need to remove the data from the corresponding register ax and BX. This also increases the complexity of programming, because in high-level language addressing this part of the work is done by the compilation system, and in assembly language by the programmer himself, which adds to the complexity of programming and the readability of the program.

Moreover, assembly language instruction is a symbol of the machine instruction, and different types of CPUs have different machine instruction system, there are different assembly languages, so, assembly language program and Machine have a close relationship. Therefore, in addition to the same series, different models of the CPU between the assembly language program has a certain degree of portability, other different types (such as minicomputer and microcomputer, etc.) between the CPU of the assembly language program is not portable, that is, the assembly language program is more general and portability than high-level language program low.

Summed up are three features: machine affinity, high speed and efficiency, writing and debugging complex (relative to high-level languages).

3. Advanced Language

Before the machine language and the assembly language we all have to understand, assembly language is also the same as the machine language, are directly to the hardware operation, but the assembly language instruction using the English abbreviation identifier, easier to identify and memory. But it is easier to identify and remember than to speak to machine language. In the actual programming, the assembly language source program is also very complex and lengthy, at this time high-level languages produced.

High-level languages do not refer to a language, but include many programming languages, such as Java, C, C + +, C #, Python, and so on, which are highly encapsulated programming languages. High-level language and computer hardware structure and instruction system independent, it has stronger expression ability, can easily represent the data operation and program control structure, can better describe various algorithms, and easy to learn to master. But the program code generated by the high-level language compiler is generally longer and slower to execute than the program code designed in assembler language.

From the very beginning of a picture we gave you can see that C language written in just a few lines of code, translated into assembly language will be much more, let alone become machine language.

4. Summary

First of all, I would like to state that we do not need to learn how to use machine language, assembly language for programming, after all, we are not a computer manufacturer of professionals. All we need to know is how to read assembly language. Because in the high-level language that we write, the compiler automatically does some optimizations when it is translated into assembly languages, which, if we do not know, causes a program error, which is described in detail later in this example.

Next blog We will explain a simple assembler instance.

  

In-depth understanding of computer systems (3.1)------assembly and machine language

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.