ECE 3430 – Intro to Microcomputer Systems

Slides:



Advertisements
Similar presentations
EET 2261 Unit 6 The Stack; Subroutines
Advertisements

TK 2633 Microprocessor & Interfacing Lecture 3: Introduction to 8085 Assembly Language Programming (2) 1 Prepared By: Associate Prof. Dr Masri Ayob.
Room: E-3-31 Phone: Dr Masri Ayob TK 2633 Microprocessor & Interfacing Lecture 1: Introduction to 8085 Assembly Language.
© 2010 Kettering University, All rights reserved..
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction.
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.
Objectives Implement pointers using indexed addressing modes Use pointers to access arrays, strings, structures, tables, and matrices Present finite-state.
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.
Passing Parameters using Stack Calling program pushes parameters on the stack one element at a time before calling subroutine. Subroutine Call (jsr, bsr)
ELE22MIC Lecture 8 ASll Examples –16 Bit Counters –Buffalo Jump Table Interrupt processing (IRQ/RTI) Stack Frame & Base Pointer Wired OR.
ECE 265 – LECTURE 5 The M68HC11 Basic Instruction Set 12/8/ ECE265.
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction.
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.
Motorola MC68HC811E2 Microcontrollers
1 ECE 372 – Microcontroller Design Assembly Programming HCS12 Assembly Programming Addressing Modes Stack Operations Subroutines.
ECE Lecture 21 Typical Assembly Language Program Bugs.
Advanced Assembly Language Programming
© 2010 Kettering University, All rights reserved..
ECE 447: Lecture 11 Introduction to Programming in Assembly Language.
BRANCHES SUBROUTINES AND MEMORY USAGE AVR Assembler M. Neil - Microprocessor Course 1.
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.
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction.
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.
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction.
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.
EE345 Chapter 2 Lecture 3 April Instruction and addressing modes 1.Extended Addressing 2.Direct Addressing 3.Inherent Addressing 4.Immediate Addressing.
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.
5-1 EE 319K Introduction to Microcontrollers Lecture 5: Conditionals, Loops, Modular Programming, Sub- routines, Parameter passing.
CPEN 231: Microcomputer Architecture and Assembly Programming Lecture 10: Stack and Subroutines John Tadrous, Ph.D. ECE Rice University
EET 2261 Unit 6 The Stack; Subroutines
ECE 3430 – Intro to Microcomputer Systems
ECE 3430 – Intro to Microcomputer Systems
Figure 8.1 of course package
Addressing Modes in Microprocessors
ECE 3430 – Intro to Microcomputer Systems
ECE 3430 – Intro to Microcomputer Systems
ECE 3430 – Intro to Microcomputer Systems
Learning Outcome #1 Architecture and Programming Model
ECE 3430 – Intro to Microcomputer Systems
ECE 3430 – Intro to Microcomputer Systems
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
ECE 3430 – Intro to Microcomputer Systems
“Assembly Table Lookup”
Subroutines … a 1st look procedures and functions in high level languages are modeled on subroutines typically, assembly code is very modular with.
Branching and Looping Lecture L3.2.
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ME4447/6405 Microprocessor Control of Manufacturing Systems and
Graded Quiz #3 Sept. 15, 2017 Clicker [AB]
ECE 3430 – Intro to Microcomputer Systems
ECE 3430 – Intro to Microcomputer Systems
ECE 3430 – Intro to Microcomputer Systems
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ECE 3430 – Intro to Microcomputer Systems
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ECE 447: Lecture 15 Stack Operations.
EET 2261 Unit 6 The Stack; Subroutines
Indexing Through Memory
Some Assembly (Part 2) set.html.
Lecture 3 - Instruction Set - Al
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ECE511: Digital System & Microprocessor
Presentation transcript:

ECE 3430 – Intro to Microcomputer Systems ECE 3430 – Introduction to Microcomputer Systems University of Colorado at Colorado Springs Lecture #12 Agenda Today 1) Subroutines - Parameter Passing Techniques - “Do No Damage” Paradigm Lecture #12 ECE 3430 – Intro to Microcomputer Systems Fall 2009

ECE 3430 – Intro to Microcomputer Systems Subroutines Subroutines - Sub-sections of code that performs specific task. - Modular design flow. - The main program loop contains logical structure of the program. - The subroutines perform the details. - Program design can be divided between multiple engineers. - Subroutines can exist anywhere in memory—but typically they are defined after the main program loop. Memory $E000 : : : Main Subroutine 1 Subroutine 2 Lecture #12 ECE 3430 – Intro to Microcomputer Systems Fall 2009

Subroutines Subroutine Call - The HC11 provides instructions for subroutine calls: BSR <label> Relative addressing. JSR <label> Direct, extended, and indexed addressing. - When these instructions are executed, the following happens: 1) The return address is pushed onto the stack (low byte first, high byte second). The “return address” is the address of the instruction immediately following the BSR or JSR instruction. 2) The program counter (PC) is loaded with the address of the beginning of the subroutine (the address for the subroutine label). $00FD $00FE $00FF SP after JSR/BSR completes XX Return HIGH Return LOW Lecture #12 ECE 3430 – Intro to Microcomputer Systems Fall 2009

