ECE 3610 MICROPROCESSING SYSTEMS

Similar documents
It translates (converts) assembly language to machine code.

Introduction to Microcontrollers III

Introduction to Microcontrollers III

EE 5340/7340 Motorola 68HC11 Microcontroler Lecture 1. Carlos E. Davila, Electrical Engineering Dept. Southern Methodist University

CodeWarrior. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff

EE 3170 Microcontroller Applications

ME4447/6405. Microprocessor Control of Manufacturing Systems and Introduction to Mechatronics. Instructor: Professor Charles Ume LECTURE 7

1. Memory Mapped Systems 2. Adding Unsigned Numbers

Lecture 9 Subroutines

Using the stack and the stack pointer

A 3-SPEED STEPPER MOTOR

ECE251: Tuesday September 11

Lecture #4 Microcontroller Instruction Set Embedded System Engineering Philip Koopman Monday, 25-Jan-2016

Outline. 2.8 Stack. 2.9 Subroutines

ECE251: Tuesday September 12

Subroutines and the Stack

Lab 2 Part 1 Assembly Language Programming and 9S12 Ports

Lab 7: Asynchronous Serial I/O

Exam I Review February 2017

Computer Organization I. Lecture 28: Architecture of M68HC11

Lecture 6 Assembly Programming: Branch & Iteration

Introduction to Microcontrollers II

ECE L A B 1 Introduction ASSEMBLY PROGRAMMING WITH MINIIDE

Introduction to the 9S12 Microcontroller

Programming the Motorola MC68HC11 Microcontroller

UNIVERSITY OF MANITOBA DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING. Term Test #2 Solution ECE 3610 MICROPROCESSING SYSTEMS

Introduction to Microcontrollers

Homework 12 Solutions

COSC345 Software Engineering. Basic Computer Architecture and The Stack

Chapter 5 Sections 1 6 Dr. Iyad Jafar

ECE 367 -Experiment #1 Fall 2012

Coe538 Final Study Guide 2016 (Questions & Answers)

Decimal, Hexadecimal and Binary Numbers Writing an assembly language program

LECTURE #21: G-CPU & Assembly Code EEL 3701: Digital Logic and Computer Systems Based on lecture notes by Dr. Eric M. Schwartz

Introduction to Microcontrollers II

Introduction to Programming

Subroutine. Chapter 8

CHAPTER 8. Solutions for Exercises

Addition and Subtraction of Hexadecimal Numbers Simple assembly language programming

ECET Chapter 2, Part 2 of 3

STUDENT LESSON A17 Quadratic Sorting Algorithms

ME 6405 Introduction to Mechatronics

Module 8: Atmega32 Stack & Subroutine. Stack Pointer Subroutine Call function

MIPS Functions and the Runtime Stack

Mark II Aiken Relay Calculator

COMP 250. Lecture 7. Sorting a List: bubble sort selection sort insertion sort. Sept. 22, 2017

Cross Assembly and Program Development

Ryerson University Department of Electrical and Computer Engineering ELE 538 Microprocessor Systems Final Examination December 8, 2003

It slearning 365 Limited. 36 Richardson Close Broughton Astley. Leicestershire LE9 6NU. First Edition

Unit wise Question Bank UNIT-II

EE319 K Lecture 7. Address mode review Assembler, Debugging Psuedo ops 16 bit timer finite state machines. University of Texas ECE

CMPEN 472 Sample EXAM II

Total: EEL 3701 Digital Logic & Computer Systems Final Exam Fall Semester 2007 COVER SHEET: Re-Grade Information: 1 (10) 2 (10) 3 (10) 4 (14) 5 (14)

A Simple MC9S12 Program

To become familiar with array manipulation, searching, and sorting.

Sample Problem Set #1

Most of the HC12 s instructions access data in memory There are several ways for the HC12 to determine which address to access

MODULE 4 INSTRUCTIONS: LANGUAGE OF THE MACHINE

Chapter 2: HCS12 Assembly Programming. EE383: Introduction to Embedded Systems University of Kentucky. Samir Rawashdeh

Exam 2 E2-1 Fall Name: Exam 2

Sorting Pearson Education, Inc. All rights reserved.

8/2/10. Looking for something COMP 10 EXPLORING COMPUTER SCIENCE. Where is the book Modern Interiors? Lecture 7 Searching and Sorting TODAY'S OUTLINE

