1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

reverse double-dabble for baseline PIC

Discussion in 'Microcontrollers' started by throbscottle, Feb 21, 2018.

  1. throbscottle

    throbscottle Well-Known Member

    Joined:
    Feb 1, 2012
    Messages:
    1,902
    Likes:
    119
    Location:
    Nuneaton, Warwickshire, UK
    Feeling pleased with myself because I managed to come up with this:
    Posting because of all the frustration I had trying to find out how to do it, all I could find was people say "it can be reversed".
    I'm sure it can be done more efficiently, I'll leave that as an exercise for those more proficient than me!

    Code (text):

    CONVERT_R ; thanks gooligum for the jump table trick!
        clrf key ; recycle key as temporary carry
    ; convert BCD to binary. Do this after displaying what's going to be converted
        movlw 0x20
        movwf counter
        clrf binary
        clrf binary+1
        clrf binary+2
        clrf binary+3
    BCDCONVERT ; convert 8 digit packed BCD to 32 bit binary
        movlw 0x04
        movwf convertcount
        movlw BCD+3
        movwf FSR
        bcf STATUS,C
    ROT_BCD_1
        rrf INDF,f
        rlf key ; key picks up the carry if there is one
        movlw 0x30
        btfsc INDF,7 ; if upper nibble is 8 or greater, take 3 from it
        subwf INDF,f ; subwf destroys the real carry
        movlw 0x03
        btfsc INDF,3 ; if lower nibble is 8 or greater, take 3 from it
        subwf INDF,f
        rrf key ; spit out the temp carrry back to the real one
        decf FSR,f
        decfsz convertcount
        goto ROT_BCD_1
        rrf binary+3, f
        rrf binary+2, f
        rrf binary+1, f
        rrf binary, f
        decfsz counter, f
        goto BCDCONVERT
        retlw 0
     
     
    • Like Like x 1
  2. dknguyen

    dknguyen Well-Known Member

    Joined:
    May 6, 2006
    Messages:
    7,545
    Likes:
    161
    Before I can be impressed, I need to know what "double-dabble" means.
     
  3. throbscottle

    throbscottle Well-Known Member

    Joined:
    Feb 1, 2012
    Messages:
    1,902
    Likes:
    119
    Location:
    Nuneaton, Warwickshire, UK

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice