Module 1-D. Control Structure Applications. Tim Rogers 2017 [1.D]-1

Similar documents
Sample Problem Set #1

Exam I Review February 2017

Exam 2 E2-1 Fall Name: Exam 2

Lecture 9 Subroutines

Exam 2 E2-1 Fall Name: Exam 2

Programming the Motorola MC68HC11 Microcontroller

Outline. 2.8 Stack. 2.9 Subroutines

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

Module 1-G. Marcos and Structured Programming

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

C SC 230 Computer Architecture and Assembly Language April 2000 Exam Sample Solutions

Reading Assignment. 68HC12 Instruction Set. M68HC12 Instruction Set Categories. Some Tips. Endianness (Byte Order) Load and Store Instructions

Wed. Sept 6 Announcements

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

An ability to program a microcontroller to perform various tasks

Disassembly of MC9S12 op codes Decimal, Hexadecimal and Binary Numbers

Disassembly of MC9S12 op codes Decimal, Hexadecimal and Binary Numbers

Coe538 Final Study Guide 2016 (Questions & Answers)

Chapter 4: Advanced Assembly Programming. EE383: Introduction to Embedded Systems University of Kentucky. Samir Rawashdeh

Using the stack and the stack pointer

The Motorola 68HC11 Instruc5on Set

Table 1: Mnemonics Operations Dictionary. Add Accumulators Add B to Y. Add with carry to B. Add Memory to B. Add 16-bit to D And B with Memory

COE538 Lecture Notes Week 3 (Week of Sept 17, 2012)

Addressing Mode Description Addressing Mode Source Format Abbrev. Description

538 Lecture Notes Week 2

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

Binary Addition. Add the binary numbers and and show the equivalent decimal addition.

Decimal, Hexadecimal and Binary Numbers Writing an assembly language program

Assembly Language Development Process. ECE/CS 5780/6780: Embedded System Design. Assembly Language Listing. Assembly Language Syntax

Introduction to Embedded Microcomputer Systems Lecture 10.1

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

Fri. Aug 25 Announcements

ELECTRICAL AND COMPUTER ENGINEERING DEPARTMENT, OAKLAND UNIVERSITY ECE-470/570: Microprocessor-Based System Design Fall 2014.

EE319K Final Fall 2005 Solution C. (3) Question 1. (3) Question 2. short function(const short in){ return in+5; } const

EE319K Fall 2006 Quiz 1 Page 1

Department of Computer Science and Engineering

2. Arithmetic Instructions addition, subtraction, multiplication, divison (HCS12 Core Users Guide, Sections 4.3.4, and ).

(5) Question 7. Simplified memory cycles (you may or may not need all 5 entries) R/W Addr Data

EE319K Fall 2005 Quiz 1A Page 1

CMPEN 472 Sample EXAM II

538 Lecture Notes Week 3

ECE331 Handout 3- ASM Instructions, Address Modes and Directives

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

EE319K Fall 2007 Quiz 1A Page 1. (5) Question 2. What will be the value of the carry (C) bit after executing the following? ldab #210 subb #60

Disassembly of an HC12 Program It is sometimes useful to be able to convert HC12 op codes into mnemonics. For example, consider the hex code:

EB301. Motorola Semiconductor Engineering Bulletin. Programming EEPROM on the MC68HC811E2 during Program Execution. Freescale Semiconductor, I

EE319K Fall 2003 Quiz 1 Page 1

CET335 Microprocessor Interfacing Lab 5: LCD Interface (Bus Attached Peripheral)

Module 2.F. Buffered, Interrupt-Driven Printer Design Example. Tim Rogers 2017

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

ECE/CS 5780/6780: Embedded System Design

CHAPTER 8. Solutions for Exercises

EE319K Fall 2010 Exam 1B Page 1

Administrivia. ECE/CS 5780/6780: Embedded System Design. Assembly Language Syntax. Assembly Language Development Process

Lab 7: Asynchronous Serial I/O

ECE/CE 3720: Embedded System Design

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.

Chapter 2 HCS12 Assembly Language

Cross Assembly and Program Development

Exam 1 Feb. 23, 25, 27?

AN1064. Motorola Semiconductor Application Note. Use of Stack Simplifies M68HC11 Programming By Gordon Doughman. Introduction

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

EE319K Spring 2010 Exam 1A Page 1

ECET Chapter 2, Part 3 of 3

ME 6405 Introduction to Mechatronics

CS 273 Machine Programming and Organization Lecture Notes

