Introduction to Embedded Microcomputer Systems Lecture 8.1. Computers in the future may weigh no more than 1.5 tons Popular Science, 1949

Similar documents
Condition Code Register. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff

EE 3170 Microcontroller Applications

Lecture 6 Assembly Programming: Branch & Iteration

ECE331 Handout 3- ASM Instructions, Address Modes and Directives

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.

EE 3170 Microcontroller Applications

Programming the Motorola MC68HC11 Microcontroller

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

The Motorola 68HC11 Instruc5on Set

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

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

Unsigned and signed integer numbers

EE319K Exam 1 Summer 2014 Page 1. Exam 1. Date: July 9, Printed Name:

538 Lecture Notes Week 2

ARM Cortex-M4 Programming Model Flow Control Instructions

EE319K Fall 2013 Exam 1B Modified Page 1. Exam 1. Date: October 3, 2013

Exam 1 Fun Times. EE319K Fall 2012 Exam 1A Modified Page 1. Date: October 5, Printed Name:

INTRODUCTION TO BRANCHING. There are two forms of unconditional branching in the MC68000.

A block of memory (FlashROM) starts at address 0x and it is 256 KB long. What is the last address in the block?

Motorola 6809 and Hitachi 6309 Programmer s Reference

Exam 1. Date: Oct 4, 2018

Introduction to Embedded Microcomputer Systems Lecture 10.1

CprE 288 Introduction to Embedded Systems ARM Assembly Programming: Translating C Control Statements and Function Calls

RCX internals (Revised February 24)

... Executing conditional instructions

EE319K Spring 2015 Exam 1 Page 1. Exam 1. Date: Feb 26, 2015

EE319K Spring 2016 Exam 1 Solution Page 1. Exam 1. Date: Feb 25, UT EID: Solution Professor (circle): Janapa Reddi, Tiwari, Valvano, Yerraballi

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

Introduction to Embedded Microcomputer Systems Lecture 6.1

(2) Part a) Registers (e.g., R0, R1, themselves). other Registers do not exists at any address in the memory map

ARM Assembly Language. Programming

EE 3170 Microcontroller Applications

NET3001. Advanced Assembly

Addressing Mode Description Addressing Mode Source Format Abbrev. Description

CprE 288 Introduction to Embedded Systems Course Review for Exam 3. Instructors: Dr. Phillip Jones

0b) [2] Can you name 2 people form technical support services (stockroom)?

OSIAC Read OSIAC 5362 posted on the course website

Reconfigurable Computing Systems ( L) Fall 2012 Tiny Register Machine (TRM)

EECE416 :Microcomputer Fundamentals and Design Instruction Sets and Groups

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

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

Introduction to Embedded Systems EE319K (Gerstlauer), Spring 2013

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

Flow Control In Assembly

Outline. ARM Introduction & Instruction Set Architecture. ARM History. ARM s visible registers

Exam 1 Feb. 23, 25, 27?

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

Mark II Aiken Relay Calculator

Introduction to Microcontrollers II

H8/300L Series Programming Manual

Chapter 04: Instruction Sets and the Processor organizations. Lesson 08: Processor Instructions - Part 1

Introduction to Microcontrollers II

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

SECTION 6 CENTRAL PROCESSING UNIT

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

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

H8/500 Series Programming Manual

Immediate vs. Extended mode: Immediate values are marked with a # symbol. They also are different instructions when assembled.

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.

Decimal, Hexadecimal and Binary Numbers Writing an assembly language program

538 Lecture Notes Week 3

538 Lecture Notes Week 3

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

ECE/CS 5780/6780: Embedded System Design

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

Cortex M3 Programming

CE-320 Microcomputers I Winter 2010 LAB 1: MINIIDE GROUP #: NAME: PARTNER: Lab 1 Page 1

The Assembly Language of the Boz 5

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

Lecture 5 Assembly Programming: Arithmetic

Xuan Guo. Lecture XIV: Review of Chapter 3 & 4. CSC 3210 Computer Organization and Programming Georgia State University. March 5, 2015.

ARM Instruction Set Architecture. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Exam I Review February 2017

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:

Computer Internals ECE2036. Lecture 2. ECE2036 Computer Internals Spring / 12

Introduction to Computers - Chapter 4

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

1. Memory Mapped Systems 2. Adding Unsigned Numbers

Programming. A. Assembly Language Programming. A.1 Machine Code. Machine Code Example: Motorola ADD

