Figure 8.1 of course package

Slides:



Advertisements
Similar presentations
Procedures 2 Intructions Supporting Procedures Making Use of a Stack.
Advertisements

Introduction to Computer Engineering ECE 252, Fall 2010 Prof. Mikko Lipasti Department of Electrical and Computer Engineering University of Wisconsin –
CPU Review and Programming Models CT101 – Computing Systems.
Chapter 9 TRAP Routines and Subroutines. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 9-2 Subroutines.
There are two types of addressing schemes:
9/20/6Lecture 3 - Instruction Set - Al Instruction Set.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
EECC250 - Shaaban #1 Lec # 6 Winter Stack-Related Instructions PEA Push Effective Address Calculates an effective address and pushes it.
Chapter 6: Machine dependent Assembler Features
Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 41 Today’s class More assembly language programming.
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.
EECC250 - Shaaban #1 lec #7 Winter Local workspace of a subroutine: A number of temporary memory locations required by the subroutine for temporary.
EECC250 - Shaaban #1 lec #8 Winter Recursive Subroutine Calls Example The purpose of this example is to examine how all parameters, local variables,
Processor Organization and Architecture Module III.
CEG 320/520: Computer Organization and Assembly Language ProgrammingIntel Assembly 1 Intel IA-32 vs Motorola
CS-280 Dr. Mark L. Hornick 1 Calling subroutines in assembly And using the Stack.
Programming Models CT213 – Computing Systems Organization.
Today’s topics Parameter passing on the system stack Parameter passing on the system stack Register indirect and base-indexed addressing modes Register.
9/20/6Lecture 3 - Instruction Set - Al Instruction Set (2)
Procedure Calls and the Stack (Lectures #18) ECE 445 – Computer Organization The slides included herein were taken from the materials accompanying Computer.
Richard P. Paul, SPARC Architecture, Assembly Language Programming, and C Chapter 7 – Subroutines These are lecture notes to accompany the book SPARC Architecture,
Passing Parameters using Stack Calling program pushes parameters on the stack one element at a time before calling subroutine. Subroutine Call (jsr, bsr)
9/20/6Lecture 2 - Prog Model Architecture, Data Types and Addressing Modes.
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson Slides4-2.ppt Modification date: March 23, Procedures Essential ingredient of high level.
Topics covered: Instruction Set Architecture CSE243: Introduction to Computer Architecture and Hardware/Software Interface.
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.
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.
CPS 4150 Computer Organization Chapter 2-2 Fall 2006 Ching-Song Don Wei.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 12 Procedure Calling.
Microprocessors CSE- 341 Dr. Jia Uddin Assistant Professor, CSE, BRAC University Dr. Jia Uddin, CSE, BRAC University.
ELE22MIC Lecture 6 Continuation of Lecture 5 Instruction Set Overview, Part 4 –HC-COM - Lab notes –Stack Pointer, Push, Pull Call/return Data –Conditional.
Chapter 14 Functions.
Computer Architecture & Operations I
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.
Displacement (Indexed) Stack
Computer Science 210 Computer Organization
Machine dependent Assembler Features
Instruction set Architecture
Figure 8.1 of course package
© Craig Zilles (adapted from slides by Howard Huang)
Lecture Set 5 The 8051 Instruction Set.
Subroutines and the Stack
Microprocessor and Assembly Language
Addressing Modes Immediate #<data> or Imm
William Stallings Computer Organization and Architecture 8th Edition
Stack Frames Stack frame = block of memory located in the system stack that contains: return address input parameters (from calling program to subroutine)
Processor Organization and Architecture
Assembler Design Options
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.
Computer Science 210 Computer Organization
MIPS Instructions.
Subroutines and the Stack
Passing Parameters Data passed to a subroutine is called a parameter.
Chapter 8 Central Processing Unit
The University of Adelaide, School of Computer Science
by Richard P. Paul, 2nd edition, 2000.
68000 Architecture, Data Types and Addressing Modes
; main program ; main move Param2, -(sp) move Param1, -(sp) Call Sub1
Computer Science 210 Computer Organization
Introduction to Micro Controllers & Embedded System Design
Subroutines … passing data
Subroutines and the Stack
Where is all the knowledge we lost with information? T. S. Eliot
Computer Organization and Assembly Language
© Craig Zilles (adapted from slides by Howard Huang)
Computer Organization
ECE511: Digital System & Microprocessor
(The Stack and Procedures)
Lecture 3 - Instruction Set - Al
Presentation transcript:

Figure 8.1 of course package Subroutines Subroutine suba Call suba Only one copy of the code is placed in memory Whenever we wish to use the code, a jump is made to it Jump to address of the first instruction of the subroutine Next instruction address should be saved before jump to subroutine is made Start of subroutine Next instruction Call suba Next instruction Jump back Call suba Next instruction Figure 8.1 of course package

Subroutine calls and returns main equ * ; ; first call move.l #next1, save_return ; save return address jmp suba ; jump to subroutine next1 … …….. ; this is where we continue … …….. ; second call move.l #next2, save_return ; save return address next2 … …….. ; this is where we continue ; third call move.l #next3, save_return ; save return address next3 … …….. ; this is where we continue ; Subroutine suba ; suba knows the symbols x and save_return ; suba equ * move.w x,d0 muls d0,d0 move.w d0,x lea save_return,a0 ;put the correct ;return address ;into a0 jmp (a0) ;return ;end of subroutine save_return ds.l 4 ;storage for return address Four extra instructions to implement subroutine. Programmer must explicitly save the return address before jumping to subroutine

Figure 2.24 Subroutine linkage using a link register Memory location Calling program Memory location Subroutine SUB --- 200 Call SUB 1000 First instruction 204 next instruction ---- ---- ---- ---- Return Here, address of next instruction must be saved by the Call instruction to enable returning to Calling program 1000 PC Link Register Call Return 204 Note: Link Register is dedicated to save return address 204 204

Nested subroutines One subroutine calling another - if link register is used, its previous contents will be destroyed - it is therefore important to save it in some other location Stack should be used - list of similar items arranged in a structure, such that last item added is the first item removed – Last-in-First-out - Push an element onto stack - Pop an element from stack to remove - elements are either word or longwords Call instruction – push address of next instruction Return – pop return address Stack Pointer originally points to the beginning of the block of memory

Calling Subroutines Two instructions – jsr, bsr Jump to subroutine – jsr address (ex. jsr suba) operand is the Effective Address (specified as absolute address) Longword address of the next instruction is pushed on to the stack Stack is implicitly used when calling subroutines The EA specified is then used to jump to the subroutine Equivalent machine instruction is (see Fig 8.3): 4EB9 0040 0100

Calling Subroutines Two instructions – jsr, bsr Branch to subroutine – bsr.b address bsr.w address (ex. bsr suba) Same as jsr, except signed displacement is added to PC Equivalent machine instruction is (see Fig 8.3): 617E or 6100 007E Machine instruction contains displacement calculated from Target address = PC + 2 + displacement