© 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

1 Lecture 3: MIPS Instruction Set Today’s topic:  More MIPS instructions  Procedure call/return Reminder: Assignment 1 is on the class web-page (due.
Review of the MIPS Instruction Set Architecture. RISC Instruction Set Basics All operations on data apply to data in registers and typically change the.
Slides revised 3/25/2014 by Patrick Kelley. 2 Procedures Unlike other branching structures (loops, etc.) a Procedure has to return to where it was called.
1 Procedure Calls, Linking & Launching Applications Lecture 15 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
ECE 232 L6.Assemb.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 6 MIPS Assembly.
1 Lecture 4: Procedure Calls Today’s topics:  Procedure calls  Large constants  The compilation process Reminder: Assignment 1 is due on Thursday.
Procedure Calls Prof. Sirer CS 316 Cornell University.
Lecture 6: MIPS Instruction Set Today’s topic –Control instructions –Procedure call/return 1.
ELEN 468 Advanced Logic Design
Instruction Set Architecture Classification According to the type of internal storage in a processor the basic types are Stack Accumulator General Purpose.
Computer Architecture CSCE 350
The University of Adelaide, School of Computer Science
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..
Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 41 Today’s class More assembly language programming.
Instruction Set Architecture & Design
© 2010 Kettering University, All rights reserved..
Execution of an instruction
MIPS Assembly Language I Computer Architecture CPSC 321 Andreas Klappenecker.
EECC250 - Shaaban #1 Lec # 5 Winter Stacks A stack is a First In Last Out (FILO) buffer containing a number of data items usually implemented.
Subroutines and Stacks Lecture L3.1. Subroutine and Stacks The System Stack Subroutines A Data Stack.
© 2010 Kettering University, All rights reserved..
CEG 320/520: Computer Organization and Assembly Language ProgrammingIntel Assembly 1 Intel IA-32 vs Motorola
© 2010 Kettering University, All rights reserved..
© 2010 Kettering University, All rights reserved..
Computer Architecture and the Fetch-Execute Cycle
ECE 265 – LECTURE 8 The M68HC11 Basic Instruction Set The remaining instructions 10/20/ ECE265.
COP4020 Programming Languages Subroutines and Parameter Passing Prof. Xin Yuan.
© 2010 Kettering University, All rights reserved..
Execution of an instruction
ECE 447: Lecture 12 Logic, Arithmetic, Data Test and Control Instructions of MC68HC11.
Lecture 4: MIPS Instruction Set
Microprocessors The ia32 User Instruction Set Jan 31st, 2002.
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction.
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.
Addressing Modes MTT CPU08 Core Motorola CPU08 ADDRESSING MODES.
1 ECE 372 – Microcontroller Design Assembly Programming HCS12 Assembly Programming Addressing Modes Stack Operations Subroutines.
ECE Lecture 21 Typical Assembly Language Program Bugs.
Topics covered: Instruction Set Architecture CSE243: Introduction to Computer Architecture and Hardware/Software Interface.
© 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.
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.
LECTURE 19 Subroutines and Parameter Passing. ABSTRACTION Recall: Abstraction is the process by which we can hide larger or more complex code fragments.
5-1 EE 319K Introduction to Microcontrollers Lecture 5: Conditionals, Loops, Modular Programming, Sub- routines, Parameter passing.
Addressing Modes in Microprocessors
ECE 3430 – Intro to Microcomputer Systems
Assembly Language Programming of 8085
ECE 3430 – Intro to Microcomputer Systems
ARM Registers Register – internal CPU hardware device that stores binary data; can be accessed much more rapidly than a location in RAM ARM has.
Procedures 101: There and Back Again
ELEN 468 Advanced Logic Design
ECE 3430 – Intro to Microcomputer Systems
A Closer Look at Instruction Set Architectures
ME4447/6405 Microprocessor Control of Manufacturing Systems and
Application Binary Interface (ABI)
MIPS Instructions.
The University of Adelaide, School of Computer Science
The University of Adelaide, School of Computer Science
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
by Richard P. Paul, 2nd edition, 2000.
Procedures and Calling Conventions
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
COMS 361 Computer Organization
An Introduction to the ARM CORTEX M0+ Instructions
Presentation transcript:

© 2010 Kettering University, All rights reserved.

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

Announcements Midterm result  Average:  Standard Dev:  Maximum: 95  Minimum: 41 Update grades on Blackboard  Q1, Q2, Q3, and Midterm  Lab1, Lab2, Lab3, and Practical exam Question 1, 2, and 3 in Lab2  I intended to have actual assembly code.  Questions were not clearly specified.  I will accept proper explanations as a right answer.  Feel free to stop by my office after this class.

Midterm Review 1. Branch instructions  BHI (unsigned), BGT (signed) Take a look at the preceding comparison instruction. Then, you can use this instead of using complex formula in the instruction reference.  BRANCH IF REGISTER IS HIGHER/GREATHER/… THAN OPERAND e.g. CMPA #$D0  Branch if ‘A’ is HIgher than ‘operand.’  BMI, BVC, BNE Check the result if it is Minus/signed oVerflow/Not Equal to zero  CMPA: A – (M)  TSTA: A – 0  V bit (signed overflow) N + N  P P + P  N N – P  P P – N  N

Midterm Review – cont’d 2. BRA and LBRA  Write a line of assembly code that begins in memory location $2450.  BRA  LBRA  When the effective (destination) address is calculated in relative addressing mode, a value that you need to add to an offset is PC.  We have to use PC which is the next address of the line of assembly code of (L)BRA

Midterm Review 3. Mostly this is about calculating postbyte(s)  -20: You cannot use 5-bit offset. You have to use 9-bit one.

Lecture 16: Parameter Passing

Today’s Goals Parameter passing Understand how to pass parameters using the stack

Call by Value vs. Call by Reference Main Program Subroutine Value Subroutine Address Memory Look for values

Passing Parameters in Registers Use registers to pass parameters The simplest type of parameter passing Pros vs. Cons  Data is immediately available to the subroutine  No extra preparations are needed.  Often fastest execution and smallest code size  Only a limited number of registers are available.  We can use ‘pass-by-reference’ to point a list of input/output values.

Example (Parameter Passing in Registers) Requirements  A subroutine that adds an array of two-byte numbers and a sample main program that calls it.  The array is passed by reference in X.  The length is passed by value in D.  The sum should be returned by value in D.  Do not worry about indicating signed or unsigned overflow.

Example (Parameter Passing in Registers) ORG $3000 Arraydc.w$1234,$5678,$ABCD Lengthdc.w3 ORG$2000 LDS#$3600 LDX#Array ; load X with address of list LDDLength; Load D with actual length JSRsumword SWI sumwordTFRD,Y LDDD#0 CPY#0 LoopBEQendsum ADDD0,X INX DEY BRAloop endsumRTS

Preserving Registers In the previous example, the subroutine uses Y. The value in Y is destroyed. If Y was in use by the main program, the main program would continue after the subroutine with an incorrect value in Y. To avoid this, registers used by a subroutine may be saved to the stack before a subroutine uses them. The saved registers are restored after the subroutine. We have two options  The caller (main program) does this.  The callee (subroutine) does this.

Preserving Registers Responsibility of the Caller:  The calling main program assumes all registers are destroyed by the subroutine  If the registers used by the subroutine are unknown (i.e. using a sub. provided by someone else), may save registers that the subroutine wouldn’t affect  Code to save/restore registers duplicated with every subroutine call. Responsibility of the Callee:  Saves only the registers that will be used by the subroutine  Save/restore code only occurs once

Example – Caller Responsible ORG $3000 Arraydc.w$1234,$5678,$ABCD Lengthdc.w3 ORG$2000 LDS#$3600 LDX#Array ; load X with address of list LDDLength; Load D with actual lengthPSHX JSRsumword PULX SWI sumwordTFRD,Y LDDD#0 CPY#0 loopBEQendsum ADDD0,X INX DEY BRAloop endsumRTS RAH RAL XH XL Stack Frame

Example – Callee Responsible ORG $3000 Arraydc.w$1234,$5678,$ABCD Lengthdc.w3 ORG$2000 LDS#$3600 LDX#Array ; load X with address of list LDDLength; Load D with actual length JSRsumword SWI PSHX sumwordPSHXPSHY TFRD,Y LDDD#0 CPY#0 loopBEQendsum ADDD0,X INX DEY BRAloop PULY endsumPULYPULX RTS XH XL RAH RAL YH YL Stack Frame Why not D? It is used to return the answer! Why not D? It is used to return the answer!

Passing Parameters in the Stack Pros and Cons  The stack pointer is already in use for the return address  Indexed addressing can easily access data stored on the stack  The amount of data passed is not limited by the register set  The data passed on the stack must be removed, and this is usually the responsibility of the caller (although this can be done by the callee) Note:  If the caller will save registers on the stack, it should be done before passing parameters.  Why? Those parameters are supposed to be used in the subroutine.

Example – Param Passing in the Stack ORG $3000 Arraydc.w$1234,$5678,$ABCD Lengthdc.w3 ORG$2000 LDS#$3600 LDX#$1234; something to save PSHX LDDLength PSHD LDD#Array PSHD JSRsumword LEAS4,SP PULX SWI sumwordLDDD#0 LDX2,SP LDY4,SP LoopBEQendsum ADDD0,X INX DEY BRAloop endsumRTS ArrH ArrL LenH LenL RetH RetL Stack Frame XH XL

Questions?

Wrap-up Parameter Passing Pros and Cons of each method What we’ve learned

What to Come More about subroutines