5-1 EE 319K Introduction to Microcontrollers Lecture 5: Conditionals, Loops, Modular Programming, Sub- routines, Parameter passing.

Slides:



Advertisements
Similar presentations
Ch. 7 Local Variables and Parameter Passing From the text by Valvano: Introduction to Embedded Systems: Interfacing to the Freescale 9S12.
Advertisements

4-1 EE 319K Introduction to Embedded Systems Lecture 4: Arithmetic overflow, Branches, Control Structures, Abstraction & Refinement Bard, Erez, Gerstlauer,
Apr. 12, 2000Systems Architecture I1 Systems Architecture I (CS ) Lecture 6: Branching and Procedures in MIPS* Jeremy R. Johnson Wed. Apr. 12, 2000.
The LC-3 – Chapter 6 COMP 2620 Dr. James Money COMP
Assembler Programming Chapter 6. EEL-4746 Best Practices.
Software engineering, program management. The problem  Software is expensive to design! – Industry estimates put software development labor costs at.
Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell Subroutine and Stacks Chapter 2.
© 2010 Kettering University, All rights reserved..
Stacks and Subroutines ELEC 330 Digital Systems Engineering Dr. Ron Hayne Images Courtesy of Ramesh Gaonkar and Delmar Learning.
Stacks and Subroutines. Some example stacks Stacks and subroutine usage The stack is a special area of the random access memory in the overall memory.
Ch.5 Modular Programming From the text by Valvano: Introduction to Embedded Systems: Interfacing to the Freescale 9S12 Published by CENGAGE, 2010.
9/20/6Lecture 3 - Instruction Set - Al1 Program Design.
ECE 265 – LECTURE 8 The M68HC11 Basic Instruction Set The remaining instructions 10/20/ ECE265.
Physics 413 Chapter 4 A Fork in the Road LDAB # $ 13 here :ADDA # $ 24 DEC B BNE here WAI BNE is the new instruction. Branch if not equal to zero.
© 2010 Kettering University, All rights reserved..
9-1 EE 319K Introduction to Microcontrollers Lecture 9:I/O Synchronization; LCD Interfacing; Implementing Local Variables using a Stack Frame; Parameter.
Lecture 8. MIPS Instructions #3 – Branch Instructions #1 Prof. Taeweon Suh Computer Science Education Korea University 2010 R&E Computer System Education.
11/02/2009CA&O Lecture 03 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
ECE 447: Lecture 12 Logic, Arithmetic, Data Test and Control Instructions of MC68HC11.
6-1 EE 319K Introduction to Microcontrollers Lecture 6: Indexed Addressing Mode and Variants, Functional Debugging, Arrays, Strings.
9/20/6Lecture 3 - Instruction Set - Al1 Program Design Examples.
ECE 265 – LECTURE 5 The M68HC11 Basic Instruction Set 12/8/ ECE265.
1 Stacks, Subroutines, I/O Routines Today: First Hour: Stacks, Subroutines –Section 3.9,3.10 of Huang’s Textbook –In-class Activity #1 Second Hour: I/O.
1 ECE 372 – Microcontroller Design Assembly Programming HCS12 Assembly Programming Addressing Modes Stack Operations Subroutines.
8-1 EE 319K Introduction to Microcontrollers Lecture 8:Fixed Point Numbers, Local Variables, Binding, Allocation, Access, Deallocation.
ECE Lecture 21 Typical Assembly Language Program Bugs.
ECE 447: Lecture 16 Common Errors & Good Programming Style.
EE 319K Introduction to Embedded Systems
Introduction to Computer Engineering ECE/CS 252, Fall 2010 Prof. Mikko Lipasti Department of Electrical and Computer Engineering University of Wisconsin.
Advanced Assembly Language Programming
Problem-solving with Computers. 2Outline  Computer System  5 Steps for producing a computer program  Structured program and programming  3 types of.
© 2010 Kettering University, All rights reserved..
Subroutines and Stacks. Stack The stack is a special area in memory used by the CPU to store register information or general data information during program.
Calling Procedures C calling conventions. Outline Procedures Procedure call mechanism Passing parameters Local variable storage C-Style procedures Recursion.
Preocedures A closer look at procedures. Outline Procedures Procedure call mechanism Passing parameters Local variable storage C-Style procedures Recursion.
Introduction to Computing Systems and Programming Programming.
1 Subroutines Advanced Programming. 2 Top-Down approach to problem solving Algorithm step by step description of how to solve a problem Divide and Conquer.
1 Stack Advanced Programming. 2 The Stack It is a special area of memory used as temporary storage A stack is a LIFO data structure Putting data into.
Revised: Aug 1, EE4390 Microprocessors Lessons 11, 12 Advanced Assembly Programming.
Stacks and Subroutines May 23. Stacks and subroutine usage The stack is a special area of the random access memory in the overall memory system The stack.
CPEN 231: Microcomputer Architecture and Assembly Programming Lecture 10: Stack and Subroutines John Tadrous, Ph.D. ECE Rice University
Deeper Assembly: Addressing, Conditions, Branching, and Loops
ECE 3430 – Intro to Microcomputer Systems
Learning Outcome #1 Architecture and Programming Model
Control Structure Applications
ECE 3430 – Intro to Microcomputer Systems
Macros and Structured Programming
ECE 3430 – Intro to Microcomputer Systems
ECE 3430 – Intro to Microcomputer Systems
Decision Making.
Lab 3 - Branching & Subroutines
“Assembly Table Lookup”
Control Structure Applications
ARM Assembly Programming
Program Design Examples
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
Graded Quiz #3 Sept. 15, 2017 Clicker [AB]
Algorithm An algorithm is a finite set of steps required to solve a problem. An algorithm must have following properties: Input: An algorithm must have.
Passing Parameters Data passed to a subroutine is called a parameter.
The University of Adelaide, School of Computer Science
Write a program to calculate x**y, given x and y.
Review.
The University of Adelaide, School of Computer Science
ECE 3430 – Intro to Microcomputer Systems
ECE 447: Lecture 15 Stack Operations.
EET 2261 Unit 6 The Stack; Subroutines
Process.
ECE511: Digital System & Microprocessor
An Introduction to the ARM CORTEX M0+ Instructions
Lecture 3 - Instruction Set - Al
Presentation transcript:

