Branching and Looping

1 / 17

# Branching and Looping - PowerPoint PPT Presentation

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.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

## PowerPoint Slideshow about 'Branching and Looping' - marcell-connor

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

Lecture L3.2

Branching and Looping
• 68HC12 Branch Instructions
• Hex-to-ASCII Subroutine
• Delay Loops
Branching and Looping
• 68HC12 Branch Instructions
• Hex-to-ASCII Subroutine
• Delay Loops

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

9: 0008 3D rts;else

11: 000B 3D rts

0009 = 0006 + 03

Branching and Looping
• 68HC12 Branch Instructions
• Hex-to-ASCII Subroutine
• Delay Loops

; 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

000A

+FFF7

10001

; Delay test

outa equ \$FF4F

ORG \$800

#include hexasc.asm

#include ms_delay.asm

sec_delay

ldy #1000 ; 1000 ms delay

jsr ms_delay

rts

main

ldab #10 ; B = 10

mn1 tba ; A = B

jsr hexasc ; get ASCII value

jsr outa ; output to screen

bsr sec_delay ; delay 1 second

decb

bne mn1 ; do 10 times

swi

Monitor routine to output

ASCII character in A