Continue to Site

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.

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

reverse double-dabble for baseline PIC

Status
Not open for further replies.

throbscottle

Well-Known Member
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:
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
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top