Below we introduce four basic program structures
1) Sequential structure
* A structure in which program modules or instructions are executed sequentially.
2) Branch structure
* The structure of jumping to different program segments (branches) according to conditions.
* Branches should not be transfers between modules, and the process should return to the main line after executing the branch.
* Be careful not to enter the entrance of another branch from the exit of one branch
3) Loop structure
* Repeat a certain program according to the loop control conditions for continuous repetitive operations.
* The loop includes the loop body and loop control; the loop structure also includes loop initialization and post-processing. There are two types of loop control: count loop and conditional loop.
* Loops can be nested, but they should not cross, and you should not jump into a loop from outside the loop body.
Reprinting must retain the address: http://www.51hei.com/mcu/286.html
4) Subroutine structure
* In the main program, the call subroutine instruction is executed, and the CPU switches to execute the subroutine. In the subroutine, the return instruction returns to the main program and continues to execute the next instruction of the call instruction.
* When calling, the return address is pushed onto the stack first, and the subroutine is transferred to the address provided by the call instruction. When returning, the return address is popped from the stack and sent to the PC, returning to the main program.
* Function modules used in multiple places in the program can adopt subroutine structure to save program space.
* Seven elements for writing and using subroutines:
* Functional description.
* Subroutine name and entry address.
* Entry conditions.
* Export status.
* Occupies resources.
* Calls in subroutines.
* Four points to note when writing and using subroutines:
* Site protection and site recovery to avoid conflicts with the main program.
* Stack operations should be performed in pairs, with PUSH first to protect the return address.
* Multiple calls should take the stack capacity into consideration, and direct or indirect reflexive calls should not be made.
* Prevent entering a subroutine without a call, and prohibit jumping out of a subroutine without a return instruction.
Previous article:MCU ISP programmer use
Next article:RS232 and RS422 interface circuits and their differences
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
- Share my fish farming process
- Let's unbox the LAUNCHXL-F28379D
- 【McQueen Trial】Python Programming (1)
- 9 tests and methods that must be performed on switching power supplies
- This week's topic: Let's talk about PID and share your experience. Two pieces of exquisite PID materials are included
- Shanghai is urgently recruiting FPGA development engineers with generous benefits! ! ! !
- Motor control circuit, MOS burnt out
- Design of filter module based on combination of single chip microcomputer and FPGA
- How to dissipate heat as a whole on the circuit board while ensuring that it is waterproof as a whole? The main reason is that the MOS tube of the patch generates the most heat and steps up and down the voltage.
- How to solve the problem that H file cannot be opened in IAR