170 likes | 316 Views
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.
E N D
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 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 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 Note: addr. of next instr. + displ. = destination address 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