EECC250 - Shaaban #1 Lec # 6 Winter99 12-15-99 68000 Stack-Related Instructions PEA Push Effective Address Calculates an effective address and pushes it.

Slides:



Advertisements
Similar presentations
Chapter 3 Introduction to the 68000
Advertisements

The University of Adelaide, School of Computer Science
EECC250 - Shaaban #1 Lec # 2 Winter Addressing Modes  Addressing modes are concerned with the way data is accessed  Addressing can be.
Assembly Language Programming
680XX Program Examples Outline –Binary to BCD –Matrix Addition –Ones Count –String Compare –Sector Map –Raster Graphics –Subroutine Calls Goal –Understand.
Machine Instructions Operations
1 Procedure Calls, Linking & Launching Applications Lecture 15 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
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.
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.
The University of Adelaide, School of Computer Science
EECC250 - Shaaban #1 lec #14 Winter Binary Coded Decimal (BCD) Arithmetic Binary Coded Decimal (BCD) is a way to store decimal numbers.
Functions Functions and Parameters. History A function call needs to save the registers in use The called function will use the registers The registers.
C Programming and Assembly Language Janakiraman V – NITK Surathkal 2 nd August 2014.
Subroutines: Passing Arguments Using the Stack. Passing Arguments via the Stack Arguments to a subroutine are pushed onto the stack. The subroutine accesses.
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 #16 Winter Estimation of Assembly Programs Execution Time For a CPU running at a constant clock rate: clock rate =
20/06/2015CSE1303 Part B lecture notes 1 Functions, part 2 Lecture B15 Lecture notes, section B15.
Choice for the rest of the semester New Plan –assembler and machine language –Operating systems Process scheduling Memory management File system Optimization.
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.
Chapters 4 & 5: LC-3 Computer Architecture Machine Instructions Assembly language Programming in Machine and Assembly Language.
Faculty of Computer Science © 2006 CMPUT 229 Subroutines (Part 1) The 68K Stack.
EECC250 - Shaaban #1 lec #8 Winter Recursive Subroutine Calls Example The purpose of this example is to examine how all parameters, local variables,
9/20/6Lecture 21 -PIC Architecture1 PIC Architecture Programmers Model and Instruction Set.
Assembly Programming on the TI-89 Created By: Adrian Anderson Trevor Swanson.
CEG 320/520: Computer Organization and Assembly Language ProgrammingIntel Assembly 1 Intel IA-32 vs Motorola
Computer Architecture Lecture 13 – part 2 by Engineer A. Lecturer Aymen Hasan AlAwady 7/4/2014 University of Kufa - Information Technology Research and.
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.
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)
Assembly Language for Intel-Based Computers, 6 th Edition Chapter 8: Advanced Procedures (c) Pearson Education, All rights reserved. You may.
ECE 265 – LECTURE 8 The M68HC11 Basic Instruction Set The remaining instructions 10/20/ ECE265.
Objective At the conclusion of this chapter you will be able to:
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)
Procedure (Method) Calls Ellen Spertus MCS 111 September 25, 2003.
Microprocessors The ia32 User Instruction Set Jan 31st, 2002.
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson Slides4-2.ppt Modification date: March 23, Procedures Essential ingredient of high level.
by Richard P. Paul, 2nd edition, 2000.
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.
October 1, 2003Serguei A. Mokhov, 1 SOEN228, Winter 2003 Revision 1.2 Date: October 25, 2003.
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.
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.
7-Nov Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Oct lecture23-24-hll-interrupts 1 High Level Language vs. Assembly.
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.
Figure 8.1 of course package
Status Register Status = system byte (supervisor only) + user byte = system status + condition code register usually, it is not important to know.
Subroutines and the Stack
Procedures (Functions)
Lecture 3 - Instruction Set - Al
CS 301 Fall 2002 Control Structures
Subroutines … a 1st look procedures and functions in high level languages are modeled on subroutines typically, assembly code is very modular with.
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.
Figure 8.1 of course package
Chapter 6 - Procedures and Macros
The MOVE Multiple: MOVEM Instruction
Functions in Hmmm Assembly
Subroutines … passing data
Problem: ! bell ! help ! ! 1 ! 2 ! ! Bal help ! ! ! !
Subroutines and the Stack
Computer Organization and Assembly Language
ECE511: Digital System & Microprocessor
Presentation transcript:

EECC250 - Shaaban #1 Lec # 6 Winter Stack-Related Instructions PEA Push Effective Address Calculates an effective address and pushes it onto the stack pointed at by address register A7 (the stack pointer, SP). The difference between PEA and LEA –LEA loads an effective address in any address register. –PEA pushes an effective address onto the stack. PEA is equivalent to: LEA,Ai MOVEA.L Ai,-(A7) Where Ai is an address register other than A7 (A0-A6)

