Several main components of single chip microcomputer have been described earlier, which constitute the hardware of single chip microcomputer scheme. The so-called hardware is an entity that can be seen and touched. However, with such hardware, it is only possible to realize the functions of calculation and control. In order to truly calculate and control, the single chip microcomputer must also be cooperated with software. Software mainly refers to various programs. Only by "pouring" (storing) all kinds of correct programs into the single chip microcomputer, it can work effectively. The single chip microcomputer can automatically carry out operation and control. It is precisely because people use the form of commands to realize the steps of calculation and control step by step, that is, instructions are stored in memory in advance. Under the control of CPU, the single chip microcomputer takes out the instructions one by one, translates and executes them. For the simple operation of adding two numbers, after the number to be calculated has been stored in the memory, the following steps need to be carried out:
Step 1: take a number from its location and send it to the arithmetic unit.
Step 2: take the second number from its storage unit and send it to the arithmetic unit;
Step 3: add; Step 4: send the added result to the specified unit in the memory.
All these fetching, sending, adding, saving, etc. are operations. We write down various operations required to be performed by the computer in the form of commands, which are instructions. But how can we identify and perform these operations? This is determined by the instruction system given by the designer when designing the single chip microcomputer. An instruction corresponding to a basic operation; All the instructions that can be executed by the single chip microcomputer are the instruction set of the single chip microcomputer. Different kinds of single chip microcomputer have different instruction systems.
When using the single chip microcomputer scheme, the problems to be solved should be compiled into a series of instructions in advance. These instructions must be the instructions that the selected MCU can recognize and execute. The instruction program compiled by MCU users to solve their own problems is called source program. Instructions are usually divided into two parts: opcode and operand. The operation code indicates what operation the computer performs, that is, the function of the instruction; The operand represents the operand or the address where the operand is located (that is, the number of the place where the operand is stored). Because MCU is a programmable device, only "recognize" binary code (0, 1). To the operation of single chip microcomputer, all instructions in the single chip microcomputer system must be expressed in the form of binary coding. For example, in the MCS-51 series single chip microcomputer of Intel company, the instruction code of the accumulator (in the arithmetic unit, the special register for participating in the operation and storing the operation results) that takes a number from the memory to the CPU is 74h, the code of the accumulator content plus the immediate number is 24h, plus the immediate number code, and the code of the accumulator sending the number to the internal RAM memory is f6h ~ f7h, etc. These instructions are machine codes that represent binary in hexadecimal.
The word length of MCS-51 single chip microcomputer is 8 bits. Sometimes, it can not be fully expressed in one byte to complete some operations. Therefore, there are single byte instructions and multi byte instructions in the instruction system. Machine code is composed of a series of 0 and 1. It has no obvious characteristics. It is difficult to remember, understand and make mistakes. Therefore, it is very difficult to write programs directly with it. Therefore, people use some mnemonics, usually English abbreviations of instruction functions, to replace the opcode. For example, mov (abbreviation of move) and add (abbreviation of addition) are commonly used as mnemonics for the transmission of numbers in MCS-51. In this way, each instruction has obvious action characteristics, is easy to remember and understand, and is not easy to make mistakes. Programs written with mnemonics are called assembly language programs. However, the mnemonic program is easy to understand, but the single chip microcomputer only knows the binary machine code. Therefore, in order for the single chip microcomputer to "read" the assembly language program, it must be converted into a program composed of binary machine code. This conversion process is called "assembly". Assembly can be realized by means of manual look-up table method, or by means of PC through the so-called "cross assembler". Once the user program composed of machine code "enters" the single chip microcomputer, and then "starts" the single chip microcomputer, it can perform the tasks specified by the input program.
MCU -- 51 CPU and memory