ECE 353 Introduction to Microprocessor Systems Michael G. Morrow, P.E. Week 6.

Slides:



Advertisements
Similar presentations
CH10 Instruction Sets: Characteristics and Functions
Advertisements

ECE 353 Introduction to Microprocessor Systems Discussion 3.
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/1/ / faculty of Electrical Engineering eindhoven university of technology Introduction Part 2: Data types and addressing modes dr.ir. A.C. Verschueren.
1 Lecture 3: Instruction Set Architecture ISA types, register usage, memory addressing, endian and alignment, quantitative evaluation.
INSTRUCTION SET ARCHITECTURES
There are two types of addressing schemes:
1 Lecture 4: Procedure Calls Today’s topics:  Procedure calls  Large constants  The compilation process Reminder: Assignment 1 is due on Thursday.
10/9: Lecture Topics Starting a Program Exercise 3.2 from H+P Review of Assembly Language RISC vs. CISC.
Instruction Set Architecture Classification According to the type of internal storage in a processor the basic types are Stack Accumulator General Purpose.
Procedure call frame: Hold values passed to a procedure as arguments
Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 41 Today’s class More assembly language programming.
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:
COMP3221: Microprocessors and Embedded Systems--Lecture 8 1 COMP3221: Microprocessors and Embedded Systems Lecture 8: Program Control Instructions
TK 2633 Microprocessor & Interfacing Lecture 3: Introduction to 8085 Assembly Language Programming (2) 1 Prepared By: Associate Prof. Dr Masri Ayob.
S. Barua – CPSC 440 CHAPTER 2 INSTRUCTIONS: LANGUAGE OF THE COMPUTER Goals – To get familiar with.
Room: E-3-31 Phone: Dr Masri Ayob TK 2633 Microprocessor & Interfacing Lecture 1: Introduction to 8085 Assembly Language.
Topics covered: ARM Instruction Set Architecture CSE 243: Introduction to Computer Architecture and Hardware/Software Interface.
What is an instruction set?
Chapter 8 :: Subroutines and Control Abstraction
Lecture 4: Advanced Instructions, Control, and Branching cont. EEN 312: Processors: Hardware, Software, and Interfacing Department of Electrical and Computer.
Machine Instruction Characteristics
ACOE2511 ACOE251/AEEC335 -Assembly Language for the 80X86/Pentium Intel Microprocessors Lecturer: Dr. Konstantinos Tatas.
13/02/2009CA&O Lecture 04 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
Programmer's view on Computer Architecture by Istvan Haller.
Dr Mohamed Menacer College of Computer Science and Engineering Taibah University CS-334: Computer.
1 Control Abstraction (Section ) CSCI 431 Programming Languages Fall 2003 A compilation of material developed by Felix Hernandez-Campos and Michael.
The x86 PC Assembly Language, Design, and Interfacing By Muhammad Ali Mazidi, Janice Gillespie Mazidi and Danny Causey © 2010, 2003, 2000, 1998 Pearson.
Lecture 8: Control, Procedures, and the Stack CS 2011 Fall 2014, Dr. Rozier.
Lecture 4: MIPS Instruction Set
Computer Architecture and Organization
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,
Microprocessors The ia32 User Instruction Set Jan 31st, 2002.
Computer Architecture EKT 422
Lecture 04: Instruction Set Principles Kai Bu
ECE 353 Introduction to Microprocessor Systems Michael G. Morrow, P.E. Week 6.
CSC 8505 Compiler Construction Runtime Environments.
ECE 353 Introduction to Microprocessor Systems Michael G. Morrow, P.E. Week 7.
ECE 353 Introduction to Microprocessor Systems Michael G. Morrow, P.E. Week 5.
Group # 3 Jorge Chavez Henry Diaz Janty Ghazi German Montenegro.
ARM-7 Assembly: Example Programs 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.
Instruction Sets. Instruction set It is a list of all instructions that a processor can execute. It is a list of all instructions that a processor can.
ECE 353 Introduction to Microprocessor Systems Michael J. Schulte Week 6.
7-Nov Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Oct lecture23-24-hll-interrupts 1 High Level Language vs. Assembly.
Computer Science 210 Computer Organization
The Cortex-M3/m4 Embedded Systems: Cortex-M3/M4 Instruction Sets
A Closer Look at Instruction Set Architectures
The University of Adelaide, School of Computer Science
Computer Organization and Assembly Language (COAL)
Chapter 9 :: Subroutines and Control Abstraction
Lecture 4: MIPS Instruction Set
Stack Frame Linkage.
MIPS Instructions.
The University of Adelaide, School of Computer Science
The University of Adelaide, School of Computer Science
Lecture 5: Procedure Calls
Review.
Chapter 9 Instruction Sets: Characteristics and Functions
Introduction to Microprocessor Programming
COMP3221: Microprocessors and Embedded Systems
Computer Architecture
Chapter 10 Instruction Sets: Characteristics and Functions
Presentation transcript:

