© 2010 Kettering University, All rights reserved..

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

EET 2261 Unit 6 The Stack; Subroutines
Lecture 20: 11/12/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
ECE 232 L6.Assemb.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 6 MIPS Assembly.
Stack Frames: Using LINK. CEG 320/5208: Stack frames and LINK2 Assembling source code One source file: –Use ORG statements for data and code –Assemble.
Computer Architecture CSCE 350
EECC250 - Shaaban #1 Lec # 6 Winter Stack-Related Instructions PEA Push Effective Address Calculates an effective address and pushes it.
© 2010 Kettering University, All rights reserved..
© 2010 Kettering University, All rights reserved..
© 2010 Kettering University, All rights reserved..
© 2010 Kettering University, All rights reserved..
© 2010 Kettering University, All rights reserved..
Software engineering, program management. The problem  Software is expensive to design! – Industry estimates put software development labor costs at.
Subroutines and Stacks Lecture L3.1. Subroutine and Stacks The System Stack Subroutines A Data Stack.
Overview C programming Environment C Global Variables C Local Variables Memory Map for a C Function C Activation Records Example Compilation.
EECC250 - Shaaban #1 lec #7 Winter Local workspace of a subroutine: A number of temporary memory locations required by the subroutine for temporary.
C Stack Frames / Pointer variables Stack: Local Variables Pass & Return values Frame Ptr linkage (R5) and PC linkage (R7) Pointer Variables: Defining &
EECC250 - Shaaban #1 lec #8 Winter Recursive Subroutine Calls Example The purpose of this example is to examine how all parameters, local variables,
© 2010 Kettering University, All rights reserved..
© 2010 Kettering University, All rights reserved..
© 2010 Kettering University, All rights reserved..
© 2010 Kettering University, All rights reserved..
Lecture 4: Advanced Instructions, Control, and Branching cont. EEN 312: Processors: Hardware, Software, and Interfacing Department of Electrical and Computer.
© 2010 Kettering University, All rights reserved..
Computer Architecture Lecture 13 – part 2 by Engineer A. Lecturer Aymen Hasan AlAwady 7/4/2014 University of Kufa - Information Technology Research and.
13/02/2009CA&O Lecture 04 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
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.
Today’s topics Parameter passing on the system stack Parameter passing on the system stack Register indirect and base-indexed addressing modes Register.
Programming Language Principles Lecture 24 Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Subroutines.
© 2010 Kettering University, All rights reserved..
1 Control Abstraction (Section ) CSCI 431 Programming Languages Fall 2003 A compilation of material developed by Felix Hernandez-Campos and Michael.
Procedure Calls and the Stack (Lectures #18) ECE 445 – Computer Organization The slides included herein were taken from the materials accompanying Computer.
© 2010 Kettering University, All rights reserved..
MAL 3 - Procedures Lecture 13. MAL procedure call The use of procedures facilitates modular programming. Four steps to transfer to and return from a procedure:
Subroutines, parameters and the stack Bryan Duggan.
MicroComputer Engineering IntroLab1 page 1 Introduction Lab1  A crash course in assembler programming  Learn how a processor works!  Decode a coded.
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.
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.
4-1 Embedded Systems C Programming Language Review and Dissection II Lecture 4.
Advanced Assembly Language Programming
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.
Preocedures A closer look at procedures. Outline Procedures Procedure call mechanism Passing parameters Local variable storage C-Style procedures Recursion.
10/1: Lecture Topics Conditional branch instructions –slides from 9/29 set Unconditional jump instructions Instruction encoding.
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.
Revised: Aug 1, EE4390 Microprocessors Lessons 11, 12 Advanced Assembly Programming.
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text.
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
Storage Classes There are three places in memory where data may be placed: In Data section declared with .data in assembly language in C - Static) On the.
ECE 3430 – Intro to Microcomputer Systems
ECE 3430 – Intro to Microcomputer Systems
Subroutines and the Stack
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ECE 3430 – Intro to Microcomputer Systems
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
Subroutines … passing data
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
Subroutines and the Stack
EET 2261 Unit 6 The Stack; Subroutines
Lecture 3 - Instruction Set - Al
Lecture 3 - Instruction Set - Al
Presentation transcript:

© 2010 Kettering University, All rights reserved.

Microcomputers I – CE 320 Electrical and Computer Engineering Kettering University Jaerock Kwon, Ph.D.

Announcements Midterm on Monday  Up to Lecture 13.  Exercises (1~4) and Quizzes (1~3) will be greatly helpful. About Lab programming assignments  Working together and discussing assignments are OK.  Write code individually even in a group. From now on … From now on …  DO NOT share your code with others.  If so, your demonstration may be ignored (0 pt out of 50 pts).  No more simply copied or slightly modified code will be accepted

Lecture 15: Subroutines

Today’s Topics What is subroutines? Learn how to call subroutines from an assembly program. Learn the properties of well-written subroutines. Learn what are pass-by-reference and pass-by-value.