EECC250 - Shaaban #2 Lec # 6 Winter The MOVE Multiple: MOVEM Instruction This instruction saves or restores multiple registers. Useful in subroutines to save the values of registers not used to pass parameters. MOVEM has two forms: MOVEM register_list, MOVEM,register_list No effect on CCR. Example: Saving/restoring registers to from memory SUBR1MOVEM D0-D7/A0-A6,SAVEBLOCKSAVE D0-D7/A0-A6... MOVEM SAVEBLOCK,D0-D7/A0-A6Restore D0-D7/A0-A6 RTS Example: Saving/restoring registers using the stack (preferred method). SUBR1MOVEM D0-D7/A0-A6,-(SP)Push D0-D7/A0-A6 onto the stack... MOVEM (SP)+,D0-D7/A0-A6Restore D0-D7/A0-A6 from the stack RTS

EECC250 - Shaaban #3 Lec # 6 Winter Example: Power Calculation Subroutine A subroutine is needed which accepts two integers as input parameters: –a base, B (a signed integer), Size = one byte (range: -128  B  127) –an exponent E (a positive integer) Size = one byte, –and, compute the function B E size of answer = long word Functional specification (pseudo code) of subroutine POWER: POWER (B, E) D1 = B ;input arguments, base D2 = E ;exponent, a positive integer initialize D3 to 1;answer initialized to 1 while D2 > 0 D3 = D1*D3 ;compute function using D2 = D2 - 1;;continued product of base end POWER Return to calling program

EECC250 - Shaaban #4 Lec # 6 Winter Basic Flow Chart of Power Word SP during subroutine Initial SP (and after return from subroutine) Return address Effect on The Stack Return to calling program D1 = base D2 = exponent D3 = 1 D3 = D3 * D1 D2 = D2 - 1 D2 = 0 ? No Yes Subroutine Start Point POWER

EECC250 - Shaaban #5 Lec # 6 Winter POWER: Four Parameter Passing Cases We’ll examine four assembly versions of the subroutine POWER and sample Main programs that calls it. Each version uses a different parameter passing method: –Case 1: Parameter passing by value, using data registers. –Case 2: Parameter passing by reference, using address registers. –Case 3: Parameter passing by value, using the stack. –Case 4: Parameter Passing by reference, using the stack

EECC250 - Shaaban #6 Lec # 6 Winter POWER Subroutine Example (Case 1) Parameter Passing by Value: Using Data Registers - Main Program - MAINORG $400Main Program origin MOVEA.L#$07FFE,SPInitialize Stack Pointer MOVE.B B,D1 Put base number into D1 EXT.WD1Sign extend base to word length CLR.WD2Clear D2 before loading exponent MOVE.B E,D2 Put exponent number into D2 BSR POWER Call subroutine POWER LEA A,A5 put address of answer into A5 MOVE.L D3,(A5)save answer STOP#$2700Done ORG$600 B DC.B4Base number stored here E DC.B 2Exponent number stored here A DS.L1answer to be stored here

EECC250 - Shaaban #7 Lec # 6 Winter POWER Subroutine Example (Case 1) Parameter Passing by Value: Using Data Registers Continued - Subroutine ORG$800Subroutine POWER origin POWER MOVE.L #1,D3 initialize result to 1 LOOP MULS D1,D3 multiply result with base SUB #1,D2 decrement power by one BNE LOOPand repeat as long as power > 0 RTSDone, return to calling program

EECC250 - Shaaban #8 Lec # 6 Winter POWER Subroutine Example (Case 2) Parameter Passing by Reference: Using Address Registers - Main Program - MAINORG $400Main Program origin MOVEA.L#$07FFE,SPInitialize Stack Pointer LEA B,A1 A1 points to base number LEA E,A2 A2 points to exponent BSR POWER Call subroutine POWER LEA A,A5 put address of answer into A5 MOVE.L D3,(A5)save answer in memory STOP#$2700Done ORG$600 B DC.B4Base number stored here E DC.B 2Exponent number stored here A DS.L1answer to be stored here

EECC250 - Shaaban #9 Lec # 6 Winter POWER Subroutine Example (Case 2) POWER Subroutine Example (Case 2) Parameter Passing by Reference: Using Address Registers Continued - Subroutine ORG$800Subroutine POWER origin POWER MOVE.B (A1),D1copy base number to D1 EXT.WD1Sign extend base to word length CLR.WD2Clear D2 before loading exponent MOVE.B(A2),D2copy exponent to D2 MOVE.L #1,D3 initialize result in D3 to 1 LOOP MULS D1,D3 multiply result D3 with base D1 SUB #1,D2 decrement power in D2 by one BNE LOOPand repeat as long as power > 0 RTSDone, return to calling program