5-1 EE 319K Introduction to Microcontrollers Lecture 5: Conditionals, Loops, Modular Programming, Sub- routines, Parameter passing

5-2 Ramesh Yerraballi Conditionals > < ≥ ≤ conditional branch instructions must follow a subtract compare or test instruction, such as  suba subb sbca sbcb subd cba cmpa cmpb cpd cpx cpy tsta tstb tst Equality/Inequality check

5-3 Ramesh Yerraballi Signed Conditional bge target ; Branch if signed greater than or equal to (), ;if (N^V)=0, or (~N.V+N.~V)=0 bgt target ; Branch if signed greater than (>), ;if (Z+N^V)=0, or (Z+~N.V+N.~V)=0 ble target ; Branch if signed less than or equal to (), ;if (Z+N^V)=1, or (Z+~N.V+N.~V)=1 blt target ; Branch if signed less than (<), ;if (N^V)=1, or (~N.V+N.~V)=1

5-4 Ramesh Yerraballi … Signed Conditional , checks

5-5 Ramesh Yerraballi Unsigned Conditional bhs target ; Branch if unsigned greater than or equal to (), ;if C=0, same as bcc bhi target ; Branch if unsigned greater than (>), ;if C+Z=0 bls target ; Branch if unsigned less than or equal to (), ;if C+Z=1 blo target ; Branch if unsigned less than (<), ;if C=1,same as bcs

5-6 Ramesh Yerraballi … Unsigned Conditional , checks

