Deepen your understanding of MCU and explain the instruction execution process of MCU

Publisher:genius5Latest update time:2018-11-22 Source: eefocusKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.


Keywords:MCU Reference address:Deepen your understanding of MCU and explain the instruction execution process of MCU

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

0-99V digital voltmeter made with STC12C2052AD microcontroller
The 0-99V digital voltmeter made with STC12C2052AD microcontroller comes from Digital Home_abenyao. I think this circuit is quite useful. The principle is simple. It directly uses the AD with STC12C2052AD microcontroller. The digital tube uses a four-digit common anode digital tube. There is a little jump after the dec
[Microcontroller]
0-99V digital voltmeter made with STC12C2052AD microcontroller
C51 microcontroller adjusts PWM wave through serial port
PWM is a commonly used electronic control technology PWM stands for pulse width modulation, which can be simply understood as the control of duty cycle. The figure below is an example of duty cycle, which is the ratio of high level time to cycle time in a cycle. Some MCUs now have built-in PWM control function,
[Microcontroller]
C51 microcontroller adjusts PWM wave through serial port
Proteus and Keil Cx51 microcontroller simulation (measure pulse width)
The width of the pulse appearing on the INT0 pin is tested using the gate bit and displayed by the light-emitting diode in the form of a number of machine cycles. Circuit Diagram: U1 source program: #include reg51.h sbit P1_1=P1^1; void main(void) { TMOD=0x02; EA=1; ET0=1; TH0=256-250; TL0=256-250;
[Microcontroller]
Atmega16 microcontroller connected to ESP8266 NodeMCU to send email
Atmega16 is a low-cost 8-bit microcontroller with a higher number of GPIOs compared to its previous versions. It has all the commonly used communication protocols like UART, USART, SPI, and I2C. Due to its wide community support and simplicity, it has a wide range of applications in the robotics, automotive, and autom
[Microcontroller]
Atmega16 microcontroller connected to ESP8266 NodeMCU to send email
Ordinary MCU Teaching Lesson 25 Matrix Keyboard Interface Technology and Programming
1. Matrix keyboard interface technology and programming 1. The structure and working principle of the matrix keyboard: When there are many keys in the keyboard, in order to reduce the occupation of I/O ports, the keys are usually arranged in a matrix form, as shown in Figure 1. In a matrix keyboard, each horizontal
[Microcontroller]
Ordinary MCU Teaching Lesson 25 Matrix Keyboard Interface Technology and Programming
MCU also needs model-based design? Haier embedded development expert Fan Jiqing says
In the rapid development of the home appliance industry, the traditional waterfall-style embedded development model is facing unprecedented challenges. As product functions become increasingly complex, how to improve development efficiency and ensure product quality has become the focus of enterprises.
[Embedded]
MCU also needs model-based design? Haier embedded development expert Fan Jiqing says
C51 single chip buzzer two butterfly code
#include // This is the code generated by the MCU music code generator #define uchar unsigned char sbit beepIO=P1^5; // Output is P1.5, can be changed to other IO ports flying m,n;  uchar code T ={{0,0}, {0xF8,0x8B},{0xF8,0xF2},{0xF9,0x5B},{0xF9,0xB7},{0xFA,0x14},{0xFA,0x66},{0xFA,0xB9},{0xFB,0x03},{0xFB,0x4A},{0xFB,0
[Microcontroller]
Design and implementation of serial communication program between PC and single chip microcomputer
  1 Introduction   Among many integrated visual development environments, VisualC++ is the best choice for programming environment. There are two main modes for the development of VC++ applications, one is WIN API mode and the other is MFC mode. The traditional WIN API mode is more cumbersome, while MFC is a re-enca
[Microcontroller]
Design and implementation of serial communication program between PC and single chip microcomputer
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号