Wed. Sept 6 Announcements

Similar documents
ECE331 Handout 3- ASM Instructions, Address Modes and Directives

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

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

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

Mark II Aiken Relay Calculator

An ability to program a microcontroller to perform various tasks

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

Programming the Motorola MC68HC11 Microcontroller

Using the stack and the stack pointer

Addition and Subtraction of Hexadecimal Numbers Simple assembly language programming

Lecture 6 Assembly Programming: Branch & Iteration

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

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

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

Module 1-G. Marcos and Structured Programming

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

Fri. Aug 25 Announcements

Cross Assembly and Program Development

ME 6405 Introduction to Mechatronics

Addition and Subtraction of Hexadecimal Numbers Simple assembly language programming

Lecture 9 Subroutines

2) [ 2 marks] Both of the following statements cause the value $0300 to be stored in location $1000, but at different times. Explain the difference.

Macro Assembler. Defini3on from h6p://

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)

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

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

A Simple MC9S12 Program

Chapter 2 HCS12 Assembly Language

It translates (converts) assembly language to machine code.

Microcontrollers. 2IN60: Real-time Architectures (for automotive systems) Mike Holenderski,

Exam I Review February 2017

Decimal, Hexadecimal and Binary Numbers Writing an assembly language program

EE319 K Lecture 3. Introduction to the 9S12 Lab 1 Discussion Using the TExaS simulator. University of Texas ECE

EE 3170 Microcontroller Applications

Coe538 Final Study Guide 2016 (Questions & Answers)

EE 3170 Microcontroller Applications

Programming Book for 6809 Microprocessor Kit

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

ECET Chapter 2, Part 2 of 3

MIGRATING TO THE 68HC12 IN C

Disassembly of MC9S12 op codes Decimal, Hexadecimal and Binary Numbers

Disassembly of MC9S12 op codes Decimal, Hexadecimal and Binary Numbers

538 Lecture Notes Week 3

Wed. Aug 23 Announcements

Lecture 5 Assembly Programming: Arithmetic

EE4390 Microprocessors

Lab 2 Part 1 Assembly Language Programming and 9S12 Ports

EE 308 Spring The HCS12 has 6 addressing modes

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

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

m 1 se 7 m 23 Introduction to Embedded Microcomputer Systems Lecture 16.1 Recap Finite State Machines Pointer implementation

Sample Problem Set #1

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

ECE 367 -Experiment #1 Fall 2012

HC11 Instruction Set Architecture

HC11 Instruction Set Architecture

Homework 12 Solutions

Branch Addressing. Jump Addressing. Target Addressing Example. The University of Adelaide, School of Computer Science 28 September 2015

EMCH 367 Fundamentals of Microcontrollers Example_Sort EXAMPLE SORT

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

Introduction to Programming

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

COSC345 Software Engineering. Basic Computer Architecture and The Stack

538 Lecture Notes Week 2

Lecture #3 Microcontroller Instruction Set Embedded System Engineering Philip Koopman Wednesday, 20-Jan-2015

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

Outline. 2.8 Stack. 2.9 Subroutines

ECE3120: Computer Systems Hardware & Software Development Tools

BRANCH IF REGISTER IS HIGHER/GREATHER/ THAN OPERAND e.g. CMPA #$D0

1. Memory Mapped Systems 2. Adding Unsigned Numbers

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

Lecture 11: Advanced Arithmetic Instructions

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.

Quick Guide to Using Code Warrior

NAME asm cross-assembler SYNOPSIS

Introduction to the 9S12 Microcontroller

Introduction to Embedded Systems. Some Nagging

Introduction to Embedded Microcomputer Systems Lecture 10.1

538 Lecture Notes Week 3

538 Lecture Notes Week 5

ECE 331: PC Lab 3 Stack and Subroutines

HC11 Instruction Set

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

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

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

Principles of Compiler Design

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

Module 7: Address Registers & Array Processing

ORG ; TWO. Assembly Language Programming

Experiment 3 3 Basic Input Output

Lecture 2: The Instruction Set Architecture

ECET Chapter 2, Part 3 of 3

Timing Generation and Measurements

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

Quick Reference Guide

538 Lecture Notes Week 5

Assembly Language programming (1)