TABLE 9-1. Symbolic Convention for Addressing Modes. Register indirect LDA (R1) ACC M[ R1] Refers to Figure 9-4. Addressing mode. Symbolic convention

538 Lecture Notes Week 5

III. Flags of the Processor Staus Register

538 Lecture Notes Week 5

COSC 243. Instruction Sets And Addressing Modes. Lecture 7&8 Instruction Sets and Addressing Modes. COSC 243 (Computer Architecture)

Exam 2 E2-1 Fall Name: Exam 2

The 6502 Instruction Set

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

10-1 C D Pearson Education, Inc. M. Morris Mano & Charles R. Kime LOGIC AND COMPUTER DESIGN FUNDAMENTALS, 4e

Course Administration

COSC345 Software Engineering. Basic Computer Architecture and The Stack

Exam 2 E2-1 Fall Name: Exam 2

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

Assembler: Basics. Alberto Bosio October 20, Univeristé de Montpellier

MIPS Memory Access Instructions

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

COMP MIPS instructions 2 Feb. 8, f = g + h i;

LAB 1: MC68000 CPU PROGRAMMING DATA TRANSFER INSTRUCTIONS

Sample Problem Set #1

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

Transcription:

Introduction to Embedded Microcomputer Systems Lecture 8.1 Computers in the future may weigh no more than 1.5 tons Popular Science, 1949 Recap Debugging: Monitor, dump TExaS Real 9S12DG Overview Addition and subtraction set CCR bits Subtraction used for conditional branching Read sections 3.8, and 5.2 in the book Watch movies on Example 3.9, 3.10, 3.11, 3.12 on the web Condition code register (CC or CCR) C set after an unsigned add if the answer is wrong V set a signed add if the answer is wrong bit name meaning after add or sub N negative result is negative Z zero result is zero V overflow signed overflow C carry unsigned overflow Table 3.. Condition code bits. + 224+ + 224 0 + Figure 3.20. Unsigned number wheel. 0 224 0 Figure 3.22. Unsigned number wheel. Observation: The carry bit, C, is set after an unsigned addition or subtraction when the result is incorrect.

Introduction to Embedded Microcomputer Systems Lecture 8.2 - + -+ + - - 127 Figure 3.23. Signed number wheel. - 127 + - - - - 127 Figure 3.24. Signed number wheel - 127 Observation: The overflow bit, V, is set after a signed addition or subtraction when the result is incorrect. Let the result R be the result of the addition A+B. N bit is set if unsigned result is above 127 or if signed result is negative. N = R7 Z bit is set if result is zero. Z = R7 & R6 & R5 & R4 & R3& R2 & R1& R0 V bit is set after a signed addition if result is incorrect V = A7 & B7 & R7 + A7 & B7 & R7 C bit is set after an unsigned addition if result is incorrect C = A7 & B7 + A7 & R7 + B7 & R7 Let the result R be the result of the subtraction A-B. N bit is set if unsigned result is above 127 or if signed result is negative. N = R7 Z bit is set if result is zero.

Introduction to Embedded Microcomputer Systems Lecture 8.3 Z = R7 & R6 & R5 & R4 & R3& R2 & R1& R0 V bit is set after a signed subtraction if result is incorrect V = A7 & B7 & R7 + A7 & B7 & R7 C bit is set after an unsigned subtraction if result is incorrect C = A7 & B7 + B7 & R7 + A7 & R7 Question 1a. What will be the value of the overflow (V) bit after executing the following? ldaa #-100 adda #50 Question 1b. What will be the value of the carry (C) bit after executing the following? ldaa #156 adda #50 Question 2a. What will be the value of the overflow (V) bit after executing the following? ldaa # -100 adda #-50 Question 2b. What will be the value of the carry (C) bit after executing the following? ldaa # 156 adda #206 Question 3. What will be the value of the carry (C) bit after executing the following? ldab #210 subb #60 Question 4. What will be the value of the overflow (V) bit after executing the following? ldaa #-70 suba #-60 Common Error: Ignoring overflow (signed or unsigned) can result in significant errors. Observation: Microcomputers have two sets of conditional branch instructions (if statements) that make program decisions based on either the C or V bit. Promotion involves increasing the precision of the input numbers, and performing the operation at that higher precision. decimal 8-bit -bit 224 1110,0000 0000,0000,1110,0000 + +0100,0000 +0000,0000,0100,0000 288 0010,0000 0000,0001,0010,0000 We can check the -bit intermediate result to see if the answer will fit back into the 8-bit result. unsigned add promote B to B R =A +B ok overflow R < 255 R >255 R R=R R=255 ok R > 0 R=R unsigned sub promote B to B R =A -B underflow R < 0 R R=0 Figure 3.25. Promotion to detect and correct unsigned arithmetic errors.