ECE 353 Introduction to Microprocessor Systems Michael G. Morrow, P.E. Week 6

Subroutines Subroutine Call and Return Parameter Passing Stack Frames ARM7 Programming Exercises Numeric conversions Multi-precision arithmetic operations Search? Sort? Topics

Subroutines So, why do we use them? Calling a subroutine BL BX Context save and restore There are two basic ways to organize context save/restore  Make it the caller’s responsibility  Make it the subroutine’s responsibility Compilers may use a hybrid approach for better efficiency Course documentation standards

Returning from a Subroutine Returning from a subroutine The return address is stored in the link register (R14, aka LR) – returning from the subroutine means that we have to branch to that address  MOV PC, LR Direct move, discouraged by ARM  BX LR Indirect branch using R14  STM / LDM Very compact context save/restore/return mechanism

Testing and Debugging Subroutines Software modularity permits us to do modular testing, so we know that the pieces work before we combine them Define software interfaces first Use stub subroutines to test the code that calls them before subroutines are completed Use driver programs to exercise and test subroutines in isolation  Verify caller context and stack not corrupted  Use adequate test vectors (not just correct values!) Integrate modules and test the system

Parameter Passing Register Passing Parameters are stored in registers Memory Passing Parameters are stored in memory Pointer Parameters By using pointer parameters, we can pass- by-reference an operand of any size  Commonly used for arrays and data structures  Data format must be known by caller and callee Exercise

Parameter Passing Stack Passing Parameters are pushed on the stack before the subroutine is called  Stack must be restored after the subroutine returns Each instance of a subroutine therefore gets its own copy of parameters The stack can also be used as storage for local variables as well as parameters These attributes are very useful in writing reentrant subroutines

Parameter Passing Using a stack frame A stack frame is a construct that we use to manage access to parameters that have been placed on the stack and to allocate and use local variables that are created in stack space A frame pointer is used to hold a constant reference to the stack frame  ARM designated R11 as the frame pointer (FP) Methodology Example So why not just use SP to access the stack?

Numeric Conversions I BCD to Binary Conversion We have a very convenient relationship between bit groupings and values BCD is either packed or unpacked  Unpacked BCD means that there is just one BCD digit per word, regardless of word size  In packed BCD, every 4 bits specify a BCD digit Exercise Write a subroutine bcd2bin to convert the packed BCD value in R1 to its equivalent binary value in R0. Assume R1 is valid packed BCD.

Numeric Conversions II ASCII Hexadecimal to Binary Conversion Have to account for all digits, 0-9 and A-F (a-f) Convenient relationship between digits and bits ASCII Decimal to Binary Conversion No convenient relationship between digits and bits Exercise Write a subroutine strupr to convert all lower case letters in the ASCIIZ string pointed to by R1 to upper case. Write a subroutine hex2bin that will convert the hexadecimal ASCIIZ string pointed to by R1 to a value in R0.

