© 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
1/1/ / faculty of Electrical Engineering eindhoven university of technology Introduction Part 2: Data types and addressing modes dr.ir. A.C. Verschueren.
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson slides3.ppt Modification date: March 16, Addressing Modes The methods used in machine instructions.
SOFTWARE ARCHITECTURE OF THE 8088 AND 8086 MICROPROCESSORS
© 2010 Kettering University, All rights reserved..
Stacks, Queues, and Deques. 2 A stack is a last in, first out (LIFO) data structure Items are removed from a stack in the reverse order from the way they.
© 2010 Kettering University, All rights reserved..
Lecture 6 Machine Code: How the CPU is programmed.
© 2010 Kettering University, All rights reserved..
S. Barua – CPSC 240 CHAPTER 10 THE STACK Stack - A LIFO (last-in first-out) storage structure. The.
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.
EET 2261 Unit 2 HCS12 Architecture
© 2010 Kettering University, All rights reserved..
Data Structures Data structures permit the storage of related data for use in your program. –Arrays.
© 2010 Kettering University, All rights reserved..
Module 10 Adapted By and Prepared James Tan © 2001.
CS-280 Dr. Mark L. Hornick 1 Calling subroutines in assembly And using the Stack.
Chapter 10 And, Finally... The Stack. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Stacks A LIFO.
Chapter 10 The Stack Stack: An Abstract Data Type An important abstraction that you will encounter in many applications. We will describe two uses:
CS-2710 Dr. Mark L. Hornick 1 Defining and calling procedures (subroutines) in assembly And using the Stack.
Dr. José M. Reyes Álamo 1.  The 80x86 memory addressing modes provide flexible access to memory, allowing you to easily access ◦ Variables ◦ Arrays ◦
© 2010 Kettering University, All rights reserved..
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.
ECE 265 – LECTURE 8 The M68HC11 Basic Instruction Set The remaining instructions 10/20/ ECE265.
© 2010 Kettering University, All rights reserved..
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..
Computer Architecture Lecture 13 – part 1 by Engineer A. Lecturer Aymen Hasan AlAwady 31/3/2014 University of Kufa - Information Technology Research and.
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction.
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.
The x86 Instruction Set Lecture 16 Mon, Mar 14, 2005.
Instruction Sets: Addressing modes and Formats Group #4  Eloy Reyes  Rafael Arevalo  Julio Hernandez  Humood Aljassar Computer Design EEL 4709c Prof:
Advanced Assembly Language Programming
2005MEE Software Engineering Lecture 7 –Stacks, Queues.
© 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.
Assembly Language Data Movement Instructions. MOV Instruction Move source operand to destination mov destination, source The source and destination are.
CSC 221 Computer Organization and Assembly Language Lecture 15: STACK Related Instructions.
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction.
Physics 413 Chapter 4: Advanced Assembly 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.
Microprocessors CSE- 341 Dr. Jia Uddin Assistant Professor, CSE, BRAC University Dr. Jia Uddin, CSE, BRAC University.
Intel MP Organization. Registers - storage locations found inside the processor for temporary storage of data 1- Data Registers (16-bit) AX, BX, CX, DX.
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
EET 2261 Unit 6 The Stack; Subroutines
G.PULLAIAH COLLEGE OF ENGINEERING AND TECHNOLOGY
ECE 3430 – Intro to Microcomputer Systems
ECE 3430 – Intro to Microcomputer Systems
The Stack.
ECE 3430 – Intro to Microcomputer Systems
Microcomputer Programming
Overview Introduction General Register Organization Stack Organization
In this lecture Global variables Local variables System stack
The Stack.
Arithmetic using a stack
Stack and Subroutines Module M17.1 Section 11.2.
Subroutines and the Stack
EE6502/MPMC/UNIT II/STACK AND SUBROUTINE/T.THARANKUMAR
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
8051 ASSEMBLY LANGUAGE PROGRAMMING
EET 2261 Unit 6 The Stack; Subroutines
Stacks, Queues, and Deques
Computer Organization and Assembly Language
(The Stack and Procedures)
Presentation transcript:

