1 / 18

Microcontroller Fundamentals & Programming

Microcontroller Fundamentals & Programming. Branch & Jump Instructions. Branch Instructions. Branch Instructions: allowed execution of a program to continue at another memory location by modifying the program counter value. 2 types of branch instructions :

thuong
Download Presentation

Microcontroller Fundamentals & Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Microcontroller Fundamentals & Programming Branch & Jump Instructions

  2. Branch Instructions • Branch Instructions: • allowed execution of a program to continue at another memory location by modifying the program counter value. • 2 types of branch instructions : • Unconditional branch and • Conditional branch.

  3. Unconditional Branch Instruction BRA (branch always). • There is only one Unconditional Branch instruction. • Flag bits in CCR will not be tested for a branch to take place. • The branch “distance” uses relative addressing. It ranges +12710 to -12810. • Sometimes the branch “distance” also known as “offset” .

  4. Example: BRAnch Instruction MnemonicsExplanations BACKWARD: BRA FORWARD ; Branch to location LDAA #$10 ; FORWARD. - - - - ; FORWARD: LDAB #$39 ; BRA BACKWARD ; Branch to location ; BACKWARD

  5. Conditional Branch Instructions • The Conditional Branch instructions allow CPU to make decision. • Flag bits in CCR are tested to decide whether a branch to take place. • The branch “distance” uses relative addressing. • It ranges from +12710 to -12810 .

  6. Conditionalbranch instructions

  7. Conditionalbranch instructions

  8. START INIT IX; AccB CLR Memory BNE (No) AccB = 0? END Branch Not Equal (BNE) Instruction Example: To clear a block of memory from location ($00) to ($10) START LDX #$0010 ;Initialise LDAB #$11 ; IX , AccB CLRA REPEAT STAA $00,X ; Clr Mem DEX DECB BNE REPEAT WAI • IX is initialised as a POINTER and AccB is initialised as a COUNTER . • Memory location ($00,X) down to ($00) will be cleared.

  9. Branch Carry Clear & Set (BCC & BCS) Instructions: • BCC => branch if Carry bit clear (C = “0”) • BCS => branch if Carry bit set (C = “1”) (Carry bit in CCR will be tested to determine whether a branch will to take effect).

  10. Branch Carry Clear & Set (BCC & BCS) Example: BCC instruction START LDAA $0100 ; copy the content of memory STAA $50 ; $0100 into memory $50 - - - - - - - - - - ADDA #$20 BCC START ; after executing ADDA, ; if C = “0” branch to START STAA $80 ; else executes STAA $80. - - - - - - - - - -

  11. Branch Equal & Not Equal (BEQ & BNE) Instructions: • BEQ branch if Zero bit set (Z = “1”) • BNE branch if Zero bit clear (Z = “0”) (Zero bit in CCR will be tested to determine whether a branch will to take effect). • BEQ = Branch if equal to zero • BNE = Branch if not equal to zero

  12. Branch Equal & Not Equal (BEQ & BNE) Example: To clear memory location ($50 to $60) using BNEinstruction. LDX #$0010 ; initialise X as counter. LDAA #$00 ; ACCA = $00 REPEAT STAA $50,X ;clear memory $50 to $60 DEX BNE REPEAT ; if register X is not zero - - - - - ; then branch to REPEAT. BEGIN LDAA $80 - - - - -

  13. Branch Minus & Plus (BMI & BPL) Instructions: • BMI branch if Negative bit set (N = “1”) • BPL branch if Negative bit clear (N = “0”) (Negative bit in the CCR will be tested to determine whether a branch will to take effect). • BMI = Branch if (result) minus • BPL = Branch if (result) plus

  14. Example: Branch Plus (BPL) Add contents in memory ($0150) and ($0151). Store +ve result in memory ($0180) using BPL instruction. LDAA $0150 ; place contents ($0150) to ACCA ADDA $0151 ;ACCA = contents ($0150)+($0151) BPL SUM ; branch to SUM if ACCA bit-7 = “0”. LDAB #$10 - - - - - - SUM STAA $0180 (An 8-bit signed number is said to be positive if the most significant bit, MSB, is a “0” and negative if MSB is a “1”).

  15. Rest of conditional branch instructions

  16. Jump Instruction • Only one jump instruction :JMP • Flag bits in CCR will not be tested for a jump to take place. • The difference between using a jump and a branch: • Jump can go to any 64K of memory location and start executing from there; whereas • Branch can go relative +12710 to -12810 of memory location.

  17. Jump Instruction Example: Jump instruction

  18. Thank You

More Related