ECE 3430 – Intro to Microcomputer Systems

Slides:



Advertisements
Similar presentations
Microprocessors.
Advertisements

Chapter 3 Introduction to the 68000
EECC250 - Shaaban #1 Lec # 2 Winter Addressing Modes  Addressing modes are concerned with the way data is accessed  Addressing can be.
Control Structures in ARM Implementation of Decisions Similar to accumulator instructions One instruction sets the flags, followed by another instruction.
Programming 68HC11.
EET 2261 Unit 5 Tables; Decision Trees & Logic Instructions
Revised: Aug 1, EE4390 Microprocessors Lesson 6,7 Instruction Set, Branch Instructions, Assembler Directives.
Assembler Programming Chapter 6. EEL-4746 Best Practices.
© 2010 Kettering University, All rights reserved..
1 ECE 372 – Microcontroller Design Basic Assembly Programming for(j=0; j
CEG 320/520: Computer Organization and Assembly Language ProgrammingFlow Control 1 Flow Control.
© 2010 Kettering University, All rights reserved..
The M68HC11 Basic Instruction Set Basic Arithmetic Instructions
ECE 265 – LECTURE 8 The M68HC11 Basic Instruction Set The remaining instructions 10/20/ ECE265.
© 2010 Kettering University, All rights reserved..
Lecture 8. MIPS Instructions #3 – Branch Instructions #1 Prof. Taeweon Suh Computer Science Education Korea University 2010 R&E Computer System Education.
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
ECE 447: Lecture 12 Logic, Arithmetic, Data Test and Control Instructions of MC68HC11.
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction.
Machine Language ELEC 330 Digital Systems Engineering Dr. Ron Hayne.
1 ECE 372 – Microcontroller Design Assembly Programming HCS12 Assembly Programming Addressing Modes Stack Operations Subroutines.
1 Introduction to Microcontroller Microcontroller Fundamentals & Programming.
ECE Lecture 21 Typical Assembly Language Program Bugs.
1 Microcontroller Fundamentals & Programming Addressing Modes.
Microcontroller Fundamentals & Programming Arithmetic Instructions.
ECE 447: Lecture 16 Common Errors & Good Programming Style.
ECE 447: Lecture 11 Introduction to Programming in Assembly Language.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 11 Conditional Operations.
Embedded Systems Lecture 5 January 25 th, 2016.
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction.
1 ECE 372 – Microcontroller Design Basic Assembly Programming for(j=0; j
EE345 Chapter 2 Lecture 3 April Instruction and addressing modes 1.Extended Addressing 2.Direct Addressing 3.Inherent Addressing 4.Immediate Addressing.
ARM Instructions ARM instructions are written as an operation code (opcode), followed by zero or more operands Operands may be constants (8-bit value),
5-1 EE 319K Introduction to Microcontrollers Lecture 5: Conditionals, Loops, Modular Programming, Sub- routines, Parameter passing.
ECE 3430 – Intro to Microcomputer Systems
ECE 3430 – Intro to Microcomputer Systems
Slide 7 Mikroprosesor Sub. Algoritma Program___
Addressing Modes in Microprocessors
Status Register Status = system byte (supervisor only) + user byte = system status + condition code register usually, it is not important to know.
ECE 3430 – Intro to Microcomputer Systems
Control Unit Lecture 6.
Assembly Language Programming of 8085
ECE 3430 – Intro to Microcomputer Systems
Homework Reading Labs PAL, pp
ECE 3430 – Intro to Microcomputer Systems
ECE 3430 – Intro to Microcomputer Systems
ECE 3430 – Intro to Microcomputer Systems
Decision Making.
Wed. Sept 6 Announcements
Conditional Branches What distinguishes a computer from a simple calculator is its ability to make decisions Decisions are made using the if statement,
Lecture 4 ( Assembly Language).
Flags Register & Jump Instruction
ME4447/6405 Microprocessor Control of Manufacturing Systems and
ECE 3430 – Intro to Microcomputer Systems
Branching and Loops.
CSC 3210 Computer Organization and Programming
ECE 3430 – Intro to Microcomputer Systems
ECE 3430 – Intro to Microcomputer Systems
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ECE 3430 – Intro to Microcomputer Systems
University of Gujrat Department of Computer Science
Homework Reading Machine Projects Labs PAL, pp
Write a program to calculate x**y, given x and y.
Physics 413 Chapter 2.
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS
Branch & Call Chapter 4 Sepehr Naimi
ECE511: Digital System & Microprocessor
An Introduction to the ARM CORTEX M0+ Instructions
Presentation transcript:

ECE 3430 – Intro to Microcomputer Systems ECE 3430 – Introduction to Microcomputer Systems University of Colorado at Colorado Springs Lecture #10 Agenda Today 1) Branch Instructions/Conditional Branches 2) CCR flags: N,H,Z,V,C Flags 3) Compare Instructions Lecture #10 ECE 3430 – Intro to Microcomputer Systems Fall 2009

Branch Instructions We need a way to alter the flow of program execution when specific conditions exist. This allows our programs to dynamically adjust to input. The Condition Code Register provides the status of the CPU. CCR[7:0] = {S,X,H,I,N,Z,V,C} S = Stop Disable X = X interrupt mask H = Half Carry I = I interrupt mask N = Negative Result Z = Zero Result V = Overflow C = Carry START LDAA INCA ACCA=10? NO YES Only these flags affect behavior of conditional branch instructions STAA END Lecture #10 ECE 3430 – Intro to Microcomputer Systems Fall 2009

ECE 3430 – Intro to Microcomputer Systems Branch Instructions CCR[7:0] = {S,X,H,I,N,Z,V,C} - These flags are altered upon execution of an instruction (check pink book to see which flags). - We can use a conditional branch instruction depending on these flags to set the new value of the PC. - A branch occurs when the PC is set to different place in the code (besides the next sequential instruction). - Branches in the HC11 always use 8-bit relative addressing. This gives a range of –128 to +127 memory locations relative to where the PC is starting. In other words, the PC can be changed to a value within –128 to +127 of the current PC location. - Labels provide an easy way to mark the destination of a branch. This way, the assembler can calculate the branch instruction’s operand value for you! - Unconditional Branch – BRA is an instruction that will always branch when executed regardless of what bits are set in the CCR. BRN is an instruction that never branches (another no-op instruction). BRA/BRN are the only two unconditional branch instructions in HC11 instruction set. - Conditional Branch – When executed, it will check the CCR. If the branch condition is true, it will set the PC to the new address location. If the branch condition is false, it will increment the PC as in normal operation. All branch instructions other than BRA/BRN in the HC11 instruction set are conditional. Lecture #10 ECE 3430 – Intro to Microcomputer Systems Fall 2009

ECE 3430 – Intro to Microcomputer Systems Conditional Branches Carry Flag Branches BCC = branch if carry clear, C=0 BCS = branch if carry set, C=1 BHS = branch if higher or same, C=0 BLO = branch if lower, C=1 ORG $E000 LDAA #$F0 MAIN: ADDA #$01 BCC MAIN ; C = 0 = branch ; C = 1 = no branch STAA $40 END Why can’t we use INCA rather than ADDA #$01? START alias A = $F0 alias A = A +1 SUM > 255? NO YES M($40) = A END Lecture #10 ECE 3430 – Intro to Microcomputer Systems Fall 2009

ECE 3430 – Intro to Microcomputer Systems Conditional Branches Carry Flag Branches How many times did this loop execute? Loop1 – A=$F1 Loop2 – A=$F2 Loop3 – A=$F3 : : Loop15 – A=$FF Loop16 – A=$00, C=1, No Branch ANSWER = 16 times START A = $F0 A = A +1 SUM > 255? NO YES M($40) = A END Lecture #10 ECE 3430 – Intro to Microcomputer Systems Fall 2009

Conditional Branches YES NO END No operation, used for timing Carry Flag Branches – Add M($40) and M($41) - If the result is =< 255, store to Port D and END - If the result is > 255, set PA4 (clear all other bits in port A) and END ORG $E000 MAIN: LDAA $40 ADDA $41 BCS ERROR ; C = 1 = branch ; C = 0 = no branch STAA $08 BRA FINISH ERROR: LDAA #%00010000 STAA $00 NOP FINISH: BRA FINISH START M($40) + M($41) SUM > 255? YES PA4 = 1 NO PortD = sum END No operation, used for timing Lecture #10 ECE 3430 – Intro to Microcomputer Systems Fall 2009

ECE 3430 – Intro to Microcomputer Systems Conditional Branches Carry Flag Branches – What does the machine code look like? Label Addr Data INST Bytes Cycles MAIN $E000 $96 LDAA $40 2 3 $E001 $40 - $E002 $9B ADDA $41 2 3 $E003 $41 - $E004 $25 BCS ERROR 2 3 $E005 $REL - $E006 $97 STAA $08 2 3 $E007 $08 - $E008 $20 BRA FINISH 2 3 $E009 $REL - ERROR $E00A $86 LDAA #%00010000 2 3 $E00B $10 - $E00C $97 STAA $00 2 3 $E00D $00 - $E00E $01 NOP 1 2 FINISH $E00F - Lecture #10 ECE 3430 – Intro to Microcomputer Systems Fall 2009

ECE 3430 – Intro to Microcomputer Systems Conditional Branches How long does it take to execute if the branch IS taken? LDAA $40 3 ADDA $41 3 BCS ERROR 3 … LDAA #%00010000 3 STAA $00 3 NOP 2 (17 cycles)(500ns) = 8.5us How long does it take to execute if the branch IS NOT taken? LDAA $40 3 ADDA $41 3 BCS ERROR 3 STAA $08 3 BRA FINISH 3 (15 cycles)(500ns) = 7.5us What is the average execution time? (7.5us + 8.5us) = 8us 2 Lecture #10 ECE 3430 – Intro to Microcomputer Systems Fall 2009

ECE 3430 – Intro to Microcomputer Systems Conditional Branches Zero Flag Branches BEQ = branch if equal to zero, Z=1 BNE = branch if NOT equal to zero, Z=0 Ex) loop 10 times ORG $E000 LDAA #10 LOOP: DECA BNE LOOP ; Z = 0 = branch ; Z = 1 = no branch END START count = 10 count = count - 1 count = 0? NO YES END Lecture #10 ECE 3430 – Intro to Microcomputer Systems Fall 2009

ECE 3430 – Intro to Microcomputer Systems Conditional Branches Zero Flag Branches How many loops? Loop1 –> A=9 Loop2 –> A=8 : Loop10 –> A=0 (Z=1, branch NOT taken) How long to execute? LOOP -> DECA 2 cycles BNE 3 cycles (5 cycles)(10 loops) = 50 cycles + LDAA #10 2 cycles TOTAL = (52 cycles)(500ns) = 26 us START count = 10 count = count - 1 count = 0? NO YES END Lecture #10 ECE 3430 – Intro to Microcomputer Systems Fall 2009

ECE 3430 – Intro to Microcomputer Systems Conditional Branches Negative Flag Branches BPL = branch if positive, N=0 BMI = branch if minus, N=1 Can be used during subtraction to indicate the value was negative. ex) M($40) – M($41) if positive, END if negative or zero, set PA4 (clear all other bits on port A) ORG $E000 LDAA $40 SUBA $41 BPL DONE LDAA #%00010000 STAA $00 DONE: BRA DONE END Lecture #10 ECE 3430 – Intro to Microcomputer Systems Fall 2009

