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

Similar documents
Lecture 6 Assembly Programming: Branch & Iteration

ECE331 Handout 3- ASM Instructions, Address Modes and Directives

EE 3170 Microcontroller Applications

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

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

The Motorola 68HC11 Instruc5on Set

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.

Programming the Motorola MC68HC11 Microcontroller

Addressing Mode Description Addressing Mode Source Format Abbrev. Description

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

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

538 Lecture Notes Week 2

Motorola 6809 and Hitachi 6309 Programmer s Reference

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

EE 3170 Microcontroller Applications

EE 3170 Microcontroller Applications

... Executing conditional instructions

SECTION 6 CENTRAL PROCESSING UNIT

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:

Department of Computer Science and Engineering

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

Unsigned and signed integer numbers

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

Fri. Aug 25 Announcements

ARM Assembly Language. Programming

RCX internals (Revised February 24)

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

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

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

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

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

H8/500 Series Programming Manual

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

EE319K Fall 2003 Quiz 1 Page 1

Cortex M3 Programming

H8/300L Series Programming Manual

EE319K Fall 2006 Quiz 1 Page 1

instruction 1 Fri Oct 13 13:05:

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

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

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

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

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

Flow Control In Assembly

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

Exam 1. Date: Oct 4, 2018

EE319K Fall 2005 Quiz 1A Page 1

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

EECE416 :Microcomputer Fundamentals and Design Instruction Sets and Groups

Introduction to Embedded Systems EE319K (Gerstlauer), Spring 2013

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

Decimal, Hexadecimal and Binary Numbers Writing an assembly language program

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

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

ECE/CS 5780/6780: Embedded System Design

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

NET3001. Advanced Assembly

ARM Cortex-M4 Programming Model Flow Control Instructions

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

Chapter 2 HCS12 Assembly Language

Sample Problem Set #1

Disassembly of MC9S12 op codes Decimal, Hexadecimal and Binary Numbers

Disassembly of MC9S12 op codes Decimal, Hexadecimal and Binary Numbers

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

Control Flow Instructions

EE319K Spring 2010 Exam 1A Page 1

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

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

Menu. Programming Models for the Atmel XMEGA Architecture (and others devices) Assembly Programming Addressing Modes for the XMEGA Instruction Set

OSIAC Read OSIAC 5362 posted on the course website

538 Lecture Notes Week 3

ECE 3120 Computer Systems Arithmetic Programming

Part 2,Number Systems Questions

Exam I Review February 2017

ME 6405 Introduction to Mechatronics

AXIS Communications A world of intelligent networks

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

EE319K Fall 2010 Exam 1B Page 1

Word Bank - questions 1-6. Place the letter of the matching term in the space provided. (2 pts. each)

1. Memory Mapped Systems 2. Adding Unsigned Numbers

HC11 Instruction Set Architecture

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

HC11 Instruction Set Architecture

III. Flags of the Processor Staus Register

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

EE 308 Spring The HCS12 has 6 addressing modes

Motorola Semiconductor Technical Data. CPU12 Reference Guide. Figure 1. Programming Model. Order this document by CPU12RG/D Rev. 1

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

Exam 2 E2-1 Fall Name: Exam 2

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

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

H8/300H Series Software Manual

The 6502 Instruction Set

Introduction to Embedded Microcomputer Systems Lecture 6.1

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

Chapter 3: part 3 Binary Subtraction

World Inside a Computer is Binary

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)

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

Transcription:

Condition Code Register 1

Topics Condition code register Addition and subtraction instructions Conditional branches 2

Condition Code Register Condition code bits are automatically set by some instructions C bit is set if there is a carry out after an addition (or a borrow out after a subtraction) V bit is set if there was overflow after two s complement addition Only meaningful if the operation was on two s complement numbers Recall that overflow occurs if you add two positive numbers and get a negative, or two negative numbers and get a positive Z is set if the result is zero N is set if the result is negative (this is just the most significant bit) H bit is the carry out of bit position 3 ( half carry ) S,X,I are not automatically set by instructions (we will cover them later) 3