APPENDIX D FLOWCHARTS AND PSEUDOCODE OVERVIEW

Procedure Call Instructions

68000 Architecture, Data Types and Addressing Modes. 9/20/6 Lecture 2 - Prog Model 1

ECE251: Tuesday September 18

ECE331 Handout 3- ASM Instructions, Address Modes and Directives

Lecture 7 Assembly Programming: Shift & Logical

ECE 372 Microcontroller Design Assembly Programming. ECE 372 Microcontroller Design Assembly Programming

Assembly Language programming (3)

Addition and Subtraction of Hexadecimal Numbers Simple assembly language programming

12/1/2016. Sorting. Savitch Chapter 7.4. Why sort. Easier to search (binary search) Sorting used as a step in many algorithms

Programming Book for 6809 Microprocessor Kit

Exam 1 Feb. 23, 25, 27?

Introduction to Embedded Microcomputer Systems Lecture 10.1

Introduction to Programming the 9S12 in C Huang Sections 5.2 and 5.3. You will be able to use all of the Motorola data manuals on the exam.

ECE/CE 3720: Embedded System Design

JUMP, LOOP AND CALL INSTRUCTIONS

Goals for This Lecture:

Computer Systems Lecture 9

History of the Microprocessor. ECE/CS 5780/6780: Embedded System Design. Microcontrollers. First Microprocessors. MC9S12C32 Block Diagram

Data Structures and Algorithms Sorting

Digital Forensics Lecture 3 - Reverse Engineering

Microcontrollers and the Freescale/Motorola HC11

Lab 1 MC9S12 Assembler and Monitor

MC9S12 Assembler Directives A Summary of MC9S12 Instructions Disassembly of MC9S12 op codes. Summary of HCS12 addressing modes ADDRESSING MODES

POTENTIOMETER. Revision Class. Instructor / Professor LICENSE

ECE 206, Fall 2001: Lab 3

Lab 4 : MIPS Function Calls

the SAP-2 I. Intro cmpt-150-arc Sections 8-8, 8-9, 9-4, 9-5, 9.6, We ll do this in bits and pieces, doing the beginning of each section first.

Programming the ARM. Computer Design 2002, Lecture 4. Robert Mullins

SRC Assembly Language Programming - III

Compiler Design. Homework 1. Due Date: Thursday, January 19, 2006, 2:00

Chapter 9 Memory Management

HC 11 Instructions! From Alex Hollowayʼs notes with! many thanks!

EE 3170 Microcontroller Applications

Subroutines. int main() { int i, j; i = 5; j = celtokel(i); i = j; return 0;}

Advanced Assembly, Branching, and Monitor Utilities

538 Lecture Notes Week 5

Preview. Memory Management

Transcription:

24.361 Lab. 4 31 ECE 3610 MICROPROCESSING SYSTEMS Laboratory 4 LAB 4: ASSEMBLER DIRECTIVES, THE STACK, SUBROUTINES, AND BUBBLE SORTING 1 INTRODUCTION This lab deals with the use of the stack and subroutines in an assembly language program. The objective of the lab is to develop a subroutine that performs a bubble sort of a list of signed numbers, sorting the numbers from smallest to largest. The bubblesort subroutine is to be designed as a library routine, so that it can be called by any HCS12 assembly language program. A calling program must be written to test the subroutine. This lab also deals with using assembler directives. 2 PREPARATION Review the lectures on the stack, subroutines, and assembler directives. 3 REQUIREMENTS AND DESIGN CONSTRAINTS 3.1 The bubblesort subroutine shall sort a list of signed numbers, sorting the numbers from smallest to largest. 3.2 The size of the list and the starting address of the list shall be passed to the bubblesort subroutine via the stack. 3.3 The bubblesort subroutine shall clean the stack prior to returning to the calling program. 3.4 The minimum size of the list shall be 2 bytes. 3.5 The maximum size of the list shall be 255 bytes. 3.6 The bubblesort subroutine shall preserve the registers it uses. 3.7 The calling program shall identify the starting address of the stack in the source code using an appropriate label and the appropriate assembler directives. 3.8 The calling program shall allocate space in USER RAM for the list of numbers using the appropriate assembler directives.