ECE 3430 – Intro to Microcomputer Systems Conditional Branches Two’s Complement Overflow Flag Branches BVS = branch if overflow occurred, V=1 BVC = branch if NO overflow occurred, V=0 Other Useful Branches (using combinations of CCR flags) BGE = branch if greater than or equal to ; N  V = 0 BLT = branch if less than ; N  V = 1 BGT = branch if greater than ; Z + (N  V) = 0 BLE = branch if less than or equal to ; Z + (N  V) = 1 BHI = branch if higher ; C + Z = 0 BLS = branch if lower or the same ; C + Z = 1 Lecture #10 ECE 3430 – Intro to Microcomputer Systems Fall 2009

Signed vs. Unsigned Branch Instructions BHI = branch if higher than BHS = branch if higher than or the same BLO = branch if lower than BLS = branch if lower than or the same Signed branch instructions: BGE = branch if greater than or equal BGT = branch if greater than BLE = branch if less than or equal BLT = branch if less than BMI = branch if negative flag is set BPL = branch if negative flag is clear Neither: BCC = branch if carry flag is clear BCS = branch if carry flag is set BEQ = branch if equal (zero flag is set) BNE = branch if not equal (zero flag is clear) BRA = branch always (unconditional branch) BRN = branch never (unconditional branch – like the NOP instruction) BVC = branch if overflow flag is clear BVS = branch if overflow flag is set Lecture #10 ECE 3430 – Intro to Microcomputer Systems Fall 2009

