Introduction to programming languages
#机器语言
Since the computer can only accept binary code, the instructions described in binary code 0 and 1 are called machine instructions, and the set of all machine instructions forms the machine language of the computer, and the program programmed in machine language is called the target program. Only the target program can be directly recognized and executed by the computer. But the machine language program has no obvious characteristics, difficult to remember, inconvenient to read and write, and depends on the specific machine, the limitations are very large, machine language belongs to the low-level language.
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 it takes to write a program is often dozens of times times or hundreds of times times the actual run time. Furthermore, the programmed programs are all 0 and 1 instruction codes, which are poor in visibility and error prone. In addition to the computer manufacturer's professionals, the vast majority of programmers are no longer learning machine language.
Machine language is understood and used by microprocessors to control its operation of binary code.
Although machine language seems to be very complex, it is regular.
There are instructions for as many as 100000 machine languages. This means that it is not possible to list all these types.
Here are some examples:
Example of a command part
Delegate load (load)
Representative Storage (store)
...
Example of the Scratchpad section
Represents A register of registers A
Represents a register B
...
Examples of memory parts
Represents memory with address 0
Represents memory with address 1
Represents memory with address 16
Represents a memory with the address 2^11
Integration examples
0000,0000,000000010000 represents LOAD A, 16
0000,0001,000000000001 on behalf of LOAD B, 1
0001,0001,000000010000 representative STORE B, 16
0001,0001,000000000001 representative STORE B, 1[1]
#汇编语言
The language of assembly language is the same as that of the machine, which is directly to the hardware, but the instruction adopts the English abbreviation identifier, which is easier to recognize and remember. It also requires programmers to write each step of a specific action in the form of a command. Each instruction in the assembler can only correspond to a very subtle action in the actual operation. For example, mobile, self-increment, so the assembly source program is generally more lengthy, complex, error-prone, and the use of assembly language programming requires more computer expertise, but the advantages of assembly language is also obvious, with assembly language can be done by the general high-level language can be achieved, and the source program generated by the assembly of the executable file is not only smaller, and execution speed quickly.
Compilation of Hello World, printing a word Hello world, need to write more than 10 lines, is also drunk.
; Hello.asm
section. Data; Data Segment Declaration
MSG db "Hello, world!", 0xA; The string to output
Len Equ $-msg; String length
section. Text; Code Snippet Declaration
Global _start; Specify the entry function
_start:; Display a string on the screen
mov edx, Len; Parameter three: string length
mov ecx, msg; Parameter two: the string to display
mov ebx, 1; Parameter one: File descriptor (STDOUT)
mov eax, 4; System call NUMBER (Sys_write)
int 0x80; Calling kernel functions
; Exit program
mov ebx, 0; Parameter one: Exit code
mov eax, 1; System call NUMBER (Sys_exit)
int 0x80; Calling kernel functions
#高级语言
High-level languages are the choice of most programmers. Compared with assembly language, it not only synthesizes many related machine instructions into a single instruction, but also removes details related to the operation but not relevant to the completion of the work, such as the use of stacks, registers, etc., which greatly simplifies the instructions in the program. At the same time, because of the omission of a lot of details, programmers do not need to have too much expertise.
The high-level language is mainly relative to the assembly language, it does not refer specifically to a specific language, but includes many programming languages, like the simplest programming language Pascal language is also a high-level language.
High-level language programming programs can not be directly recognized by the computer, must be converted to be executed, according to the conversion can be divided into two categories:
Compile class: Compile refers to the application source code before the execution of the program, "translated" Into the target code (machine language), so its target program can be independent of its language environment execution (compiled after the generated executable file, the CPU can understand the 2 binary machine code composition), the use of more convenient, high efficiency. However, once the application needs to be modified, the source code must be modified, and then recompiled to generate a new target file (*. obj, which is the obj file) to execute, only the target file without source code, modification is inconvenient.
After compiling the program, you do not need to re-translate, directly using the results of the compilation is OK. The program executes efficiently, relies on the compiler, the cross-platform is inferior. such as C, C + +, Delphi, etc.
Interpretation class: The execution is similar to our daily life "simultaneous translation", the application source code on the other side by the corresponding language interpreter "translated" Into the target code (machine language), side execution, so inefficient, and can not produce independent executable files, the application can not be separated from its interpreter (want to run, The interpreter must be loaded first, just like talking to a foreigner, there must be a translator present, but this is a more flexible way to adjust and modify the application dynamically. such as Python, Java, PHP, Ruby and other languages.
The advantages and disadvantages of machine language, assembly language, advanced languages
Machine language
#优点是最底层 with the fastest execution speed
#缺点是最复杂, lowest development efficiency
Assembly
#优点是比较底层 with the fastest execution speed
#缺点是复杂, lowest development efficiency
Advanced language
#编译型语言执行速度快, not dependent on the language environment, cross-platform poor
#解释型跨平台好, a code that is used everywhere, the disadvantage is that the execution is slow, dependent on the interpreter to run
Programming Language Basics