Many assemblers provide additional support mechanisms for program development, assembly control and auxiliary debugging. Some assembly language programming tools often provide macros, also known as macro assemblers.
Assembly language is not as widely used in programming as most other programming languages. In today's practical application, it is usually applied to the bottom, hardware operation and high-demand program optimization occasions. Drivers, embedded operating systems and real-time running programs all need assembly language.
Chinese name: assembly language mbth: assembly language discipline: software engineering generation year: 1950s compilation mode: assembly development process, language features, overall features, advantages and disadvantages, language composition, data transmission instructions, integer and logic operation instructions, shift instructions, bit operation instructions, condition setting instructions, control transmission instructions, string operation instructions, I/O instructions, related technologies, assembly programs, compilation environment. When it comes to the production of assembly language, we must first speak machine language. Machine language is a collection of machine instructions. Machine instruction extension is a command that the machine can execute correctly. The machine instructions of an electronic computer are a series of binary digits. The computer converts it into a series of high and low levels, thus driving and operating the electronic devices of the computer. The computer mentioned above refers to a machine that can execute machine instructions and perform operations. This is the concept of early computers. In our common PC, there is a chip to complete the functions of the computer mentioned above. This chip is what we often call CPU (Central Processing Unit). Because of the different hardware design and internal structure, each microprocessor needs to be controlled by different level pulses to work. So each microprocessor has its own machine instruction set, that is, machine language. Early programming used machine language. Programmers type the program code with the number of 0, 1 on paper tape or card, 1 punches holes, and 0 does not punch holes, and then input the program into a computer for operation through a paper tape machine or card machine. This machine language is composed of pure 0 and 1, which is very complicated, inconvenient to read and modify, and prone to errors. Programmers soon found that the use of machine language brought trouble, difficult to distinguish and remember, and brought obstacles to the development of the whole industry, so assembly language came into being. The main body of assembly language is assembly instruction. The difference between assembly instructions and machine instructions lies in the way instructions are expressed. Assembly instruction is an easy-to-remember writing format of machine instructions. Operation: the contents of register BX are sent to ax10011111000 machine instruction mov? Ax, bx assembly instructions from then on, programmers used assembly instructions to write source programs. But the computer can only read machine instructions, so how to make the computer execute the program written by the programmer with assembly instructions? At this time, a translator is needed, which can convert assembly instructions into machine instructions. Such a program is called a compiler. Programmers write source programs in assembly language, then compile them into machine code with assembly compiler, and finally execute them by computers. The characteristics of working process language Assembly language is a programming language directly oriented to the processor. The processor works under the control of instructions, and every instruction that the processor can recognize is called a machine instruction. Each processor has a set of instructions that it can recognize, called instruction sets. When executing instructions, the processor takes different actions to complete different functions according to different instructions, which can not only change its internal working state, but also control the working state of other peripheral circuits. Another feature of assembly language is that the object it operates on is not specific data, but registers or memories, that is, it directly processes registers and memories, which is why the execution speed of assembly language is faster than other languages, but it also makes programming more complicated, because since data is stored in registers or memories, there must be an addressing method, that is, how to find the needed data. For example, in the above example, we can't use data directly like a high-level language, but we should first take the data out of the corresponding registers AX and BX. This also increases the complexity of programming, because in high-level languages, addressing is done by the compiler system, while in assembly languages, it is done by the programmer himself, which increases the complexity of programming and reduces the readability of the program. Furthermore, assembly language instructions are symbolic representations of machine instructions, and different types of CPU have different machine instruction systems, so assembly language programs are closely related to machines. Therefore, apart from the portability of assembly language programs between different types of CPUs in the same series, assembly language programs between different types of CPUs (such as minicomputers and microcomputers) cannot be transplanted, that is to say, the universality and portability of assembly language programs are lower than those of high-level language programs. It is precisely because of the "machine-related" characteristics of assembly language that programmers can make reasonable arrangements for various resources inside the machine when writing programs in assembly language, so that it is always in the best use state. The program written in this way has short execution code and fast execution speed. Assembly language is one of the most closely related, direct and time and space efficient programming languages. It is one of the compulsory courses for computer application technology majors in colleges and universities, and plays an important role in cultivating students to master programming technology and be familiar with computer operation and program debugging technology. General features: 1. Machine Correlation This is a low-level machine-oriented language, which is usually specially designed for a specific computer or series of computers. Because it is symbolic representation of machine instructions, different machines have different assembly languages. Using assembly language can face the machine, give full play to the characteristics of the machine, and get high-quality programs. 2. High-speed and efficient assembly language maintains the advantages of machine language, and has the characteristics of directness and simplicity, and can effectively access and control various computer hardware devices, such as disks, memory, CPU, I/O connection ports, etc. , occupying less memory, is an efficient programming language. 3. Complexity of programming and debugging Because the hardware is directly controlled, simple tasks also require a large number of assembly language statements, so all aspects need to be covered when programming, and all possible problems need to be considered, and all kinds of software and hardware resources should be allocated and used reasonably. In this way, it will inevitably increase the burden on programmers. Similarly, when debugging a program, it is difficult to find out whether there is a problem with the operation of the program. Advantages 1. Because the program designed with assembly language is finally transformed into machine instructions, it can keep the consistency of machine language, be direct and simple, and can access and control various hardware devices of the computer like machine instructions, such as disks, memory, CPU, I/O connection ports, etc. Using assembly language, you can access all accessible software and hardware resources. 2. The object code is short, occupies less memory and has high execution speed. It is an efficient programming language. It is often used in conjunction with high-level languages to improve the execution speed and efficiency of programs and make up for the shortcomings of high-level languages in hardware control. It is widely used. Disadvantages 1. Assembly language is machine-oriented and at the bottom of the whole computer language system, so it is regarded as a low-level language, and is usually specially designed for a specific computer or series of computers. Different processors have different assembly language grammars and compilers, and the compiled program cannot be executed on different processors, so it lacks portability. 2. It is difficult to understand the programming intention from the assembly language code, and the maintainability is poor. Even simple work needs a lot of assembly language code, which is easy to produce bugs and difficult to debug; 3. Using assembly language, you must know a certain processor very well, and you can only optimize it for a specific architecture and processor, so the development efficiency is very low, and the cycle is long and monotonous. This part of data transfer instruction consists of general data transfer instruction MOV, conditional transfer instruction CMOV, stack operation instruction Push/Pusha/Pushad, exchange instruction XCHG/XLAT/BSWAP, address or segment descriptor selector instruction LEA/LDS/LES/LFS/LGS/LSS, etc. Note that CMOV is not a specific instruction, but a cluster of instructions, including a large number of instructions, which are used to decide whether to perform the specified branch operation according to some bit states of EFLAGS register. Integer and logic operation instructions are used to perform arithmetic and logic operations, including addition instruction ADD/ADC, subtraction instruction SUB/SBB, addition instruction INC, subtraction instruction DEC, comparison operation instruction CMP, multiplication instruction MUL/IMUL, division instruction DIV/IDIV, sign extension instruction CBW/CWDE/CDQE, decimal adjustment instruction DAA/DAS/AAA/AAS and logic operation. Shift instruction This part of the instruction is used to move a register or memory operand a specified number of times. Include logical left shift instruction SHL, logical right shift instruction SHR, arithmetic left shift instruction SAL, arithmetic right shift instruction SAR, cyclic left shift instruction ROL, cyclic right shift instruction ROR, etc. These bit operation instructions include bit test instruction BT, bit test and set instruction BTS, bit test and reset instruction BTR, bit test and negation instruction BTC, bit forward scan instruction BSF, bit backward scan instruction BSR, etc. Conditional setting instruction This is not a specific instruction, but a cluster of instructions, including about 30 instructions, used to set an 8-bit register or memory operand according to some bit states of EFLAGS register. For example, SETE/ SETNE/SETJI and so on. This part of control transfer instruction includes unconditional transfer instruction JMP, conditional transfer instruction J /JCXZ, loop instruction LOOP/LOOPE/LOOPNE, procedure call instruction RET, interrupt instruction INTn, INT3, INTO, IRET, etc. Note that J is an instruction cluster, which contains many instructions and is used to decide whether to branch according to some bit states of EFLAGS register. INT n is a soft interrupt instruction, and n can be a number between 0 and 255 to indicate the interrupt vector number. This part of string operation instruction is used to operate data strings, including string transfer instruction MOVS, string comparison instruction CMPS, string scanning instruction SCANS, string loading instruction LODS and string saving instruction STOS. These instructions can be operated continuously by selectively using the prefixes REP/REPE/REPZ/REPNE and REPNZ. I/O command This part of the command is used to exchange data with peripheral devices, including the IN/INS input command of the connection port and the OUT/OUTS output command of the connection port. Auxiliary instructions of high-level languages provide convenience for compilers of high-level languages, including the instruction ENTER for creating stack frames and the instruction LEAVE for releasing stack frames. This part of the control and privilege instructions include no operation instruction NOP, stop instruction HLT, WAIT/MWAIT, escape instruction ESC, bus blocking instruction LOCK, memory range check instruction BOUND, global descriptor table operation instruction LGDT/SGDT, interrupt descriptor table operation instruction LIDT/SIDT, local descriptor table operation instruction LLDT/SLDT, descriptor segment boundary value loading instruction LSR, Descriptor access reading instruction LAR, task register operation instruction LTR/STR, request privilege level adjustment instruction ARPL, task switch flag clearing instruction CLTS, control register and debug register data transmission instruction MOV, cache control instruction INVD/WBINVD/INNVLPG, model related register reading and writing instruction RDMSR/WRMSR, processor information acquisition instruction CPUID, timestamp reading instruction RDTSC, etc. Floating-point and multimedia instructions are used to speed up the operation of floating-point data, and single-instruction multiple-data (SIMD and its extended SSEx) instructions are used to speed up the processing of multimedia data. This part of the instruction data is too large to list one by one, please refer to the INTEL manual yourself. The instructions for virtual machine expansion include invept/invvpid/vmcall/vmclear/vmlaunch/vmresume/vmptrld/vmptrst/vmread/vmwrite/vmxoff/vmon, etc. Related Art Assemblers Typical modern assemblers construct object codes from mnemonics to operation codes, and parse symbol names into memory addresses and other entities. Using symbolic reference is an important feature of assembler, which can save tedious and time-consuming manual address calculation after modifying the program. Basically, it is to change the machine code into some letters, and then change the input instruction letters into obscure machine code when compiling. Symbolic programs written in non-machine languages such as assembly language are called source programs, and the function of assembly language compiler is to translate source programs into target programs. The object program is a machine language program, which can be processed and executed by the CPU of the computer when it is placed in a predetermined position in the memory. Generally speaking, there are few debugging environments for assembly and very good compilers. The choice of compiler depends on the type of target processor and the specific system platform. Generally speaking, a fully functional compiler should be very convenient to use, for example, it should be able to automatically arrange formats, highlight grammar, integrate compilation, linking and debugging, and be convenient and practical. For the widely used personal computers, there are MASM, NASM, TASM, gas, FASM, radar and so on. , but most of them do not have debugging function. If you are learning assembly language, easy assembly is a very suitable assembly compiler for beginners because it has a perfect integration environment. Development Prospect Assembly language is a mnemonic of machine language, which is easier to read, write, debug and modify than boring machine code. At the same time, excellent assembly language designers make the compiled code execute faster and occupy less memory space than high-level languages through clever design. However, the running speed and space occupation of assembly language are aimed at high-level languages, which need ingenious design, and the code execution efficiency of some high-level languages is also very high after compilation, so this advantage is gradually weakening. In addition, writing complex programs has obvious limitations. Assembly language depends on concrete models, so it can't be universal and can't be transplanted between different models. People often say that assembly language is a low-level language, but this does not mean that assembly language should be abandoned. On the contrary, assembly language is still a language that the bottom programmers of computers (or microcomputers) must understand. In some industries and fields, assembly is essential and not applicable. However, at present, the biggest field of computer is IT software, which is what we often call computer application software programming. In the hands of skilled programmers, the efficiency and performance of programs written in assembly language are relatively higher than those written in other languages, but at the cost of longer optimization time. If the computer principle and programming foundation are not solid, it will increase the difficulty of its development, and the loss will outweigh the gain. Compared with the software development around 20 10, it has become a market-oriented software industry. Coupled with the Excellence and cross-platform of high-level language, it is impossible for a company to let a team write everything in assembly language, which takes several times or even dozens of times. It is best to do it in other languages. As long as the final result is not much worse than that written in assembly language, it can be completed first. This is the inevitable result under the market economy. However, so far, no programmer dares to conclude that assembly language is unnecessary to learn. At the same time, assembly language is a machine-oriented programming language, and some well-designed assembly programmers have left software development and squeezed into industrial electronic programming. For industries with relatively small functions but high requirements for language design in hardware, such as 4-bit single chip microcomputer, due to its capacity and operation, electronic engineers in this industry are generally responsible for developing and designing circuits and software control. The main development language is assembly, and the use of C language only accounts for a small part, so it is difficult for electronic development engineers to find it. In some industrial companies, the salary of core electronic engineers is higher than that of any other employees. In contrast, the average electronic engineer's salary is ten times that of a programmer. This situation is because since 2 1 century, although many people have studied assembly, not many people have really mastered it. Compared with advanced languages, it is difficult to learn, difficult to use and has a small scope of application. Although simple, it is too flexible. It is much more difficult for people who have studied advanced languages to learn assembly than at first, but it is easy for people who have studied assembly to learn advanced languages. Assembly language is a compulsory language for a programmer who fully understands the principle of microcomputer. Practical application With the increasing complexity of modern software systems, a large number of packaging high-level languages such as C/C++, Pascal/Object Pascal came into being. These new languages make programmers more simple and efficient in the development process, and enable software developers to meet the requirements of rapid software development. However, due to its complexity, the application field of assembly language is gradually shrinking. But this does not mean that compilation is useless. Because assembly is closer to machine language, it can directly operate the hardware, and the generated program runs faster than other languages and occupies less memory, so it is widely used in some programs with high timeliness requirements, the core modules of many large programs, industrial control and so on. In addition, although there are many programming languages to choose from, assembly is still a compulsory course for computer majors in universities, so that students can deeply understand the operating principle of computers. Historically, assembly language was once one of the most popular programming languages. With the growth of software scale, and the consequent requirements for the progress and efficiency of software development, high-level languages have gradually replaced assembly languages. But even so, high-level language can't completely replace the function of assembly language. Take the Linux kernel as an example. Although most of the code is written in C language, it is inevitable to use assembly code in some key places. Because of the close relationship between this part of code and hardware, even C language can't cope with it, while assembly language can make full use of its strengths and avoid its weaknesses, and maximize the performance of hardware. First of all, most statements in assembly language directly correspond to machine instructions, which has the advantages of fast execution speed, high efficiency and small code amount. It is very useful in those places where storage capacity is limited, but fast real-time echo is needed, such as instruments and meters, industrial control equipment, etc. Secondly, assembly language can be used in the core part of the system program and the part that often deals with the system hardware. For example, the core program segment of the operating system, the initialization program of I/O interface circuit, the bottom drivers of external devices, and frequently called subroutines, dynamic link libraries, some advanced drawing programs, electronic game programs and so on. Thirdly, assembly language can be used for software encryption and decryption, computer virus analysis and prevention, program debugging and error analysis. Finally, by learning assembly language, we can deepen our understanding of computer principles and operating systems. By learning and using assembly language, we can perceive, experience and understand the logical functions of machines, and lay a technical and theoretical foundation for understanding the principles of various software systems. Master the principle of hardware system and lay the foundation for practical application. There are many classic teaching materials of assembly language, which are involved in various processors, and there are no fewer than 100 kinds of rough statistics. Among so many textbooks, the ones that are widely used can be classified as follows: x86 processor 1. X86 Assembly Language: From Real Mode to Protected Mode, by Li Zhong, Electronic Industry Press, 20 13- 1. Based on INTEL x86 processor, NASM compiler and BOCHS virtual machine. Assembly language is the language of the processor. In this sense, since you learn assembly language, you should program the hardware directly, instead of using inexplicable DOS interrupts and API calls. This is an interesting book. It won't spend space on calculating some boring math problems. On the contrary, it teaches you how to directly control hardware, display characters, read hard disk data and control other hardware without the support of BIOS, DOS, Windows, Linux or any other software. We know that 32-bit and 64-bit are the mainstream, real mode and DOS operating system have become history, and both Linux and Windows are working in protected mode. This book talks about 32-bit protection mode from the real mode, with special emphasis on 32-bit protection mode. Reading this book is very helpful to understand the working principle of modern computers and modern operating systems. 2. Assembly Language (2nd Edition), edited by Wang Shuang and published by Tsinghua University Press, 20 13-4- 1 is an assembly textbook based on INTEL 8086 processor, MASM compiler and DOS platform. It is mainly based on the real mode of 8086 processor and does not involve the commonly used 32-bit and 64-bit modes, but it is easy to understand and has a good response from readers. 3. Course of 80x86 Assembly Language Programming, edited by Yang Jiwen, Tsinghua University Publishing House, 1999-3- 1, based on INTEL x86 processor, MASM and TASM compilers, including 16 bit real mode and 32-bit protection mode, and described the latter in detail. 4.32-bit assembly language programming, edited by Qian Xiaojie, Machinery Industry Press, 201-8-1,an assembly textbook based on INTEL x86 processor, MASM compiler and WINDOWS platform. 5. Principle Assembly Language and Interface Technology of 16/32-bit Microcomputer, edited by Qian Xiaojie and Chen Tao, Mechanical Industry Press, February 2005-1Based on INTEL x86 processor, the basic principle, assembly language and interface technology of16-bit microcomputer are discussed, and the 32-bit microcomputer system is introduced. 6. Intel Assembly Language Programming (5th Edition), written by Irving (USA), Electronic Industry Press, 20 12-7- 1, an assembly textbook based on Intel x86 processor, MASM compiler and DOS/WINDOWS platform, which contains both 16 real mode and 32 bits. 7. "Programming Art of Assembly Language (2nd Edition)", by Hyde (USA), Tsinghua University Press, 2011Based on INTEL x86 processor, using the author's self-made high-level assembler (HLA) as the teaching tool, in order to obtain a part of it, 8.X86PC assembly language, Electronic Industry Press, 2011/is based on INTEL x86 processor, in which not only the contents of 16 bit real mode are discussed, but also the ARM and MCU 1. Assembly Language Programming Based on ARM Architecture (2nd Edition), edited by Wenquan Gang et al., Beijing University of Aeronautics and Astronautics Press, 20 10-8- 1 Processor based on ARM architecture is an introductory textbook for learning embedded technology. 2. Zero-based avr microcontroller, edited by Xu Yimin, Machinery Industry Press, 2011,overview of avr microcontroller, development tools of avr microcontroller, C language of AVR microcontroller, basic structure of atmega 16 microcontroller, instruction system and assembly system of AVR, etc. 3. The main functions of NI Multisim 10 in single-chip computer simulation are expounded in "5 1 Single-chip Computer Simulation Course Based on Multisim10", which is edited by Nie Dian and published by Electronic Industry Press, with 2010-21. 4.PIC 18 Microcontroller: Architecture, Programming and Interface Design, by Berry, Tsinghua University Press, April 2009-1 Microcontrollers are widely used in many fields such as automobiles, household appliances, industrial control and medical equipment. Taking PIC 18 series microcontrollers of Microchip company as an example, this book comprehensively explains how to use C language and assembly language to program microcontrollers. 5. "Assembly Language Programming" compiled by Zhao China Electric Power Press 2002-101Assembly language is the compulsory content of China computer software professional and technical qualification examination and advanced programmer level examination. This book is a monograph on CASL assembly language programming.