Addressing Mode Description Addressing Mode Source Format Abbrev. Description

We will study the MIPS assembly language as an exemplar of the concept.

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

Transcription:

Wed. Sept 6 Announcements HW 3 / Lab 3 posted [1.C]-1

Endianness Problem: Memory is byte addressed. Sometimes you want to access multi-byte values (16-bit, 32-bits etc.) X is 2-bytes Addr Memory Value LDX $100 There is only 1-byte at address $100 99 100 101 $12 $34 $56 Q: Where does the other byte come from? Q: What is the final value loaded into X? A: 101 A: $3456 Q: Is that the ONLY possibility? [1.C]-2

Endianness X = $3456 LDX $100 Address Points to BIG byte of the number Big Endian Addr 99 100 101 Memory Value $12 $34 $56 9S12 (ECE 362) X = $5634 LDX $100 Address Points to little byte of the number Little Endian Addr 99 100 101 Memory Value $12 $34 $56 [1.C]-3

Indexed-Indirect with constant offset Review Abbrev. Name Description Examples [IDX2] Indexed-Indirect with Constant Offset X A Eff. address = ((<X Y SP PC>) + signed_const) Example Instruction LDAA [0,Y] ADDA [5,X] Memory 2 memory lookups Eff Address (H) Eff Address (L) Indirect Address + Assembly Instruction opcode postbyte offset high offset low ADDA [5,X] 1010 1011 1110 0011 0000 0000 0000 0101 [1.C]-4

Pointless Clicker Question #3 What is the result after the instruction: Review ADDA [0,X] Memory Addr Value 0 0t A: A=12t, X = 0t B: A=17t, X = 0t P C: A=21t, X = 2t D: A=21t, X = 0t E: I am too lost to try Regs Name Value A 10t 1 2t 2 7t 3 0t X 0t 65534 7t [1.C]-5

Module 1-C Assembly Control Structures Tim Rogers 2017 [1.C]-6

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. Table Lookup F. Parameter Passing G. Macros and Structured Programming [1.C]-7

Objective Assembly Control Structures Typically High-level lang. code Why? Compiler Eg. gcc,vscc, cw Assembly Code Right now ECE 362 Still useful to think about high-level language constructs: loops, conditionals, etc [1.C]-8

But First Some Background Pseudo Ops Tells assembler to do something without generating any code These pseudo ops are specific to each dev env These can make your assembly coding life easier and your code easier to read. [1.C]-9

Key Code Warrior Pseudo Ops Pseudo op Description Example ORG RMB EQU Originate code. Sets the memory address of the code that follows Reserve Memory Byte. Allocates (but does not initialize) memory. Equate a label with a org $800 ldaa #5 ; This instruction starts at $800 label RMB 2 ; reserve 2 bytes starting at label loopiterations EQU 5 ; Assembler will replace loopiterations with 5 numeric value FCB Form Constant Byte. value FCB 8 ; the label value points to memory initialized to 8 FDB Form Double Byte value FDB $FFFF ; the label value points to the high byte of memory initialized to $FFFF [1.C]-10

Key Code Warrior Pseudo Ops Pseudo op Description Example FCC Form Constant Character string fcc This is a string ; label string now points to the quoted text INCLUDE Include another assembly file include myfile.asm END Reserve Memory Byte. Allocates (but does not initialize) memory. ; some code end I can write whatever I want here, cause the assembler will stop looking. [1.C]-11

Expressions Can include these in the operand field of some instructions Executed on your desktop at assembly time, not on the 9S12 at runtime. Examples: ldaa #2*value/37 bne exit+1 staa mem+2 [1.C]-12

Strings Quoted strings are converted to equivalent ASCII characters by the assembler program Examples: cmpa #'J' string fcc Hello world [1.C]-13

Labels Labels are symbols used to represent memory locations in which program or data are stored When used in the operand field of a transfer-ofcontrol instruction, the assembler converts these symbols to absolute locations (for jump instructions) or signed relative offsets (for branch instructions) Examples: org $800 jmp iloop ; address is $803 iloop bra iloop ; offset is $FE [1.C]-14

Control Structures Naïve and optimized ways to transform them Roughly the equivalent of turning off/on optimizations in your compiler Naïve versions are much easier to understand and are a 1:1 translation of the original source code. [1.C]-15