Example ADDA instruction from CPU12 Reference Manual 4

Example ldaa #$AA ; load accumulator A with $AA adda #$BC ; add $BC to accumulator A Carry out of most significant bit position Carry out of bit 3 position 1 1 1 1 carries 1 0 1 0 1 0 1 0 ($AA) + 1 0 1 1 1 1 0 0 ($BC) 0 1 1 0 0 1 1 0 Result is $66 Resulting condition code bits? Resulting condition code bits H N Z V C - - 1-0 0 1 1 - means unchanged 5

Example ldaa #$73 ; load accumulator A with $73 adda #$FA ; add $FA to accumulator A Resulting condition code bits - - - H N Z V C 6

Overflow Interpretation If adding unsigned numbers, C=1 means overflow If adding two s complement numbers, V=1 means overflow (a) If unsigned: 64 + 64 128 0 1 Ok, no overflow, and C=0. N,V bits not meaningful. 0 1 0 0 0 0 0 0 + 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 b) If two s complement: 64 + 64 128 Resulting condition code bits: N = 1 V = 1 C = 0 Z = 0 Too big; not in range -128..+127. Overflow, set V=1. 7

Example 1 1 0 0 0 0 0 0 + 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 Resulting condition code bits: N = V = C = Z = 8

Add and subtract instructions 16 bit addition instructions also set N,Z,V,C bits Subtract instructions also set N,Z,V,C bits You can test for overflow the same way (C is actually borrow-out, not carry-out) adca,adcb are used to do multiprecision addition Table 1.7 Add and subtract instructions Mnemonic aba abx aby adca <opr> adcb <opr> adda <opr> addb <opr> addd <opr> Function Add B to A Add B to X Add B to Y Add with carry to A Add with carry to B Add without carry to A Add without carry to B Add without carry to D Subtract Instructions Operation A [A] + [B] X [X] + [B] Y [Y] + [B] A [A] + [opr] + C B [B] + [opr] + C A [A] + [opr] B [B] + [opr] D [D] + [opr] Mnemonic Function Operation sba sbca <opr> sbcb <opr> suba <opr> subb <opr> subd <opr> Add Instructions Subtract B from A Subtract with borrow from A Subtract with borrow from B Subtract memory from A Subtract memory from B Subtract memory from D A [A] - [B] A [A] - [opr] - C B [B] - [opr] - C A [A] - [opr] B [B] - [opr] D [D] - [opr] 9

Conditional Branches Unlike BRA (branch always), these instructions only branch if a condition is true If the condition isn t true, execution just continues on to the next instruction Examples Test if for overflow (unsigned) ldaa adda bcs N1 N2 OVERFLOW Test if a number is zero deca beq ZERO These instructions test whether a certain bit in the condition code register is set (or clear) Branch if clear Branch if set Bit BCC BCS C BNE BEQ Z BPL BMI N BVC BVS V Test if a number is positive subd M1 bpl POSITIVE 10

Conditional Branches (continued) These instructions test a combination of condition code bits Use these immediately after doing a subtraction; e.g., N1-N2 Example ldaa N1 suba N2 bhi N1BIGGER ; go here if N1>N2 (unsigned) If you look at the definition of BHI: It branches if C + Z = 0 (the + means logic OR ) This makes sense because if C=1 then N1<N2 and we don t want to branch Also if Z=1 then N1=N2 and we don t want to branch BGE ( ) BLT (<) 2 s comp BGT (>) BLE ( ) 2 s comp BHS ( ) BLO (<) Unsigned BHI (>) BLS ( ) Unsigned 11

Summary The Condition Code Register is one of the CPU registers The bits in the CCR are automatically set as a result of executing machine code instructions You can test those bits to do things like Detect if an instruction gave a zero result, or overflow Conditionally branch, if a CCR bit is set 12