Single-chip execution process, side weight hardware process
In order to deepen the understanding of the beginners to the 51 single-chip degree, the process of executing the instructions is now in detail, I hope to be inspired to you! The process of performing a single-chip performing program is actually the process of performing our program. That is, the process of taking one by one. The computer can be divided into three phases per execution of a directive. That is, the instruction is taken --- Analysis instruction ----- Execute the instruction. The task of taking the instruction is to read the row instruction from the program memory according to the value in the program counter PC, and sent to the instruction register. The task of the analysis instruction phase is to extract the instruction operating code in the command register, and analyze its instruction nature. If the instruction requires an operand, look for an operand address.
The process of computer executing programs actually repeat the above-described operational procedure, until the shutdown command can be looped. When the computer is working, the program and data must first be sent to the memory by an input interface circuit and a data bus through an external device, and then taken out by one by one. However, the procedures in the microcontroller generally have all been cured in the in-chip or on-chip memory in advance. Thus, the instruction can be executed. Below we will give an example to illustrate the execution of the instruction: When booting, the program calculator PC becomes 0000H. The single-chip automatically enters the execution program process under the timing circuit action. The execution process is actually taken out of the command (the instruction phase stored in the memory) and the execution instruction (analysis, and execution instruction). For example, instructions: MOV A, # 0E0h, the machine code is "74h E0H", which is the function of which the operating number E0H is sent to the accumulator, and the 74h unit is stored in the 0000H unit, and E0H is stored in the 0001H unit. When the single-chip start running, the first is to enter the normally, and the second order is:
1. The content of the program counter (at this time is 0000h) to the address register; 2. The content of the program counter is automatically added 1 (change to 0001H); 3. The content (0000H) of the address register is sent to the memory through the internal address bus. The address decoded in the memory is selected, so that the address of 0000h is selected; 4. The CPU is valid; 5. The contents of the memory cells are selected under the read command control (at this time should be 74h) to the internal data bus. On, since it is an end, the content is sent to the instruction register through the data bus. At this point, the finger stage is completed, and the decoding analysis and execution instruction phase are entered.
Since the content in this entry instruction register is 74h (opcode), the microcontroller will know that the command is to send a number to the A accumulator, and the number is next to the next one. Storage unit. Therefore, executing the instruction must also take the data (E0H) from the memory to the CPU, ie, the second byte is taken in the memory.
The process is very similar to the step stage, just at this time, the PC has been 0001H. The instruction decoder combines the timing component to generate a micro-operation series of the 74H operation code, and the digital E0H is taken out from the 0001H unit. Since the command is required to send the number to the A accumulator, the removed number is entered into the A accumulator through the internal data bus, rather than entering the instruction register. At this point, the execution of one instruction is completed.
PC = "0002H" in the single chip microcontroller, the PC is automatically added to the memory each time the CPU is referred to or taken, the microcontroller enters the next acquisition stage. This process has been repeated until it receives a pause instruction or a loop waiting instruction pause. The CPU is such a manner to perform instructions to complete all the specified functions.
51 MCU program execution process detailed analysis
The single-chip microcomputer is something that does not have a system. The code written in Keil is a bare metal code, that is, the code you write is similar to the operating system, and the in-depth writing of bare machine code helps to understand the hardware features.
If the hardware characteristics have been fixed, it is a code. Suddenly thinks to explore the implementation process of the 51 single-chip microcomputer. This idea originated from the main function in each 51 program, which eventually hangs a while (1); statement. Why add a while dead loop to let the program stay in the main function. What effect does the while (1); the statement does it affect?
Write a very simple program to try it.
The above procedure is performed, and the water controlled the water controlled by the P1 port is flashed. The program eventually entered while (1); in the insang, this is a good explanation.
Now WHILE (1); statement is blocked. I thought the program couldn't be implemented correctly, because I exited the main function, just like Render needs to be looped (although the progral of the flash is not within the loop, I still can't help but generate this mistake). The result of the program execution is: the water lane is constantly flashing!
See the guess and action after this phenomenon ^ - ^:
(1) This board is broken! (After running a C language file with an operating system such as a Linux character interface, it will return to the Linux shell program after completion of a C language file that does not have a dead cycle. Hurry and change the board and then test it, it is obviously the same result.
(2) The last (some) statements in the MAIN function will always be executed. (Based on the experience of running standard C language files under the OS platform, it can never think of whether the main function is called multiple times or multiple times)
(3) Once the C language instruction is taken into the single-chip microcontroller, the single-chip automatically generates a main program loop to perform the contents of the main function in the C language? (Although it is very absurd, still thinking)
(4) Hurry the implementation process of the single-chip microcontroller in Google Baidu (although in Google Baidu, the "51 MCU program execution process" search is not found.). Confused search term: "51 single-chip main". Then there is a question as you have asked me: Why don't you add While (1) in the main function; how to execute repeatedly after the statement? The key words of answers include "program running, watchdog, reset".
(5) The opportunity of the embedded machine will move the "51 single-chip program execution process" and tell the teacher to the phenomenon of the process I have written, including how I verified.
Teacher's answer: The Keil C51 program automatically loads a file called "startup.a51", and after a series of initialization operations have entered the user-written C language program in the user, the main function is executed. After the startup.a51 file, there is a statement that jumps to the program entry main function, so it will enter the C language main program main function to perform related content.
Then I used the Keil software to simulate the code that runs the above:
The program starts running on the first statement of the program entry main function, the Disassembly window is a window corresponding to the C language code and the assembly code. The front is the address, which is the compilation statement corresponding to the C language. The following window is the location of the corresponding file running code, pointing by the yellow arrow to the code that is currently executing. Then click the single-step running toolbar, and guide the MAIN function, and the program jumps to the following code location in Startup.a51:
Continue to click on single-step call until you enter a loop:
Here is a loop, according to the function of DJNZ instruction: each time DJNZ RO, iDataLoop minimizes the value of R0, and if the value of R0 is not 0, it jumps to the iDataLoop address. Obviously this is a loop, then how much is the value of RO, displayed in the following window:
It can be seen that the initial value of R0 is 0x7f, where it will be cycled 0x7f (128), and the meaning of the R0 value here can be viewed. So where will the program after this loop? The place where the program runs after this loop is as follows:
Run again again:
According to Disassembly, this statement is executed, and go back to the main function, try it.
Yes!
Therefore, in the 51 single-chip microcomputer, the execution process of the program is constantly (as a value of R0 as a delay condition, the specific meaning can continue to explore), execute the MAIN function.
Why do we run the C language code that runs without a dead cycle in Linux, it will terminate itself? This is a different operational process:
(1) The C51 single-chip microcomputer does not have an OS (operating system), the execution situation of the code is here to be scheduled by startup.a51, without a larger program to manage how to call the main function.
(2) The platform like Linux is an OS. Running a C language program is a task for Linux, in addition to running the C language program, there are other tasks. This task is also completed when running a C language program. If you run a file name "Hello.c" function in the Linux Shell interface, the process of the "Hello World!" Is as follows:
Compilation: GCC Hello.c -o Hello
Run: ./ Hello
When running the Hello executable file, you can call the Hello this executable. After the Hello is running, return the return value or the like to the shell interface. The life and death of the entire C language file has a Linux shell program management. , Read full text, original title: 51 single-chip program execution process detailed analysis
Article Source: [Micro Signal: Aidanpianji, WeChat Public Number: Tea McU] Welcome to add attention! Please indicate the source of the article.
Our other product: