Four basic program structures

Publisher:JoyfulSpiritLatest update time:2013-01-07 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.

Reference address:Four basic program structures

Previous article:MCU ISP programmer use
Next article:RS232 and RS422 interface circuits and their differences

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号