5-7 Ramesh Yerraballi Problem Solving When we solve problems on the computer, we need to answer these questions:  What does being in a state mean? List state parameters  What is the starting state of the system?Define the initial state  What information do we need to collect?List the input data  What information do we need to generate?List the output data  How do we move from one state to another? Actions we could do  What is the desired ending state?Define the ultimate goal

5-8 Ramesh Yerraballi Successive Refinement  Start with a task and decompose the task into a set of simpler subtasks  Subtasks are decomposed into even simpler sub-subtasks.  Each subtask is simpler than the task itself.  Make design decisions  Subtask is so simple, it can be converted to software code.

5-9 Ramesh Yerraballi Decomposition “do A then do B” → sequential “do A and B in either order” → sequential “if A, then do B” → conditional “for each A, do B” → iterative “do A until B” → iterative “repeat A over & over forever” → iterative (condition always true) ‏ “on external event do B” → interrupt “every t msec do B” → interrupt

5-10 Ramesh Yerraballi Successive Refinement: Example

5-11 Ramesh Yerraballi if-then-else Two alternative implementations

5-12 Ramesh Yerraballi while loop

5-13 Ramesh Yerraballi for loop

5-14 Ramesh Yerraballi Modular Design  Goal  Clarity  Create a complex system from simple parts  Definition of modularity  Maximize number of modules  Minimize bandwidth between them  Entry point (where to start)  The label of the first instruction of the subroutine  Exit point (where to end)  The rts instruction  Good practice, one rts as the last line

5-15 Ramesh Yerraballi Modular Design  Public (shared, called by other modules)  Add underline in the name, module name before  Private (not shared, called only within this module)  No underline in the name  Helper functions  Coupling (amount of interaction between modules)  Data passed from one to another (bandwidth)  Synchronization between modules

5-16 Ramesh Yerraballi Subroutines and the Stack classical definition of the stack  push saves data on the top of the stack,  pull removes data from the top of the stack  stack implements last in first out (LIFO) behavior  stack pointer (SP) points to top element many uses of the stack  temporary calculations  subroutine (function) return addresses  subroutine (function) parameters  local variables  psha push Register A on the stack  pshb push Register B on the stack  pshx push Register X on the stack  pshy push Register Y on the stack  desS=S-1(reserve space)  pula pull from stack into A  pulb pull from stack into B  pulx pull from stack into X  puly pull from stack into Y  insS=S+1 (discard top of stack)

5-17 Ramesh Yerraballi Registers to pass parameters Subroutine 3) Sees the inputs in registers 4) Performs the action of the subroutine 5) Places the outputs in registers High level program 1)Sets Registers to contain inputs 2)Calls subroutine 6) Registers contain outputs

5-18 Ramesh Yerraballi Introduction to Pointers Pointers are addresses pointing to objects. The objects may be data, functions, or other pointers: If register X or Y contains an address we say it points into memory

5-19 Ramesh Yerraballi Use of Index registers

5-20 Ramesh Yerraballi Functional Debugging Pt = Buf;ldx #Buf stx Pt Pt will point into the buffer. Pt must be initialized to point to the beginning, before the debugging begins. #define SIZE 20 unsigned char Buf[SIZE]; unsigned char *Pt; SIZE equ 20 Buf rmb SIZE Pt rmb 2 Instrumentation: dump into array without filtering Assume happy is strategic 8-bit variable.

5-21 Ramesh Yerraballi … Functional Debugging Next, you add jsr Save statements at strategic places within the system. Use the debugger to display the results after program is done void Save(void){ if(Pt < &Buf[SIZE]){ (*Pt) = happy; Pt++; } Save pshb pshx ;save ldx Pt ;X=>Buf cpx #Buf+SIZE bhs done ;skip if full ldab happy stab 0,X ;save happy inx ;next address stx Pt done pulx pulb rts The debugging instrument saves the strategic variable into the Buffer.