Branching and looping
This presentation is the property of its rightful owner.
Sponsored Links
1 / 17

Branching and Looping PowerPoint PPT Presentation


  • 70 Views
  • Uploaded on
  • Presentation posted in: General

Branching and Looping. Lecture L3.2. Branching and Looping. 68HC12 Branch Instructions Hex-to-ASCII Subroutine Delay Loops. Branch Displacement. Negative Branch. How many times is the instruction INCB executed?. Bit-Condition Branch Instruction. Branching and Looping.

Download Presentation

Branching and Looping

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Branching and looping

Branching and Looping

Lecture L3.2


Branching and looping1

Branching and Looping

  • 68HC12 Branch Instructions

  • Hex-to-ASCII Subroutine

  • Delay Loops


Branch displacement

Branch Displacement


Negative branch

Negative Branch


How many times is the instruction incb executed

How many times is the instruction INCB executed?


Bit condition branch instruction

Bit-Condition Branch Instruction


Branching and looping2

Branching and Looping

  • 68HC12 Branch Instructions

  • Hex-to-ASCII Subroutine

  • Delay Loops


Branching and looping

Branching Example

1: ; Hex to ascii subroutine

2: ; input: A = hex value

3: ; output: A = ascii value of lower nibble of input

4: 0000 hexasc

5: 0000 84 0F anda #$0f ;mask upper nibble

6: 0002 81 09 cmpa #$9 ;if A > 9

7: 0004 23 03 bls ha1

8: 0006 8B 37 adda #$37 ; add $37

9: 0008 3D rts;else

10: 0009 8B 30 ha1 adda #$30 ; add $30

11: 000B 3D rts

Note: destination address = addr. of next instr. + displ.

0009 = 0006 + 03


Branching and looping3

Branching and Looping

  • 68HC12 Branch Instructions

  • Hex-to-ASCII Subroutine

  • Delay Loops


Branching and looping

; ms_delay

; input: Y = no. of milliseconds to delay

0000 ms_delay

0000 34 pshx

0001 CE 07CF md1 ldx #1999 ; N = (8000 - 5)/4

0004 09 md2 dex ; 1 ccycle

0005 26 FD bne md2 ; 3 ccycle

0007 03 dey

0008 26 F7 bne md1 ; Y ms

000A 30 pulx

000B 3D rts

Note: addr. of next instr. + displ. = destination address

000A

+FFF7

10001


Branching and looping

;Delay test

outaequ$FF4F

ORG$800

#includehexasc.asm

#includems_delay.asm

sec_delay

ldy#1000; 1000 ms delay

jsrms_delay

rts

main

ldab#10; B = 10

mn1tba; A = B

jsrhexasc; get ASCII value

jsrouta; output to screen

bsrsec_delay; delay 1 second

decb

bnemn1; do 10 times

swi

Monitor routine to output

ASCII character in A


  • Login