In order to deepen the understanding of 51 MCU instructions for beginners, the instruction execution process is now explained in detail. I hope it will be inspiring to you!
The process of microcontroller executing a program is actually the process of executing the program we compiled. That is, the process of executing one instruction at a time. The computer can be divided into three stages for each instruction execution: fetching instructions, analyzing instructions, and executing instructions.
The task of instruction fetching is to read the current instruction from the program memory according to the value in the program counter PC and send it to the instruction register.
The task of the instruction analysis stage is to take out the instruction opcode in the instruction register, decode it, and analyze its instruction nature. If the instruction requires an operand, find the operand address.
The process of computer execution of program is actually to repeat the above operation process one by one until a stop instruction is encountered, and then the waiting instruction can be looped. When a computer is working, the program and data must first be sent to the memory through the input interface circuit and data bus through external devices, and then taken out one by one for execution. However, the program in the microcontroller is generally solidified in the on-chip or off-chip program memory through the writer in advance, so the instruction can be executed as soon as the computer is turned on. Below we will give an example to illustrate the execution process of the instruction. Reprinted from 21ic Basic Knowledge
When the computer is turned on, the program counter PC changes to 0000H. Then the microcontroller automatically enters the program execution process under the action of the timing circuit. The execution process is actually a cycle of fetching instructions (fetching instructions stored in the memory in advance) and executing instructions (analyzing and executing instructions).
For example, the instruction: MOV A, #0E0H, its machine code is "74H E0H", the function of this instruction is to send the operand E0H to the accumulator, 74H is stored in the 0000H unit, and E0H is stored in the 0001H unit. When the microcontroller starts running, it first enters the instruction fetch stage, and the order is:
1 The content of the program counter (0000H at this time) is sent to the address register;
2 The content of the program counter automatically increases by 1 (becomes 0001H);
3 The content of the address register (0000H) is sent to the memory through the internal address bus, and the address decoding circuit in the memory follows, so that the unit with address 0000H is selected;
4 The CPU enables the read control line;
5 Under the control of the read command, the content of the selected memory cell (which should be 74H at this time) is sent to the internal data bus. Because it is the instruction fetch stage, the content is sent to the instruction register through the data bus. At this point, the instruction fetch stage is completed and the decoding analysis and instruction execution stage begins.
Since the content entering the instruction register this time is 74H (operation code), after the decoder decodes it, the MCU will know that the instruction is to send a number to the A accumulator, and the number is in the next storage unit of this code. Therefore, to execute this instruction, the data (E0H) must be taken out of the memory and sent to the CPU, that is, the second byte must be taken from the memory. The process is very similar to the instruction fetch stage, except that the PC is already 0001H at this time. The instruction decoder combines the timing components to generate a micro-operation series of the 74H operation code, so that the number E0H is taken out from the 0001H unit. Because the instruction requires the obtained number to be sent to the A accumulator, the taken number enters the A accumulator through the internal data bus instead of entering the instruction register. At this point, the execution of an instruction is completed. PC = "0002H" in the MCU, and PC automatically increases by 1 every time the CPU fetches an instruction or a number from the memory, and the MCU enters the next instruction fetch stage. This process is repeated until a pause instruction is received or the loop wait instruction is paused. This is how the CPU executes instructions one by one to complete all specified functions.
Previous article:How is the microcontroller program executed? Where is the instruction data written?
Next article:The relationship between microcontroller instruction set and operating system
Recommended ReadingLatest update time:2024-11-16 11:48
- Popular Resources
- Popular amplifiers
- Wireless Sensor Network Technology and Applications (Edited by Mou Si, Yin Hong, and Su Xing)
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- MSP430F5529 serial port clock and SPI clock configuration issues
- [Evaluation of SGP40] + UART communication + use of at32f407 development board
- Solid-state devices versus vacuum tubes: Will the two coexist for a long time?
- [Atria AT32WB415 Review] 5. Bluetooth Low Energy Version (BLE) Official Demo Review
- This amplifier is a bit figurative, isn't it?
- ad19.0.10 3D display problem
- Why is there only one channel with data when using STM32's TIMER to capture DMA?
- The concept and function of PA and LNA in Bluetooth module
- [Shanghai Hangxin ACM32F070 development board review] 7. Give the watchdog a thread
- New member reporting in!