Passing Parameters Data passed to a subroutine is called a parameter.

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

The University of Adelaide, School of Computer Science
680XX Program Examples Outline –Binary to BCD –Matrix Addition –Ones Count –String Compare –Sector Map –Raster Graphics –Subroutine Calls Goal –Understand.
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.
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 sub { –#parameters are placed – –. –return; }
Pointers A pointer is a variable that contains memory address as its value. A variable directly contains a specific value. A pointer contains an address.
Chapter 5 The LC-3 LC-3 Computer Architecture Memory Map
Chapter
Topics covered: ARM Instruction Set Architecture CSE 243: Introduction to Computer Architecture and Hardware/Software Interface.
M68K Assembly Language Programming Bob Britton Chapter 6 Efficient Algorithm Development Notice: Slides in this series originally, provided by B.Britton,
5/6/99 Ashish Sabharwal1 JVM Architecture n Local storage area –Randomly accessible –Just like standard RAM –Stores variables (eg. an array) –Have to specify.
EECC250 - Shaaban #1 lec #7 Winter Local workspace of a subroutine: A number of temporary memory locations required by the subroutine for temporary.
Chapters 4 & 5: LC-3 Computer Architecture Machine Instructions Assembly language Programming in Machine and Assembly Language.
EECC250 - Shaaban #1 lec #8 Winter Recursive Subroutine Calls Example The purpose of this example is to examine how all parameters, local variables,
Lecture 7: MIPS Instruction Set Today’s topic –Procedure call/return –Large constants Reminders –Homework #2 posted, due 9/17/
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
Stacks and Subroutines ELEC 330 Digital Systems Engineering Dr. Ron Hayne Images Courtesy of Ramesh Gaonkar and Delmar Learning.
Computer Architecture Lecture 13 – part 2 by Engineer A. Lecturer Aymen Hasan AlAwady 7/4/2014 University of Kufa - Information Technology Research and.
CSC Computer Organization Lecture 4: Machine Instructions and Programs Terrence Mak.
7/23 C Programming in Embedded Systems Computer Science & Engineering Department Arizona State University Tempe, AZ Dr. Yann-Hang Lee
Assembly Language for Intel-Based Computers, 6 th Edition Chapter 8: Advanced Procedures (c) Pearson Education, All rights reserved. You may.
Adapted from Computer Organization and Design, Patterson & Hennessy, UCB ECE232: Hardware Organization and Design Part 7: MIPS Instructions III
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.
V 1.01 Arrays and Pointers in C A pointer variable is a variable that contains the address of another variable. An array is a collection of like elements,
4-1 Embedded Systems C Programming Language Review and Dissection II Lecture 4.
Chapter 2 — Instructions: Language of the Computer — 1 Conditional Operations Branch to a labeled instruction if a condition is true – Otherwise, continue.
X86_64 programming Tutorial #1 CPSC 261. X86_64 An extension of the IA32 (often called x86 – originated in the Intel 8086 processor) instruction set to.
Second word first word Figure 2.5. Memory words. n bits last word i th word.
The LC-3 – Chapter 5 COMP 2620 Dr. James Money COMP
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.
Introduction to Intel IA-32 and IA-64 Instruction Set Architectures.
CPS 4150 Computer Organization Chapter 2-2 Fall 2006 Ching-Song Don Wei.
1 CSCI 2510 Computer Organization Memory Addressing and Assembly Instruction Basics.
Computer Science 210 Computer Organization
Figure 8.1 of course package
Computer Science 210 Computer Organization
Subroutines … passing data
Subroutines and the Stack
Microcomputer Programming
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
CS 301 Fall 2002 Control Structures
ECE 445 CS1251 Computer Organization Carl Hamacher
Subroutines … a 1st look procedures and functions in high level languages are modeled on subroutines typically, assembly code is very modular with.
CPE/EE 421 Microcomputers: Motorola 68000: Assembly Language and C
Figure 2.1. Binary, signed-integer representations.
Computer Science 210 Computer Organization
Introduction to Intel IA-32 and IA-64 Instruction Set Architectures
Subroutines and the Stack
The University of Adelaide, School of Computer Science
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
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.
; main program ; main move Param2, -(sp) move Param1, -(sp) Call Sub1
Figure 8.1 of course package
Subroutines … passing data
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
Subroutines and the Stack
Computer Architecture
By Nasser Halasa Assembly Language.
Introduction Lab1 A crash course in assembler programming
Computer Organization and Assembly Language
Lecture 3 - Instruction Set - Al
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ECE511: Digital System & Microprocessor
Lecture 3 - Instruction Set - Al
Presentation transcript:

Passing Parameters Data passed to a subroutine is called a parameter. There are two classes of parameters: - in (call by value) Original data does not change Copy of original data is used by subroutine Copy may be modified - in-out (call by reference) Original data can be modified Location of data is passed Parameters are passed using: Registers (data registers used to pass by value) Parameter (Memory) block (address register used to pass address of the block) Block may be just one location or a block of memory locations Stack (stack can be both used to pass by value, or by reference)

Passing Parameters Calling Program move N,R1 ;R1 serves as a counter – used to pass by value move #NUM1,R2 ; R2 points to the list – used to pass by reference ; address of the first number on the list Call LISTADD ; call the subroutine move R0,SUM ; save result …… Subroutine LISTADD Clear R0 ; initialize sum to zero LOOP Add (R2)+,R0 ; Add entry from list Decrement R1 Branch > 0 LOOP Return (Fig 2.25 of Hamacher)

Example of Passing Parameters by parameter block ; Parameter Blocks have advantage when the number of parameters to be passed is large. If all registers were used for parameter passing, subroutine will have no registers to work with ;Main Program main equ * …. lea block, a0 ; move address of parameter block to a0 move.l #string, (a0) ; move string address to block jsr convert ; call subroutine ….. ; result is in the block (four bytes offset) ….. ….. ; end of code ; Subroutine convert convert equ * movea.l block, a2 ; copy string pointer to a2 ….. ; assume result is in d0 move.w d0, 4(a0) ; save the result in the block rts ; return ; Data area ; string ds.b 20 ; storage for string block ds.l 1 ; first parameter: base address of the string ds.w 1 ; second parameter: resulted signed integer end