ECE 3430 – Intro to Microcomputer Systems Conditional Branches Compare Instructions Branch instructions do not modify CCR bits. They simply read the current state of the CCR bits. At times we want to alter the CCR but not change the contents of the accumulators. By altering the state of the CCR bits, we can control what value the branch condition is relative to --rather than always zero. Compare instructions allow us to do this: CBA = A – B = compare accumulator A to accumulator B CMPA = A - M($??) = compare accumulator A to memory CMPB = B - M($??) = compare accumulator B to memory CPD = D - M($??) = compare accumulator D to memory CPX = X - M($??) = compare index register X to memory CPY = Y - M($??) = compare index register Y to memory TST = M($??) – 0 = test for zero or minus (on memory location) TSTA = A – 0 = test for zero or minus (on ACCA) TSTB = B – 0 = test for zero of minus (on ACCB) Typically, the above compare/test instructions should immediately precede a branch instruction! Lecture #10 ECE 3430 – Intro to Microcomputer Systems Fall 2009

Using Compare Instructions to Influence Branch Instruction Behavior PORTA: EQU $0000 ORG $E000 START: LDAA $40 CMPA #120 BGT SET4 CLR4: LDAB PORTA ANDB #%11101111 BRA REJOIN SET4: LDAB PORTA ORAB #%00010000 REJOIN: STAB PORTA … START A = M($0040) A > 120? YES PA4 = 1 NO PA4 = 0 END Optimization: Move LDAB after LDAA and memory/time can be saved. Lecture #10 ECE 3430 – Intro to Microcomputer Systems Fall 2009

