1 / 17

Branching and Looping

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. 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. Branching and Looping Lecture L3.2

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

  3. Branch Displacement

  4. Negative Branch

  5. How many times is the instruction INCB executed?

  6. Bit-Condition Branch Instruction

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

  8. 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

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

  10. ; 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

  11. ; 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

More Related