ECE 3430 – Intro to Microcomputer Systems Subroutines Subroutine Return - The HC11 provides the following instruction to return from a subroutine: RTS ; return from subroutine - When this instruction is executed, the following happens: 1) The return address is pulled off of the stack (high byte first, low byte second). 2) The program counter (PC) is loaded with the address that was pulled off of the stack. $00FD $00FE $00FF XX Return HIGH SP after RTS completes Return LOW Lecture #12 ECE 3430 – Intro to Microcomputer Systems Fall 2009

ECE 3430 – Intro to Microcomputer Systems Subroutines Subroutine example ORG $E000 LDS #$00FF MAIN: LDAA $40 LDAB $41 BSR ADDEM BRA MAIN ADDEM: ABA RTS END What address is pushed on the stack when BSR is called? Label Addr Data INST $E000 $8E LDS #$00FF $E001 $00 - $E002 $FF - MAIN: $E003 $96 LDAA $40 $E004 $40 - $E005 $D6 LDAB $41 $E006 $41 - $E007 $8D BSR ADDEM $E008 $REL - $E009 $20 BRA MAIN $E00A $REL - ADDEM: $E00B $1B ABA $E00C $39 RTS Lecture #12 ECE 3430 – Intro to Microcomputer Systems Fall 2009

Subroutines Subroutine example ORG $E000 LDS #$00FF MAIN: LDAA $40 LDAB $41 BSR ADDEM BRA MAIN ADDEM: ABA RTS END What address is pushed on the stack when BSR is called? $E009 Label Addr Data INST $E000 $8E LDS #$00FF $E001 $00 - $E002 $FF - MAIN: $E003 $96 LDAA $40 $E004 $40 - $E005 $D6 LDAB $41 $E006 $41 - $E007 $8D BSR ADDEM $E008 $02 - $E009 $20 BRA MAIN $E00A $F8 - ADDEM: $E00B $1B ABA $E00C $39 RTS $00FD $00FE $00FF SP after BSR instruction completes XX $E0 $09 Lecture #12 ECE 3430 – Intro to Microcomputer Systems Fall 2009

Subroutines – Parameter Passing Passing Parameters to Subroutines Parameters can provide input info to a subroutine or receive output info from a subroutine. 1) Use registers/accumulators - Registers and/or accumulators provide additional info to the subroutine. 2) Use the stack - Values pushed on the stack provide additional info to the 3) Use global memory - Reserved memory locations provide additional info to the Lecture #12 ECE 3430 – Intro to Microcomputer Systems Fall 2009

Subroutines – Do No Damage Preserving the Programming Model (Do No Damage Paradigm) If not using registers to pass parameters, it is imperative that subroutines do not inadvertently alter the programming model. In other words, the contents of A, B, X, Y, etc should be the same before and after calling a subroutine. SUB1: PSHA ; do no damage: push everything this subroutine uses PSHB LDAA PORTA LDAB PORTD ABA STAA $0040 PULB ; damage no do: pull everything that was previously pushed PULA RTS This becomes very important when subroutines are calling other subroutines. Lecture #12 ECE 3430 – Intro to Microcomputer Systems Fall 2009

Subroutines – Register/Accumulator Parameter Passing Ex 1) Using registers: Output value to port D: ORG $E000 MAIN: LDAA #10 JSR OUTD DONE: BRA DONE * * Subroutine: Output value to port D OUTD: STAA PORTD RTS Lecture #12 ECE 3430 – Intro to Microcomputer Systems Fall 2009

Subroutines – Stack Parameter Passing Ex 2) Using the stack: Output value to port D: ORG $E000 MAIN: LDAA #10 PSHA ; place input parameter on stack JSR OUTD PULA ; remove input parameter from stack DONE: BRA DONE * * Subroutine: Output value to port D OUTD: PSHA ; do no damage PSHX TSX ; X now points to top stack element LDAA 5,X STAA PORTD PULX ; damage no do PULA RTS Stack $00FA X(high) top $00FB X(low) $00FC A $00FD Ret(high) $00FE Ret(low) $00FF Input val bottom Lecture #12 ECE 3430 – Intro to Microcomputer Systems Fall 2009

Subroutines – Global Memory Parameter Passing Ex 3) Using global memory: Output value to port D: ORG $0040 OUTVAL: RMB 1 ORG $E000 MAIN: LDAA #10 STAA OUTVAL JSR OUTD DONE: BRA DONE * * Subroutine: Output value to port D OUTD: PSHA LDAA OUTVAL STAA PORTD PULA RTS Lecture #12 ECE 3430 – Intro to Microcomputer Systems Fall 2009

Debugging/Utility Library Subroutine Parameters No Parameters: INIT initializes the library PAUSE pause execution until key press DMPREG dump programming model OUTCRLF move cursor to a new line Global Memory Parameter Passing: DMPMEM dump a range of memory (MEMADDR and MEMSIZE) DMPRM DMPREG + DMPMEM Register/Accumulator Parameter Passing: OUTA outputs hexadecimal representation of ACCA SNDBYTE outputs single ASCII character Stack Parameter Passing: INCHAR returns ASCII for key when key pressed (returns ASCII through stack) OUTSTRG outputs a terminated string (needs parameter telling it where string begins) OUTSTRGN outputs a non-terminated string (needs parameters telling it where string begins and how many characters to print) Lecture #12 ECE 3430 – Intro to Microcomputer Systems Fall 2009