Using Compare Instructions to Influence Branch Instruction Behavior BGT (signed) takes branch if “Z + (N  V) = 0” evaluates as true. BHI (unsigned) takes branch if “C + Z = 0” evaluates as true. Assume M($0040) = 128 S X H I N Z V C LDAA $40 - - - - 1 0 0 0 CMPA #120 - - - - 0 0 1 0 BGT SET4 0 + (0  1) = 0 1 = 0 no branch BHI SET4 0 + 0 = 0 0 = 0 branch 128-120 = negative – positive = positive overflow Lecture #10 ECE 3430 – Intro to Microcomputer Systems Fall 2009

Using Compare Instructions to Influence Branch Instruction Behavior BGT (signed) takes branch if “Z + (N  V) = 0” evaluates as true. BHI (unsigned) takes branch if “C + Z = 0” evaluates as true. Assume M($0040) = 100 S X H I N Z V C LDAA $40 - - - - 0 0 0 0 CMPA #120 - - - - 1 0 0 1 BGT SET4 0 + (1  0) = 0 1 = 0 no branch BHI SET4 1 + 0 = 0 1 = 0 no branch 100-120 = positive – positive = negative Subtracted larger number from smaller (borrow). Result is negative. Negative, no overflow, carry (due to borrow) Lecture #10 ECE 3430 – Intro to Microcomputer Systems Fall 2009