ECET Chapter 2, Part 2 of 3

Introduction to Programming the 9S12 in C Huang Sections 5.2 and 5.3

Mark II Aiken Relay Calculator

ECE 3120 Computer Systems Arithmetic Programming

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

N bit is set if result of operation in negative (MSB = 1) Z bit is set if result of operation is zero (All bits = 0)

Motorola HC11. Fun with Microcontrollers and Embedded Systems

Introduction to Microcontrollers III

Lecture 6 Assembly Programming: Branch & Iteration

CO Computer Architecture and Programming Languages CAPL. Lecture 9

Introduction to Embedded Systems and Chapter 1: Introduction to HCS12/MC9S12. EE383: Introduction to Embedded Systems University of Kentucky

Wed. Aug 23 Announcements

Digital Fundamentals. CHAPTER 2 Number Systems, Operations, and Codes

EE 3170 Microcontroller Applications

MIGRATING TO THE 68HC12 IN C

COSC345 Software Engineering. Basic Computer Architecture and The Stack

SECTION 6 CENTRAL PROCESSING UNIT

Introduction to Microcontrollers III

538 Lecture Notes Week 3

CHAPTER 6 ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS

EE 308 Spring The HCS12 has 6 addressing modes

Lecture 11: Advanced Arithmetic Instructions

TEMPERATURE SENSOR. Revision Class. Instructor / Professor LICENSE

Lab 2 Part 1 Assembly Language Programming and 9S12 Ports

EE319K Fall 2007 Quiz 3 Page 1 of 8

; export symbols ; export 'Entry' symbol. ; include derivative specific macros PORTA EQU $0000 PORTB EQU $0001 DDRA EQU $0002 DDRB EQU $0003

Linking Assembly Subroutine with a C Program

ECE 3610 MICROPROCESSING SYSTEMS

ECE3120: Computer Systems Hardware & Software Development Tools

ECE 367 -Experiment #1 Fall 2012

Quick Guide to Using Code Warrior

MACO Multiple Agent Climbing Organism

Introduction to Microcontrollers

Menu Computer Organization Programming Model for the an example microprocessors (the G-CPU & Motorola 68HC11) Assembly Programming Look into my...

Transcription:

Module 1-D Control Structure Applications Tim Rogers 2017 [1.D]-1

Learning Outcome #1 An ability to program a microcontroller to perform various tasks How? A. Architecture and Programming Model B. Instruction Set Overview C. Assembly Control Structures D. Control Structure Applications E. Parameter Passing F. Table Lookup G. Macros and Structured Programming [1.D]-2

Objective Control Structure Applications Why? unsigned int I; for(i=1;i<=10;i++) { <statements>; } Loops are nice Whole N apps equ are? better macme loop org $800 pshb ; (2) pshx ; (2) pshy ; (2) ldx #XA ; (2) ldy #YA ; (2) movw #0,ACM ; (5) movw #0,ACM+2 ; (5) ldab #N ; (1) emacs ACM ; (13) leax 2,x ; (2) leay 2,y ; (2) dbne b,loop ; (3) puly ; (3) pulx ; (3) pulb ; (3) rts ; (5) ACM rmb 4 XA fdb?,?,? YA fdb?,?,? [1.D]-3

3 Simple apps 1. Software Delay 2. Extended-precision binary add/subtract 3. Extended-precision decimal add/subtract [1.D]-4

Software Delay Purpose: Do nothing, but for a specific amount of time Fine if you need an imprecise delay : key de-bouncing for instance Why does this end up being imprecise? Parameter-dependent overhead Interrupts Input: (A) = <Delay Time in ms> Passing arguments via registers delay_func Output: nothing [1.D]-5

Software Delay How (and this is just one way to do this): doubly-nested loop Inner loop takes 1ms (will time it based on number of cycles/instruction) Outer loop controls # times we go through inner loop One question: How many times do we need to go around the inner loop get to 1ms? [1.D]-6

Reminder Can find the exact cycle count for each insn in reference manual [1.D]-7

delay_func loopo loopi [X] = cycles pshx [2] psha [2] pshc [2] ldx # 2661 [2] Note: Need to know clock speed of CPU here, assume it is 8 MHz, i.e., each cycle is 125 ns Total Cycles = (A) * [ (X)*3 + 5] + 20 Set (A)=1ms dbne x,loopi [3] 8000 = (1) * [ (X)*3 + 5] + 20 Here, X ~ 2658 10 Set (A)=100ms dbne a,loopo [3] pulc [3] pula [3] pulx [3] rts [5] 800,000 = (100) * [ (X)*3 + 5] + 20 Here, X ~ 2664 10z [1.D]-8

