Subroutines and Stacks Lecture L3.1. Subroutine and Stacks The System Stack Subroutines A Data Stack.

Slides:



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

Apr. 12, 2000Systems Architecture I1 Systems Architecture I (CS ) Lecture 6: Branching and Procedures in MIPS* Jeremy R. Johnson Wed. Apr. 12, 2000.
EECC250 - Shaaban #1 Lec # 6 Winter Stack-Related Instructions PEA Push Effective Address Calculates an effective address and pushes it.
HCS12 Arithmetic Lecture HC12 Arithmetic Addition and Subtraction Shift and Rotate Instructions Multiplication Division.
Fuzzy Control Lecture 6.1. Fuzzy Control Fuzzy Sets Design of a Fuzzy Controller –Fuzzification of inputs: get_inputs() –Fuzzy Inference –Processing the.
Programming the HC12 in C. Some Key Differences – Note that in C, the starting location of the program is defined when you compile the program, not in.
Chapter 9 & 10 Subroutines and Interrupts. JSR Instruction: JSR offset (11 bit) xxxxxxxxxxx [PC ]  R7, JMP Offset Jump to Subroutine at offset.
EECC250 - Shaaban #1 lec #7 Winter Local workspace of a subroutine: A number of temporary memory locations required by the subroutine for temporary.
COMP3221: Microprocessors and Embedded Systems--Lecture 9 1 COMP3221: Microprocessors and Embedded Systems Lecture 9: Data Transfer Instructions
Chapter 9 Trap Routines TRAP number (go to service routine) & RET (return from service routine) Subroutines (or Functions) JSR offset or JSRR rn (go to.
Faculty of Computer Science © 2006 CMPUT 229 Subroutines (Part 1) The 68K Stack.
Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell Subroutine and Stacks Chapter 2.
CEG411/611 Microprocessor Based System Design What is this course about? Computer : Processor, Memory, I/O Microprocessor versus microcontroller Embedded.
© 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.
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..
9-1 EE 319K Introduction to Microcontrollers Lecture 9:I/O Synchronization; LCD Interfacing; Implementing Local Variables using a Stack Frame; Parameter.
1 Control Abstraction (Section ) CSCI 431 Programming Languages Fall 2003 A compilation of material developed by Felix Hernandez-Campos and Michael.
Number Conversions Lecture L3.4. Number Conversions ASCII Number String to Binary Conversion Binary Number to ASCII String Conversion.
Passing Parameters using Stack Calling program pushes parameters on the stack one element at a time before calling subroutine. Subroutine Call (jsr, bsr)
Computer Architecture Lecture 13 – part 1 by Engineer A. Lecturer Aymen Hasan AlAwady 31/3/2014 University of Kufa - Information Technology Research and.
ELE22MIC Lecture 8 ASll Examples –16 Bit Counters –Buffalo Jump Table Interrupt processing (IRQ/RTI) Stack Frame & Base Pointer Wired OR.
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.
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.
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.
Advanced Assembly Language Programming
Operand Addressing And Instruction Representation Tutorial 3.
© 2010 Kettering University, All rights reserved..
MIPS Subroutines Subroutine Call – jal subname Saves RA in $31 and jumps to subroutine entry label subname Subroutine Return – jr $31 Loads PC with return.
Pushing the Return Address To return to the caller a subroutine must have the correct return address in $ra when the jr instruction is performed. But this.
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.
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.
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.
ELE22MIC Lecture 17 Writing 68HC11 software 68HC11 Main Timer System –Output Compare –What is different about TOC1?
ELE22MIC Lecture 6 Continuation of Lecture 5 Instruction Set Overview, Part 4 –HC-COM - Lab notes –Stack Pointer, Push, Pull Call/return Data –Conditional.
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.
Computer Architecture & Operations I
ECE 3430 – Intro to Microcomputer Systems
Figure 8.1 of course package
Lab 3 - Branching & Subroutines
Computer Science 210 Computer Organization
Branching and Looping Lecture L3.2.
Stack and Subroutines Module M17.1 Section 11.2.
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
Graded Quiz #3 Sept. 15, 2017 Clicker [AB]
The CPU12 Microprocessor Core
Subroutines and the Stack
COMP3221: Microprocessors and Embedded Systems
MIPS functions.
Figure 8.1 of course package
The MOVE Multiple: MOVEM Instruction
Computer Science 210 Computer Organization
Subroutines … passing data
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ECE 447: Lecture 15 Stack Operations.
Lecture 3 - Instruction Set - Al
The Simulator project.
Implementing Functions: Overview
Presentation transcript:

Subroutines and Stacks Lecture L3.1

Subroutine and Stacks The System Stack Subroutines A Data Stack

The System Stack

Pushing D on the stack

1: ; System stack 2: = ORG $4000 3: 4000 CF 08FF LDS #$08FF 4: 4003 CC 1234 LDD #$1234 5: 4006 CD 5678 LDY #$5678 6: B PSHD 7: 400A 35 PSHY 8: 400B 30 PULX 9: 400C 31 PULY 10: 400D 3F SWI What values end up in X and Y?

Subroutine and Stacks The System Stack Subroutines A Data Stack

1: ; Subroutine example 2: 3: 4: = ORG $4000 5: 4000 EX2 6: 4000 CC 1234 LDD #$1234 7: A JSR SUB1 8: JSR SUB2 9: F SWI 10: 11: 400A SUB1 12: 400A C ADDD #$ : 400D JSR SUB2 14: D RTS 15: 16: 4011 SUB2 17: 4011 C ADDD #$ : D RTS

1: ; Subroutine example 2: 3: 4: = ORG $4000 5: 4000 EX2 6: 4000 CC 1234 LDD #$1234 7: A JSR SUB1 8: JSR SUB2 9: F SWI 10: 11: 400A SUB1 12: 400A C ADDD #$ : 400D JSR SUB2 14: D RTS 15: 16: 4011 SUB2 17: 4011 C ADDD #$ : D RTS Stack 4006 D 1234

Stack : ; Subroutine example 2: 3: 4: = ORG $4000 5: 4000 EX2 6: 4000 CC 1234 LDD #$1234 7: A JSR SUB1 8: JSR SUB2 9: F SWI 10: 11: 400A SUB1 12: 400A C ADDD #$ : 400D JSR SUB2 14: D RTS 15: 16: 4011 SUB2 17: 4011 C ADDD #$ : D RTS D 68AC

Stack : ; Subroutine example 2: 3: 4: = ORG $4000 5: 4000 EX2 6: 4000 CC 1234 LDD #$1234 7: A JSR SUB1 8: JSR SUB2 9: F SWI 10: 11: 400A SUB1 12: 400A C ADDD #$ : 400D JSR SUB2 14: D RTS 15: 16: 4011 SUB2 17: 4011 C ADDD #$ : D RTS D 79BD

Stack : ; Subroutine example 2: 3: 4: = ORG $4000 5: 4000 EX2 6: 4000 CC 1234 LDD #$1234 7: A JSR SUB1 8: JSR SUB2 9: F SWI 10: 11: 400A SUB1 12: 400A C ADDD #$ : 400D JSR SUB2 14: D RTS 15: 16: 4011 SUB2 17: 4011 C ADDD #$ : D RTS D 79BD

Stack 1: ; Subroutine example 2: 3: 4: = ORG $4000 5: 4000 EX2 6: 4000 CC 1234 LDD #$1234 7: A JSR SUB1 8: JSR SUB2 9: F SWI 10: 11: 400A SUB1 12: 400A C ADDD #$ : 400D JSR SUB2 14: D RTS 15: 16: 4011 SUB2 17: 4011 C ADDD #$ : D RTS D 79BD

Stack : ; Subroutine example 2: 3: 4: = ORG $4000 5: 4000 EX2 6: 4000 CC 1234 LDD #$1234 7: A JSR SUB1 8: JSR SUB2 9: F SWI 10: 11: 400A SUB1 12: 400A C ADDD #$ : 400D JSR SUB2 14: D RTS 15: 16: 4011 SUB2 17: 4011 C ADDD #$ : D RTS D 79BD

Stack : ; Subroutine example 2: 3: 4: = ORG $4000 5: 4000 EX2 6: 4000 CC 1234 LDD #$1234 7: A JSR SUB1 8: JSR SUB2 9: F SWI 10: 11: 400A SUB1 12: 400A C ADDD #$ : 400D JSR SUB2 14: D RTS 15: 16: 4011 SUB2 17: 4011 C ADDD #$ : D RTS D 8ACE

Stack 1: ; Subroutine example 2: 3: 4: = ORG $4000 5: 4000 EX2 6: 4000 CC 1234 LDD #$1234 7: A JSR SUB1 8: JSR SUB2 9: F SWI 10: 11: 400A SUB1 12: 400A C ADDD #$ : 400D JSR SUB2 14: D RTS 15: 16: 4011 SUB2 17: 4011 C ADDD #$ : D RTS D 8ACE

Saving and restoring registers in a subroutine ;subroutine example subname pshb;save B pshx;save X ;instructions that ----;change B and X ---- pulx;restore X pulb;restore B rts Note that you MUST pull ALL registers that you pushed on the stack

Subroutine and Stacks The System Stack Subroutines A Data Stack

Using X as a stack pointer for a data stack LDY 2,X+ will pop $1234 into Y

Subroutine to add two numbers on the data stack

Subroutine to subtract two numbers on the data stack