Numeric Conversions III Binary to ASCII Hexadecimal Conversion Convenient relationship between bit groupings and ASCII digits Binary to ASCII Decimal Conversion No convenient relationship between bit groupings and digits Two methods for determining the ASCII digit values  Division/modulus  Repeated subtraction

Multi-Precision Arithmetic I Although the ARM is limited to 32-bit addition, we can write code to perform addition of much longer numbers Exercise Write a subroutine add256 to add two 256 bit numbers (assume little-endian) Assume that pointers to the numbers are passed in using R1 and R2, and the result is to be stored in memory at the location pointed to by R0

Multi-Precision Arithmetic II Write a subroutine mul64 to do an unsigned 64-bit multiplication with a 64- bit result Operands are to be passed using a standard stack frame, ensuring that they are in little-endian form in memory when they are on the stack Any temporary storage must be allocated on the stack. (Do not use registers) Return the result in R1:R0

Sorting and Searching Write a subroutine bsort that implements a bubble sort on an array of bytes. The address of the array should be passed in R0, with the length of the array in R1. Write a subroutine bsearch that implements a binary search on a sorted array of bytes. The address of the array should be passed in R0, the array length in R1, and the search target in R2. Return in R0 the address where the target is located, or -1 if the target is not found.

Wrapping Up Pre-quiz #4 due by Monday class time. Next week we start delving into microprocessor system hardware – this is usually uncharted territory for most students, so read and ask questions Reading for next week Textbook Ch. 9 ADUC 51-52, 60-61, Supplement #2 (available in

Pointer Parameter Exercise i. Define a variable length data structure where the first word is the number of words of data that follow (could be 0). ii. Write a subroutine CountNZ that finds the number of nonzero data elements in the array. iii. Assume that the starting address of the data structure is passed in R1. iv. Return the result in R0.

Stack Frame Example Write code for a main program that uses a stack frame to call a procedure Update - parameter words X=1,Y=2, data=3 are to be pushed in that order. Draw a word-wide stack diagram, indicating the objects placed on it by the caller. Write a stub Update procedure - assume the procedure must use 2 words of local variables Set up the stack frame, Load the 3 passed parameters into R0, Store R0 into the 2 local variable words, Clean up the stack frame, and Return. Update the stack diagram, indicating how it is used/allocated by the procedure.

BL Instruction Reference Syntax BL{ } RTL if (cond is true)  R14  next instruction address  PC  PC + offset Flags are not affected cond1011signed_immediate_24

BX Instruction Reference Syntax BX{ } RTL if (cond is true)  T flag  Rm[0]  PC  Rm & 0xFFFFFFFE Flags are not affected In ARM v5 and higher, there is also a BLX instruction cond SBO 0001Rm

MLA Instruction Reference Syntax MLA{ }{S},,, RTL if (cond is true)  Rd  Rn + (Rs Rm) Flags (if S used) N, Z (C is unpredictable)

ARM Stack Frame Methodology 1. Caller pushes N parameters on the stack 2. Caller executes call (BL), return address is in R14 3. Subroutine does context save using PUSH, including R11 and R14 4. Subroutine sets R11 (frame pointer, aka FP) to the SP value to establish a fixed reference to the stack frame 5. Subroutine subtracts 4*X from SP to allocate space for X words of local variable space a. Must always allocate local variable space in multiples of words! 6. Subroutine code executes a. Parameters are accessed by using FP as base register with positive offset (i.e., the last parameter pushed on stack is addressed by [FP,#(4*registers_pushed_in_context_save)] ) b. Local variables are accessed by using FP as base register with negative offset (i.e. the first word of local variable space is addressed by [FP,#-4] ) 7. Subroutine deallocates local variables (ADD SP, #4*X) 8. Subroutine does POP to restore context and return 9. Caller adds value to SP to deallocate the passed parameter space a. ADD SP, #4*N b. Caller clean-up supports use of a variable number of arguments, so it is a common implementation in practice