EECC250 - Shaaban #10 Lec # 6 Winter Addressing Modes Revisited: Address Register Indirect Addressing with Displacement The addressing notation: d16(A0) or (d16,A0) –Refers to the address contained in register A0 plus a signed 16 bit displacement d16 –Some assembles accept only one of the above syntax forms. Examples: MOVE.L (12,A4),D3 or MOVE.L 12(A4),D3 MOVE.W (-$4,A1),D0 or MOVE.W -$4(A1),D0

EECC250 - Shaaban #11 Lec # 6 Winter POWER Subroutine Example (Case 3) Parameter Passing by Value: Using The Stack - Main Program - MAINORG $400Main Program origin MOVEA.L#$07FFE,SPInitialize Stack Pointer MOVE.B B,D1 Put base number into D1 EXT.WD1Sign extend base to word length MOVE.W D1,-(SP) push base B onto the stack CLR.WD2Clear D2 before loading exponent MOVE.B E,D2 Put exponent number into D2 MOVE.W D2,-(SP) push exponent E onto the stack BSR POWER Call subroutine POWER MOVE.L (SP)+,D3 pop answer from stack resetting SP LEA A,A5 put address of answer into A5 MOVE.L D3,(A5)save answer STOP#$2700Done ORG$600 B DC.B4Base number stored here E DC.B 2Exponent number stored here A DS.L1answer to be stored here

EECC250 - Shaaban #12 Lec # 6 Winter POWER Subroutine Example (Case 3) POWER Subroutine Example (Case 3) Parameter Passing by Value: Using The Stack Continued - Subroutine - ORG$800Subroutine POWER origin POWER MOVE.W 6(SP),D1copy base from stack to D1 CLR.WD2Clear D2 before loading exponent MOVE.B4(SP),D2copy exponent from to D2 MOVE.L #1,D3 initialize result in D3 to 1 LOOP MULS D1,D3 multiply result D3 with base D1 SUB #1,D2 decrement power in D2 by one BNE LOOPand repeat as long as power > 0 MOVE.LD3,4(SP)Push result onto the stack RTSDone, return to calling program

EECC250 - Shaaban #13 Lec # 6 Winter Effect on The Stack Word Just before calling Subroutine Current SP Base B Exponent E Initial SP Word Just before end of main Current SP = Initial SP Just after calling Subroutine Word Current SP Base B Exponent E Initial SP Return address 8 Word Just before return to main Current SP Answer Return address Initial SP 4 8 (Case 3)

EECC250 - Shaaban #14 Lec # 6 Winter POWER Subroutine Example (Case 4) POWER Subroutine Example (Case 4) Parameter Passing by Reference: Using The Stack - Main Program - MAINORG $400 Main Program origin MOVEA.L#$07FFE,SP Initialize Stack Pointer PEA B Push address of Base onto the stack PEA E Push address of Exponent onto the stack PEA A Push address of Answer onto the stack BSR POWER Call subroutine POWER LEA 12(SP),SP Stack clean-up: stack pointer reset STOP#$2700 Done ORG$600 B DC.B4 Base number stored here E DC.B 2 Exponent number stored here A DS.L1 answer to be stored here

EECC250 - Shaaban #15 Lec # 6 Winter POWER Subroutine Example (Case 4) Parameter Passing by Reference: Using The Stack Continued - Subroutine - ORG$800Subroutine POWER origin POWER MOVEA.L12(SP),A1load Base address in A1 MOVEA.L 8(SP),A2load Exponent address in A2 MOVEA.L 4(SP),A3load Answer address address in A3 MOVE.B (A1),D1 Put base number into D1 EXT.WD1Sign extend base to word length CLR.WD2Clear D2 before loading exponent MOVE.B(A2),D2copy exponent from to D2 MOVE.L #1,D3 initialize result in D3 to 1 LOOP MULS D1,D3 multiply result D3 with base D1 SUB #1,D2 decrement power in D2 by one BNE LOOPand repeat as long as power > 0 MOVE.LD3,(A3)Save result in memory RTSDone, return to calling program

EECC250 - Shaaban #16 Lec # 6 Winter Effect on The Stack Word Just before calling Subroutine Current SP Initial SP Base Address Exponent Address Answer Address Word Just after calling Subroutine Current SP Initial SP Base Address Exponent Address Answer Address Return Address (Case 4) PEA B PEA E PEA A BSR POWER

EECC250 - Shaaban #17 Lec # 6 Winter Effect on The Stack Just after return to main Word Just after stack clean-up in Main Current SP = Initial SP Word Current SP Initial SP Base Address Exponent Address Answer Address (Case 4) LEA 12(SP),SP RTS