IF-ELSE IF C Syntax: if (condition 1) <statement 1>; else if (condition 2) <statement 2>; else if (condition 3) <statement 3>; Example: if(i==1) pay=100; else if(i==2) pay=200; else if(i==3) pay=300; else if(i==4) pay=400; Hand Compilation: ; variables i rmb 1; pay rmb 2; ; Assume some code sets i if1 if2 if3 if4 Notice that the conditions are inverted ldaa i cmpa #1 bne if2 movw #100,pay bra if_end cmpa #2 bne if3 movw #200,pay bra if_end cmpa #3 bne if4 movw #300,pay bra if_end cmpa #4 bne if_end movw #400,pay if_end [1.C]-16

SWITCH (CASE) C Syntax: switch (variable) { } case value 1: <statement 1>; break; case value 2: <statement 2>; break; case value 3: <statement 3>; break; default: <statement default>; Example: switch(i) { case 1: pay=100; break; case 2: pay=200; break; case 3: pay=300; break; case 4: pay=400; break; default: pay=0; } Hand Compilation: ; variables i rmb 1; pay rmb 2; ; Assume some code sets i case_start ldaa i case1 cmpa #1 bne case2 movw #100,pay bra case_exit case2 cmpa #2 bne case3 movw #200,pay bra case_exit case3 cmpa #3 bne case4 movw #300,pay bra case_exit case4 cmpa #4 bne default movw #400,pay bra case_exit default movw #0,pay case_exit [1.C]-17

FOR C Syntax: for (variable initialization; condition; variable update) { <statements executed while condition is true>; } Hand Compilation: Example: unsigned int I; for(i=1;i<=10;i++) { ; } 16-bit unsigned control variable I rmb 2 for_start movw #1,I for_loop ldd I cpd #10 bhi for_exit ldd I addd #1 std I bra for_loop for_exit [1.C]-18

WHILE C Syntax: while (condition) { <statements executed while condition is true>; } Example: unsigned int I; I=1; while(i<=10) { ; I++; } 16-bit unsigned control variable Hand Compilation: I rmb 2 while_start movw #1,I while_loop ldd I cpd #10 bhi while_exit ldd I addd #1 std I bra while_loop while_exit In this while, assembly is identical to for [1.C]-19

DO WHILE C Syntax: do { <statements executed while condition is true>; } while (condition) Example: unsigned int I; I=1; do { ; I++; } while(i<=10) 16-bit unsigned control variable In do, the conditions are the same Hand Compilation: I rmb 2 dowhile_start movw #1,I dowhile_loop ldd I addd #1 std I cpd #10 bls dowhile_loop dowhile_exit [1.C]-20

Some optimized loop constructs Prof. Meyer referred to these as assembly style Need to be careful about register bounds. i.e. a loop with an 8-bit counter can only go around a limited number of times [1.C]-21

Optimized FOR (0 255) Key: Use registers as loop counters ITER EQU ; unsigned byte ( char ) calculation of ITER+1 is done at assembly time for_start ldab #ITER+1 for_loop dbeq b,for_exit bra for_loop for_exit Basic idea: Count (B) down, and use the ZERO condition as a completion indicator make use of compound decrement and branch instruction [1.C]-22

Optimized FOR (0 65,535) Key: Use registers as loop counters calculation of ITER+1 is done at assembly time ITER EQU for_start ldx #ITER+1 for_loop dbeq x,for_exit ; unsigned word ( int ) Basic idea: Count (X) down, and use the ZERO condition as a completion indicator make use of compound decrement and branch instruction bra for_loop for_exit Note: In optimized FOR constructs, the loop overhead is reduced to 3 instructions [1.C]-23

Optimized DO (1 256) ITER EQU ; unsigned byte ( char ) do_start ldab #ITER do_loop code block is executed at least once dbne b,do_loop do_exit completion check at bottom of loop [1.C]-24

Optimized DO (1 65,536) ITER EQU ; unsigned word ( int ) do_start ldx do_loop #ITER code block is executed at least once dbne x,do_loop do_exit completion check at bottom of loop Note: In optimized DO constructs, the loop overhead is reduced to 2 instructions [1.C]-25