What is Subroutines? A subroutine in a self-contained section of code that implements a specific function that can be called from many different places. Reasons why we use subroutines  Save memory The amount of memory required to store a program is reduced if the code to implement a function is stored only once instead of each time the function is needed in the program.  Improve reusability of code Functions implemented subroutines are often easier to insert into future programs for code reuse.  Better organization A complicated program can be more organized with subroutines. Execution time increases and code size may increase as well. A definition of subroutines

Need Something for Subroutine Operation Let’s take a look at this code. ORG$2000 LDAA#17; 2000 BRAMagA; 2002 Ret1STAA$1000; 2004 LDAA#-1; 2007 BRAMagA; 2009 Ret2STAA$1001; 200B SWI; 200E ; Subroutine MagA ; compute magnitude of a single byte number ; input: byte in register A ; output: magnitude returned in register A ORG$2200 MagATSTA BPLreturn NEGA ????? ReturnBRA ?????

Subroutine Instructions JSR (Jump Sub Routine)  Pushes two-byte address of the next line of code on the stack first.  Jump/Branch to the subroutine. RTS (ReTurn from Subroutine)  Pulls two bytes off the stack and jumps to that address. JSR and RTS

Example for Subroutines ORG$2000 LDS#$3600; 2000 LDAA#17; 2003 Jsr1JSRMagA; 2005 Ret1STAA$1000; 2008 LDAA#-1; 200B Jsr2JSRMagA; 200D Ret2STAA$1001; 2010 SWI; 2013 ; compute magnitude of a single byte number ; input: byte in register A ; output: magnitude returned in register A MagATSTA BPLreturn NEGA ReturnRTS 35FD 35FE 35FF 3600 SP 35FD 35FE 35FF 3600 SP 35FD 35FE 35FF 3600 SP 35FD 35FE 35FF 3600 SP After Return After Jsr1 After Jsr2 After Return XX XX 35FE 35FD 35FE 35FF 3600 SP XX FD 35FE 35FF 3600 SP XX XX 35FE 35FD 35FE 35FF 3600 SP XX FD 35FE 35FF 3600 SP After Return After Jsr1 After Jsr2 After Return

Nesting Subroutines ORG$2000 LDS#$3600; 2000 LDAA#17; 2003 LDAB#-1; 2005 JsrABJSRMagAB; 2007 SWI; 200A MagABJSRMagA; 200B PSHA1PSHA; 200E TFRB,A; 200F JSR1JSRMagA; 2011 TFRA,B; 2014 PULA1PULA; 2016 RTS1RTS; 2017 MagATSTA; 2018 BPLreturn; 2019 NEGA; 201B ReturnRTS; 201C 35FD 35FE 35FF 3600 SP 35FD 35FE 35FF 3600 SP 35FD 35FE 35FF 3600 SP 35FD 35FE 35FF 3600 SP After MagAB After JsrAB After Return After PSHA1 35FC 35FB XX 20 0A XX 35FE 35FD 35FE 35FF 3600 SP 0E 20 0A XX 35FC 35FD 35FE 35FF 3600 SP XX 20 0A XX 35FE 35FD 35FE 35FF 3600 SP A XX 35FD 35FE 35FF 3600 SP After MagAB After JsrAB After Return After PSHA1 XX 35FC 20 35FC XX 35FC XX 35FC XX 35FB XX 35FB XX 35FB XX 35FB

Nesting Subroutines –cont’d ORG$2000 LDS#$3600; 2000 LDAA#17; 2003 LDAB#-1; 2005 JsrABJSRMagAB; 2007 SWI; 200A MagABJSRMagA; 200B PSHA1PSHA; 200E TFRB,A; 200F JSR1JSRMagA; 2011 TFRA,B; 2014 PULA1PULA; 2016 RTS1RTS; 2017 MagATSTA; 2018 BPLreturn; 2019 NEGA; 201B ReturnRTS; 201C 35FD 35FE 35FF 3600 SP 35FD 35FE 35FF 3600 SP 35FD 35FE 35FF 3600 SP 35FD 35FE 35FF 3600 SP After Return After Jsr1 After PULA1 After RTS1 35FC 35FB A XX 35FB 35FD 35FE 35FF 3600 SP A XX 35FD 35FE 35FF 3600 SP XX 20 0A XX 35FE 35FD 35FE 35FF 3600 SP XX FD 35FE 35FF 3600 SP After Return After Jsr1 After PULA1 After RTS FC XX 35FC XX 35FC XX 35FC 20 35FB XX 35FB XX 35FB XX 35FB

Well-written Subroutines** One entry point One exit point One specific function One returned object Use the stack to store local variables Use the Stack for local Specific function Return one object Use the Stack for local Specific function Return one object One entry One exit

Parameter Passing Pass-by-value  The data itself is passed Pass-by-reference  The address of the data is passed

Questions?

Wrap-up Subroutines JSR, RTS What we’ve learned

What to Come Parameter passing