; main program ; main move Param2, -(sp) move Param1, -(sp) Call Sub1

Slides:



Advertisements
Similar presentations
680XX Program Examples Outline –Binary to BCD –Matrix Addition –Ones Count –String Compare –Sector Map –Raster Graphics –Subroutine Calls Goal –Understand.
Advertisements

Computer Science 210 Computer Organization Recursive Subroutines System Stack Management.
Solution 2nd Exam.
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.
The University of Adelaide, School of Computer Science
9/20/6Lecture 3 - Instruction Set - Al Instruction Set.
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.
Data Transfer Group ECE 511: Digital System & Microprocessor.
Faculty of Computer Science © 2006 CMPUT 229 Subroutines - Part 2 Calling Itself.
Developing a bicycle speed-o-meter A comparison between the Analog Devices ADSP-BF533 (Blackfin) and Motorola MC68332.
CSCE 212 Quiz 2 – 2/2/11 1.What is the purpose of the jal instruction? 2.What are the two conditional branching (if, goto; not the slt instruction) instructions.
Subroutines and Stacks Lecture L3.1. Subroutine and Stacks The System Stack Subroutines A Data Stack.
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.
EECC250 - Shaaban #1 lec #7 Winter Local workspace of a subroutine: A number of temporary memory locations required by the subroutine for temporary.
CEG 320/520: Computer Organization and Assembly Language ProgrammingThe Stack and Subroutines 1 The Stack and Subroutines.
Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell Subroutine and Stacks Chapter 2.
EECC250 - Shaaban #1 lec #8 Winter Recursive Subroutine Calls Example The purpose of this example is to examine how all parameters, local variables,
CEG 320/520: Computer Organization and Assembly Language ProgrammingFlow Control 1 Flow Control.
CEG 320/520: Computer Organization and Assembly Language ProgrammingIntel Assembly 1 Intel IA-32 vs Motorola
CPE/EE 421 Microcomputers: Motorola 68000: Assembly Language and C Instructor: Dr Aleksandar Milenkovic Lecture Notes.
Chapter 2 Introduction to Computer Architecture and Assembly Language.
Assembly Language Macros Most assemblers include support for macros. The term macro refers to a word that stands for an entire group of instructions. Macro.
Passing Parameters using Stack Calling program pushes parameters on the stack one element at a time before calling subroutine. Subroutine Call (jsr, bsr)
Procedure (Method) Calls Ellen Spertus MCS 111 September 25, 2003.
9/20/6Lecture 2 - Prog Model Architecture, Data Types and 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.
Computer Architecture CSE 3322 Lecture 4 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/10/09
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.
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.
Atari ST workshop 21/1/ Atari ST knowhow Workshop 2: Hardware and software hacks.
EET 2261 Unit 6 The Stack; Subroutines
C Calling Conventions parameters are passed on the run-time or system stack, SP (or A7) parameters pushed on stack in “right to left” order of call A6.
ECE 3430 – Intro to Microcomputer Systems
Figure 8.1 of course package
Slide 7 Mikroprosesor Sub. Algoritma Program___
While Loop While Loop i := 0; x := 2; WHILE i < 100
Subroutines … passing data
Lab 3 - Branching & Subroutines
Stack Frames Stack frame = block of memory located in the system stack that contains: return address input parameters (from calling program to subroutine)
Lecture 3 - Instruction Set - Al
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.
Interfacing with I/O Devices
CPE/EE 421 Microcomputers: Motorola 68000: Assembly Language and C
Int add3 (int a, int b, int c) { return a + b + c; } int sum = 0; main () sum += add3 (1, 2, 3); sum += 10; sum += add3 (10, 20, 30);
Addressing in Jumps jump j Label go to Label op address 2 address
Passing Parameters Data passed to a subroutine is called a parameter.
* M. R. Smith, University of Calgary, Alberta,
Self-modifying Code program intentionally modifies code in the program by overwriting machine code may be used by code designers to obscure branch addresses.
68000 Architecture, Data Types and Addressing Modes
Reentrant Code a reentrant procedure can have several calls open to it at the same time in an interrupt environment, different ISRs may call the same routine.
Write a program to calculate x**y, given x and y.
MIPS functions.
Figure 8.1 of course package
The MOVE Multiple: MOVEM Instruction
Controls, Properties, and Procedures
Subroutines … passing data
Basic Instruction Cycle
Developing a bicycle speed-o-meter
Subroutines and the Stack
EET 2261 Unit 6 The Stack; Subroutines
Program Pass I LC Symbol Table Pass II Machine Code ORG $400
Lecture 3 - Instruction Set - Al
ECE511: Digital System & Microprocessor
The Simulator project.
Lecture 3 - Instruction Set - Al
Presentation transcript:

; main program ; main move Param2, -(sp) move Param1, -(sp) Call Sub1 Level1 move (sp), Result Add #8, sp … SP  R1 R0 Return Level2 Param3 R3 R2 Return Level1 Param1 Param2 Sub1 moveM.l R0-R3, -(sp) move.l Param3, -(sp) …. Call Sub2 Level2 move (sp)+, R2 … move R3, 20(sp) moveM (sp)+, R0-R3 Return Sub2 moveM.l R0-R1, -(sp) …. move 12(sp), R0 … move R1, 12(sp) moveM (sp)+, R0-R1 Return All moves above are longword moves

d0 = 1 Return Level2 d0 = 2 d0 = 3 Return Level1 7000  ; Recursive Subroutine FACTOR ; data equ $6000 program equ $4000 stack equ $7000 org data number dc.w 3 result ds.w 1 org program main movea.w #stack, sp move.w number, d0 bsr FACTOR Level1 move.w d0, result move.w #228, d7 trap #14 FACTOR move.w d0, -(sp) subq.w #1, d0 bne push move.w (sp)+, d0 bra return push bsr FACTOR Level2 mulu (sp)+, d0 return rts end