Introduction to Embedded Microcomputer Systems Lecture 8.4 Write C code to solve one of these To promote a signed number, we duplicate the sign bit decimal 8-bit -bit - 1010,0000 1111,1111,1010,0000 - -0100,0000-0000,0000,0100,0000-0 0110,0000 1111,1111,0110,0000 signed add promote B to B signed sub promote B to B R =A +B R =A -B underflow overflow underflow overflow R < - R >127 R < - R >127 R R R = - R=127 R = - R=127 R=R R=R Figure 3.26. Flowcharts showing how to use promotion to detect and correct signed arithmetic errors. Write C code to solve one of these Common Error: Even though most C compilers automatically promote to a higher precision during the intermediate calculations, they do not check for overflow when demoting the result back to the original format. bcc l1 ;jump to l1 if C=0 bcs l2 ;jump to l2 if C=1 bvc l3 ;jump to l3 if V=0 bvs l4 ;jump to l4 if V=1 bpl l5 ;jump to l5 if N=0 bmi l6 ;jump to l6 if N=1 bne l7 ;jump to l7 if Z=0 beq l8 ;jump to l8 if Z=1 ceiling and floor unsigned add unsigned sub R=A+B R=A-B C C=0 C=1 R=255 C C=0 C=1 R=0 Figure 3.27. Flowcharts showing how to use overflow bits to detect and correct unsigned arithmetic errors. Assume A8 B8 and R8 are three 8-bit (1-byte) global variables defined in RAM. A8 ds 1 ;Input B8 ds 1 ;Input R8 ds 1 ;Output The following assembly language adds two unsigned 8-bit numbers, using the algorithm presented in Figure 2.33. ldaa A8 ;get first input adda B8 ;A8+B8

Introduction to Embedded Microcomputer Systems Lecture 8.5 OK1 bcc OK1 ;if C=0, then no error, ldaa #255 ;overflow staa R8 The following assembly language subtracts two unsigned 8-bit numbers. ldaa A8 ;get first parameter suba B8 ;A8-B8 bcc OK2 ;if C=0, then no error, ldaa #0 ;underflow OK2 staa R8 C code assembly code if(g2 == G1){ isequal(); bne jsr isequal if(g2!= G1){ isnotequal(); beq jsr isnotequal ldd H2 if(h2 == H1){ cpd H1 isequal(); bne jsr isequal ldd H2 if(h2!= H1){ cpd H1 isnotequal(); beq jsr isnotequal Table 5.1. Conditional structures that test for equality. Signed conditional branch bge target ;Branch if signed greater than or equal to, ;if (N^V)=0, or (~N V+N ~V)=0 bgt target ;Branch if signed greater than, ;if (Z+N^V)=0, or (Z+~N V+N ~V)=0 ble target ;Branch if signed less than or equal to, ;if (Z+N^V)=1, or (Z+~N V+N ~V)=1 blt target ;Branch if signed less than, ;if (N^V)=1, or (~N V+N ~V)=1 C code if(g2 > G1){ isgreater(); if(g2 >= G1){ isgreatereq(); assembly code ble jsr isgreater blt jsr isgreatereq

Introduction to Embedded Microcomputer Systems Lecture 8.6 if(g2 < G1){ isless(); if(g2 <= G1){ islesseq(); Table 5.3. Signed conditional structures. bge jsr isless bgt jsr islesseq Unsigned conditional branch bhs target ;Branch if unsigned greater than or equal to, ;if C=0, same as bcc bhi target ;Branch if unsigned greater than, ;if C+Z=0 blo target ;Branch if unsigned less than, ;if C=1, same as bcs bls target ;Branch if unsigned less than or equal to, ;if C+Z=1 C code if(g2 > G1){ isgreater(); if(g2 >= G1){ isgreatereq(); if(g2 < G1){ isless(); if(g2 <= G1){ islesseq(); Table 5.2. Unsigned conditional structures. assembly code bls jsr isgreater blo jsr isgreatereq bhs jsr isless bhi jsr islesseq The bottom line Use C bit, bhi, bhs, blo, bls for unsigned numbers Use V bit, bgt, bge, blt, ble for signed numbers Zero pad for unsigned 8 to bit conversion Sign ext for signed 8 to bit conversion Overflow detection using C and V bits Overflow correction using promotion or ceiling/floor