© 2010 Kettering University, All rights reserved.

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

Announcements Quiz 3 result  Average:  Standard Deviation: 7.78  Range: 66 ~ 99

Lecture 14: Stack

Today’s Goals Learn how HCS12 stack functions

What is the Stack? The stack is a last-in, first-out (LIFO) data structure. Two fundamental operations  Push: add to the top of the list  Pop/Pull: removes an item from the top of the list. Temporary variable storage  When subroutines are called. Think books stacked on a table c.f. Queue  First-in, first-out (FIFO) data structure Last in, First out (LIFO)

The Stack Memory diagram of a stack Available Stack Space Used Stack Space Top of Stack Bottom of Stack 35FF 3400 First item placed onto the stack Last item placed onto the stack First item that can be removed from the stack Last item that can be removed from the stack

Important Concepts about Stacks A regular RAM section will be used. No hardware enforces this boundary. Much like variable-length array The stack grows toward lower addresses when a value is added. SP (Stack Pointer register) holds the address of the current index of the stack.  SP moves up (decrements) when an item is added  SP moves down (increments) when an item is removed  Note: Addition/Removal happens after SP moves up/down  All bytes in the stack space that are located at addresses lower than SP are considered unused

Important Concepts about Stacks Depth:  the number of bytes stored on the stack Empty:  If the depth is 0, we say the stack is empty. Underflow  Removing a byte from an empty stack Overflow  The depth is larger than the available stack space

Manipulating the Stack and SP PSHx  Push an item to the stack  X: A, B, C(CCR), D, X, Y 1.S register is first decremented by the number of bytes to be pushed, 2.then the value from the register is copied into the memory indicated by S. PULx  Pull or Pop an item from the stack  X: A, B, C(CCR), D, X, Y  One or two bytes (depends on the size of the register) at the top of the stack is/are copied into the specified register,  then S is incremented Note: PSHx and PULx (except for PULC) do not affect on CCR bits Again, there is no separate space for the stack. The stack is just a chunk of RAM. S register holds the current position. Adding/Removing an item to a stack

Manipulating the Stack and SP LDS  Load the stack pointer  Typically use only immediate addressing mode.  Typically initialize the pointer at the beginning of a program. LEAS  Remember LEAX and LEAY?  Load Effective Address into S register  This is useful to manipulate stack pointer without pushing/popping values.  With negative offsets, create space on the top of the stack  With positive offsets, removes data from the top of the stack

Examples Example 1 1: LDS #$3600 2: LDAA #$AA 3: LDAB #$BB 4: PSHA 5: PSHB 6: PULA 7: PULB 35FD 35FE 35FF 3600 SP 35FD 35FE 35FF 3600 SP 35FD 35FE 35FF 3600 SP 35FD 35FE 35FF 3600 SP After Line 4 35FD 35FE 35FF 3600 SP After Line 1 After Line 5 After Line 6 After Line 7 XX FD 35FE 35FF 3600 SP XX AA XX 35FF 35FD 35FE 35FF 3600 SP XX BB AA XX 35FE 35FD 35FE 35FF 3600 SP XX AA XX 35FF 35FD 35FE 35FF 3600 SP After Line 4 XX FD 35FE 35FF 3600 SP After Line 1 After Line 5 After Line 6 After Line 7

Examples Example 2 1:LDS #$3600 2:LDAA #$AA 3:LDAB #$BB 4:PSHD 5: LDD #$CCDD 6:LEAS 2,SP 35FD 35FE 35FF 3600 SP 35FD 35FE 35FF 3600 SP 35FD 35FE 35FF 3600 SP 35FD 35FE 35FF 3600 SP After Line 4 After Line 1 After Line 5 After Line 6 XX FD 35FE 35FF 3600 SP XX AA BB XX 35FE 35FD 35FE 35FF 3600 SP XX AA BB XX 35FE 35FD 35FE 35FF 3600 SP XX FD 35FE 35FF 3600 SP After Line 4 After Line 1 After Line 5 After Line 6

Questions?

Wrap-up Stack PUSx, PULx, LDS, LEAS What we’ve learned

What to Come Subroutines