VI XỬ LÝ Vxl ch03 8051 3 9 cau truc va tk chuong trinh

48 0 0
VI XỬ LÝ Vxl ch03 8051 3 9 cau truc va tk chuong trinh

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Hardware Summary of 8051 2011/12/7 T L Jong, Dept of E E , NTHU 1 System & Program System & Program Developments of 8051Developments of 8051 Program Structure and Design Introduction Advantages and Di[.]

System & Program Developments of 8051 “ Program Structure and Design “ “ “ “ “ “ Introduction Advantages and Disadvantages of Structured Programming The Three Structures: statements, loops, choice Pseudo Code Syntax Assembly Language Programming Tools & Techniques for Program Development “ “ “ The Development Cycle Integration and Verification Command and Environments 2011/12/7 T L Jong, Dept of E.E., NTHU Introduction “ Structured Programming: “ “ “ Organizing and coding programs that reduces complexity, improves clarity, and facilitates debugging and modifying All programs may be written using only three structures: statements, loops, and choice—too good to be true Introduce Structure programming to assembly language programming “ “ “ 2011/12/7 Flowcharts Pseudo code Assembly language T L Jong, Dept of E.E., NTHU Flowcharts Decision block Off-page connector Process box Predefined process (subroutine) Input/Output block Program flow arrow Program terminator 2011/12/7 T L Jong, Dept of E.E., NTHU Pseudo Code “ Strict adherence to structure in combination with informal language “ [get a character from the keyboard] “ IF [condition is true] THEN [do statement 1] ELSE BEGIN [do statement 2] [do statement 3] END 2011/12/7 T L Jong, Dept of E.E., NTHU Advantages & Disadvantages of Structured Programming “ Advantages: “ Simple to trace, debug “ Finite number of structures “ Structures as building block “ The set of structure is complete “ Structures are self-documenting, easy to read “ Structures are easy to describe in flowcharts, syntax diagrams, pseudo code, “ Increased program productivity 2011/12/7 T L Jong, Dept of E.E., NTHU Advantages & Disadvantages of Structured Programming “ Disadvantages: “ Only a few high-level languages (Pascal, C, PL/M) accept the structures directly; others require extra translation stage “ Structured program may execute slower and require more memory “ Some problems (a minority) are more difficult to solve using only the three structures “ Nested structures can be difficult to follow 2011/12/7 T L Jong, Dept of E.E., NTHU The Three Structures “ Statements “ [count = 0] “ PRINT_STRING(“Select Option:”) “ Loops (iteration) “ WHILE/DO “ REPEAT/UNTIL “ Choice “ IF/THEN/ELSE “ CASE 2011/12/7 T L Jong, Dept of E.E., NTHU The WHILE/DO Statement WHILE [condition] DO [statement] (statement might not be performed at all!) “ Enter Condition True? WHILE [c == 1] DO [statement] No ENTER: STATEMENT: Yes EXIT: Statement 2011/12/7 JNC EXIT (statement) JMP ENTER (continue) Exit T L Jong, Dept of E.E., NTHU WHILE/DO: SUM Subroutine [sum (A) = 0] WHILE [length (R7) > 0] DO BEGIN [sum = sum + @pointer (R0)] [increment pointer] [decrement length] END 8051 code (closely structured; 13 bytes) (loosely structured; bytes) SUM: CLR A LOOP: CJNZ R7,#0,STAM JMP EXIT STAM: ADD A,@R0 INC R0 DEC R7 JMP LOOP: EXIT: RET SUM: 2011/12/7 CLR INC MORE: DJNZ RET SKIP: ADD INC SJMP T L Jong, Dept of E.E., NTHU A R7 R7,SKIP A,@R0 R0 MORE WHILE/DO Pseudo code: WHILE [ACC != CR AND R7 != 0] DO [statement] Enter ACC != ? 8051 code: ENTER: No Yes No R7 != 0? Yes Statement 2011/12/7 Exit CJNE A,#0DH,SKIP JMP EXIT SKIP: CJNE R7,#0,STAM JMP EXIT STAM: (one or more statements) JMP ENTER EXIT: (continue) T L Jong, Dept of E.E., NTHU 10

Ngày đăng: 13/04/2023, 08:07

Tài liệu cùng người dùng

Tài liệu liên quan