24.361 Lab. 4 32 3.9 The calling program shall allocate space for the variables starting address and size using the appropriate assembler directives and appropriate labels. 3.10 The calling program shall reference the starting address and size variables using labels. 3.11 Except for the information passed to the stack, the subroutine shall not assume to have any knowledge about the calling program s memory environment, including the starting address and size variables. 3.12 The subroutine shall not use any absolute memory locations. The subroutine can use the stack for temporary variables it may need. 4 ALGORITHM Figure 1 shows an algorithm to sort a list of numbers. The list is 5 bytes long. Without loss of generality, for simplicity, the numbers are all positive and are shown in decreasing order. The register is used as a pointer into the list, as well as an indication when to stop the inner loop. At the start of each outer loop, is initialized to the Starting Address (SA). Each time through the loop, is incremented. When = Ending Address (), this is when the inner loop is done. Notice that the is decremented each time through the outer loop. This is because when one outer loop has been completed, the largest number has been bubbled down to the bottom of the list. And the number at the bottom of the list does not need to be checked again in the next outer loop. The variable is also used to indicate when the outer loop is done, i.e., when the = SA, then the sorting is complete. Each time through the inner loop, two numbers are compared. If the first number is greater than the second, then they are swapped. The following is a piece of code that does the compare and swap: ldaa $00,x ldab $,x cba ble skip staa $,x stab $00,x skip continue,...

24.361 Lab. 4 33 Inner Loop 1 2 3 4 Outer Loop =SA 1 = 2 =SA = 3 =SA = 4 =SA = = SA =, done = Compare and swap if greater SA = Starting Address = Ending Address Inner loop is executed if not equal to Outer loop is executed if not equal to SA Fig. 1. Suggested algorithm for performing bubble sort.

24.361 Lab. 4 34 5 DELIVERABLES Draw a flow chart that represents the algorithm described in Fig. 1. In the flow chart, also identify which register(s) or memory location(s) your design will use to implement the variables: SA and. Show all detail in the flow chart. Submit the flow chart to the TA for marking. Show your working bubble sort program to your T.A. Submit your commented source code. The source code should specify how the subroutine expects to receive the input parameters, the size of the parameters, and the order in which they are sent. The source code should comment the instructions used to clean the stack. The Section Appendix A: Points to Ponder must be answered in your log book and submitted to the TA for marking by the next day following the lab. APPENDI A: POINTS TO PONDER 1. Does the assembler generate any machine code for the statement: ROMStart EQU $4000 If so, what is the machine code? What is the purpose of the EQU? What is the difference between an assembler directive and an assembly language statement? 2. Does the assembler generate any machine code for the statement: ORG RAMStart If so, what is the machine code? What is the significance of RAMStart? What is the value of RAMStart? 3. What is the maximum size of the stack? In other words, how big does the stack in the bubble- Sort subroutine grow? Is there any danger of the stack over-writing the calling program s data area? 4. Draw a memory map, showing the starting and ending addresses of all objects in USER RAM used by the calling program and the bubblesort subroutine. 5. How does the calling program pass the size of the list and the starting address of the list to the subroutine bubblesort? What other possible methods are there for passing this data to the subroutine? What are the advantages/disadvantages of the alternative methods of passing parameters to a subroutine?

24.361 Lab. 4 35 6. Does the bubblesort subroutine pass a result back to the calling program? What is the result of executing the bubblesort subroutine? 7. What objects in USER RAM are shared by the calling program and the bubblesort subroutine? 8. A design constraint was that the bubblesort subroutine must clean the stack. What is the meaning of the statement clean the stack, and explain how you implemented it. 9. Note that the calling program may also clean the stack by simply re-initializing the stack pointer to the start of the stack. Is it better to have the calling program or the subroutine to clean the stack? Explain your reason(s). 10. A design constraint was that the calling program must use labels to identify the starting address and size of the list. In addition, the bubblesort subroutine will use labels to identify branch targets. The question is: is the assembler able to assemble all of the assembly language statements, in particular, the ones that use labels, in one pass through the source code? If not, then what is the minimum number of passes through the source code that is required so that the assembler can fully assemble all assembly language statements? 11. Complete the following statement: the assembler is a -pass assembler. 12. Describe how the PSHA instruction operates in the HCS12 microprocessor used in the lab. Does this differ in any way compared with the way the PSHA instruction operates and described in the Lecture Notes? Explain any advantages or disadvantages between the two methods.