N equ? Some Timing Analysis macme loop org $800 pshb ; (2) pshx ; (2) pshy ; (2) ldx #XA ; (2) ldy #YA ; (2) movw #0,ACM ; (5) movw #0,ACM+2 ; (5) ldab #N ; (1) emacs ACM ; (13) leax 2,x ; (2) leay 2,y ; (2) dbne b,loop ; (3) puly ; (3) pulx ; (3) pulb ; (3) rts ; (5) 1. If N=0, the total number of cycles consumed by macme is: A: 55 B: 235 C: 5135 D: 5155 P E: None of these ACM rmb 4 XA fdb?,?,? YA fdb?,?,? [1.D]-9

N equ? Some Timing Analysis macme loop org $800 pshb ; (2) pshx ; (2) pshy ; (2) ldx #XA ; (2) ldy #YA ; (2) movw #0,ACM ; (5) movw #0,ACM+2 ; (5) ldab #N ; (1) emacs ACM ; (13) leax 2,x ; (2) leay 2,y ; (2) dbne b,loop ; (3) puly ; (3) pulx ; (3) pulb ; (3) rts ; (5) 1. 2. If N=1, the total number of cycles consumed by macme is: A: 55 P B: 235 C: 5135 D: 5155 E: None of these ACM rmb 4 XA fdb?,?,? YA fdb?,?,? [1.D]-10

N equ? Some Timing Analysis macme loop org $800 pshb ; (2) pshx ; (2) pshy ; (2) ldx #XA ; (2) ldy #YA ; (2) movw #0,ACM ; (5) movw #0,ACM+2 ; (5) ldab #N ; (1) emacs ACM ; (13) leax 2,x ; (2) leay 2,y ; (2) dbne b,loop ; (3) puly ; (3) pulx ; (3) pulb ; (3) rts ; (5) 3. 1. If N=10, the total number of cycles consumed by macme is: A: 55 B: 235 P C: 5135 D: 5155 E: None of these ACM rmb 4 XA fdb?,?,? YA fdb?,?,? [1.D]-11

N equ? Some Timing Analysis macme loop org $800 pshb ; (2) pshx ; (2) pshy ; (2) ldx #XA ; (2) ldy #YA ; (2) movw #0,ACM ; (5) movw #0,ACM+2 ; (5) ldab #N ; (1) emacs ACM ; (13) leax 2,x ; (2) leay 2,y ; (2) dbne b,loop ; (3) puly ; (3) pulx ; (3) pulb ; (3) rts ; (5) 4. If N=255, the total number of cycles consumed by macme is: A: 55 B: 235 C: 5135 P D: 5155 E: None of these ACM rmb 4 XA fdb?,?,? YA fdb?,?,? [1.D]-12

Extended-Precision (EP) Binary Add Motivation: Want to add numbers that are bigger than 16-bits How? Assume 2 large values are in memory Use CF to propagate the carry of 8-bit adds Sort of like building large adders in HW from small adders Store pointers to the 2 numbers augend (top number), addend (bottom number) Use auto increment/decrement pointers to move addition along [1.D]-13

EP Binary Add (augend) (augend) + (addend) Storing result over one of the inputs Registers Name Value A X Y 11t 0t 51t 50t 100t 101t (augend) (X) + (addend) (Y) --------------- (result) (X) 1 ldaa 0,x 2 adca 1,y+ 3 staa 1,x+ Repeat for size of numbers X Y Memory Addr Value 50t 51t 1t 2t 100t 10t 101t 20t [1.D]-1414

Code EP Binary Add [1.D]-15

Our EP Examples Input: Assumes memory labels point to inputs addn Output: Nothing explicitly passed out, updates memory at label In effect, there really is no argument passing to this function [1.D]-16

Code EP Binary Subtract sbca [1.D]-17

Code EP Decimal Add daa [1.D]-18

EP Decimal Subtract Q: Is this just as easy? No: There is no das (decimal adjust subtraction) So how? Use daa, take the 10 s compliment of subtrahend first (flipping its sign). Then do normal adca + daa. (result) BCD (minuend) BCD + [ 99 BCD (subtrahend) BCD + 1] radix (10 s) complement of subtrahend DAA [1.D]-19

EP Decimal Subtract Add 1 to get radix complement and propagate carry [1.D]-20