ECE 353 Introduction to Microprocessor Systems Discussion 3.

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

Topics Left Superscalar machines IA64 / EPIC architecture
Registers of the 8086/ /2002 JNM.
ARM versions ARM architecture has been extended over several versions.
Appendix D The ARM Processor
Cosc 2150: Computer Organization
CPSC 330 Fall 1999 HW #1 Assigned September 1, 1999 Due September 8, 1999 Submit in class Use a word processor (although you may hand-draw answers to Problems.
Wat gaan we doen? harhaling data types
Passing by-value vs. by-reference in ARM by value C code equivalent assembly code int a;.section since a is not assigned an a:.skip initial.
Code Generation.
1 Lecture 3: MIPS Instruction Set Today’s topic:  More MIPS instructions  Procedure call/return Reminder: Assignment 1 is on the class web-page (due.
1 ARM Movement Instructions u MOV Rd, ; updates N, Z, C Rd = u MVN Rd, ; Rd = 0xF..F EOR.
Run-time Environment for a Program different logical parts of a program during execution stack – automatically allocated variables (local variables, subdivided.
1 Procedure Calls, Linking & Launching Applications Lecture 15 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
Procedures in more detail. CMPE12cGabriel Hugh Elkaim 2 Why use procedures? –Code reuse –More readable code –Less code Microprocessors (and assembly languages)
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
Apr. 12, 2000Systems Architecture I1 Systems Architecture I (CS ) Lecture 6: Branching and Procedures in MIPS* Jeremy R. Johnson Wed. Apr. 12, 2000.
Procedure call frame: Hold values passed to a procedure as arguments
ECE 353 Introduction to Microprocessor Systems Michael G. Morrow, P.E. Week 6.
1 Storage Registers vs. memory Access to registers is much faster than access to memory Goal: store as much data as possible in registers Limitations/considerations:
Procedures in more detail. CMPE12cCyrus Bazeghi 2 Procedures Why use procedures? Reuse of code More readable Less code Microprocessors (and assembly languages)
Run-Time Storage Organization
S. Barua – CPSC 440 CHAPTER 2 INSTRUCTIONS: LANGUAGE OF THE COMPUTER Goals – To get familiar with.
28/06/2015CMPUT Functions (2)  Function calling convention  Various conventions available  One is specified by CMPUT229  Recursive functions.
Digression: the “Stack” 1 CS502 Spring 2006 Digression: the “Stack” Imagine the following program:– int factorial(int n){ if (n
Stacks and Subroutines ELEC 330 Digital Systems Engineering Dr. Ron Hayne Images Courtesy of Ramesh Gaonkar and Delmar Learning.
The Stack Pointer and the Frame Pointer (Lecture #19) ECE 445 – Computer Organization The slides included herein were taken from the materials accompanying.
13/02/2009CA&O Lecture 04 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
ECE 353 Introduction to Microprocessor Systems Discussion 11.
Code Generation Gülfem Savrun Yeniçeri CS 142 (b) 02/26/2013.
Slides revised 3/25/2014 by Patrick Kelley. 2 Procedures Higher Level languages have adopted a standard Referred to as C-style calling Uses the stack.
Lecture 18: 11/5/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
1 Control Abstraction (Section ) CSCI 431 Programming Languages Fall 2003 A compilation of material developed by Felix Hernandez-Campos and Michael.
Procedure Calls and the Stack (Lectures #18) ECE 445 – Computer Organization The slides included herein were taken from the materials accompanying Computer.
Procedures. Why use procedures? ? Microprocessors (and assembly languages) provide only minimal support for procedures Must build a standard form for.
Adapted from Computer Organization and Design, Patterson & Hennessy, UCB ECE232: Hardware Organization and Design Part 7: MIPS Instructions III
COP4020 Programming Languages Subroutines and Parameter Passing Prof. Xin Yuan.
Passing Parameters using Stack Calling program pushes parameters on the stack one element at a time before calling subroutine. Subroutine Call (jsr, bsr)
Microprocessors The ia32 User Instruction Set Jan 31st, 2002.
ECE 353 Introduction to Microprocessor Systems Michael G. Morrow, P.E. Week 6.
מבנה מחשב תרגול 4 מבנה התוכנית. 2 Introduction When we wrote: ‘int n = 10’; the compiler allocated the variable’s memory address and labeled it ‘n’. In.
Computer Architecture CSE 3322 Lecture 4 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/10/09
4-1 Embedded Systems C Programming Language Review and Dissection II Lecture 4.
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.
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.
ECE 353 Introduction to Microprocessor Systems Michael J. Schulte Week 6.
Function Calling. Mips Assembly Call and Return Steps for procedure calling –Save the return address –Jump to the procedure (function) –Execute the procedure.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 12 Procedure Calling.
“ INSTRUCTIONS SET OF AVR MICROCONTROLLER ” SIGMA INSTITUTE OF ENGINEERING Prepared By: SR.NO NAME OF STUDENT ENROLLMENT 1 Abhishek Lakhara
Computer Architecture & Operations I
Storage Allocation Mechanisms
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.
Computer Science 210 Computer Organization
Lecture 5: Procedure Calls
The Stack.
CSCI206 - Computer Organization & Programming
Chapter 9 :: Subroutines and Control Abstraction
CSCI206 - Computer Organization & Programming
Stack Frame Linkage.
MIPS Instructions.
The University of Adelaide, School of Computer Science
Review.
Ithaca College Machine-Level Programming VII: Procedures Comp 21000: Introduction to Computer Systems & Assembly Lang Spring 2017.
Problem: ! bell ! help ! ! 1 ! 2 ! ! Bal help ! ! ! !
Problem: ! bell ! help ! ! 1 ! 2 ! ! Bal help ! ! ! !
Systems Architecture I
Computer Architecture
Where is all the knowledge we lost with information? T. S. Eliot
Computer Organization and Assembly Language
Ithaca College Machine-Level Programming VII: Procedures Comp 21000: Introduction to Computer Systems & Assembly Lang Spring 2017.
Presentation transcript:

ECE 353 Introduction to Microprocessor Systems Discussion 3

Topics Subroutines/Stack Frames/Multi- Precision Arithmetic Q & A

Problem Write a procedure that multiplies two 64-bit unsigned numbers and returns a 64-bit result in R1:R0. R1 – upper order bits R0 – lower order bits

Problem (0). Draw a diagram showing the complete execution of a 64-bit multiplication using 32-bit multiplies and generating a 128-bit result. (Note: We will only use 64- bits of the result.) A B X C D (B*D)H(B*D)L (A*D)H(A*D)L (B*C)H(B*C)L (A*C)H(A*C)L XX XX R1 R0

Problem (1). Write a main code fragment that calls the subroutine (mul64). Use a standard stack frame to pass two double-word parameters to the subroutine. Place them on the stack so that they are in little endian format. Put operand 1 on first. Clean up the stack after the subroutine returns.

Problem (1). ; Filename: main5.s ; Author: ECE 353 Staff ; Description: main program file for discussion 6 ARM;use ARM instruction set EXTERN mul64 EXPORT __main AREA FLASH, CODE, READONLY __main ;mul64 exercise MOVR0, #0x ;operand1 MSW PUSH{R0} MOVR0, #0xC ;operand1 LSW PUSH{R0} MOVR0, #0x000000FF;operand2 MSW PUSH{R0} MOVR0, #0x ;operand2 LSW PUSH{R0} BLmul64 ADDSP, #16;cleanup stack B __main END

Problem (2). Draw a diagram of the stack at the point when the call is made to mul64. (Note: the stack is drawn as 32-bits in width.)

Answer SP -> OP1 MSW OP1 LSW OP2 MSW OP2 LSW

Problem (3). Write the complete subroutine that performs 64-bit unsigned multiplication, returning a 64-bit result.64-bit unsigned multiplication Use a standard stack frame to retrieve the source operands. Place the 64-bit result in R1:R0 Allocate space for any temporary storage on the stack frame (do not use registers)(three words needed).

Problem (2). ; Filename: mul64.s ; Author: ECE 353 Staff ; Description: Implementation of 64-bit multiply function ARM;use ARM instruction set EXPORT mul64 AREA FLASH, CODE, READONLY ; Name: mul64 ; Description: 64 x 64 unsigned multiply ; Assumes: Arguments pushed on stack in little-endian form ; first pushed - 64-bit operand1 ; second pushed - 64-bit operand2 ; Returns: R1:R bit product (truncated) ; Modifies: None mul64 END

(2). mul64 PUSH{R11,LR};context save MOVR11, R13;get frame pointer SUBR13, R13, #12;allocate local variable space ;B*D LDRR0, [R11, #16];get operand1 LSW (B) LDRR1, [R11, #8];get operand2 LSW (D) UMULLR0, R1, R0, R1;BDH:BDL in R1:R0 STRR1, [R11, #-4];BDH to temp1 (local) STRR0, [R11, #-8];BDL to temp2 (local) ;A*D LDRR0, [R11, #8];get operand2 LSW (D) LDRR1, [R11, #20];get operand1 MSW (A) MULR0, R0, R1;R0 = ADL STRR0, [R11, #-12];ADL to temp3 (local) ;B*C LDRR0, [R11, #16];get operand1 LSW (B) LDRR1, [R11, #12];get operand2 MSW (C) MULR1, R0, R1;R1 = BCL ;add up MSW of result LDRR0, [R11, #-12];get temp3 (ADL) ADDR1, R1, R0;R1 = BCL + ADL LDRR0, [R11, #-4];get temp1 (BDH) ADDR1, R1, R0;R1 = BCL + ADL + BDH LDRR0, [R11, #-8];get temp2 (BDL) ;cleanup and exit ADDR13, R13, #12;deallocate local variable space mul64_exit POP{R11,PC};restore context and return END

Problem (4). Update the drawing in part (2) to reflect the total stack frame used by the subroutine.

Answer SP -> OP1 MSW OP1 LSW OP2 MSW OP2 LSW SP -> FP -> [FP + 20] [FP + 16] [FP + 12] [FP + 8] [FP - 4] [FP - 8] [FP - 12] R14 R11 temp1 temp2 temp3

Questions?