• AVR Freaks

Hot!Double Dabble DSC

Author
Gort2015
Klaatu Barada Nikto
  • Total Posts : 3333
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
2019/11/15 17:33:36 (permalink)
1 (1)

Double Dabble DSC

A handy function to produce 10 x BCD Nibbles from a 32bit binary number using the DSC accumulators.
36 instructions in all.
 
I have been busy with a regex compiler +runtime but needed a small function to print 32bit timings.  These chips cannot do division on 32bit numbers.
 
With a 32bit number + 10 x 4bit BCDs, 72bits need to be shifted, accumulators A + B joined
 
To use as a function in C, add a single underscore to doubledabble in the asm code.
 
C prototype:
void doubledabble(unsigned long Number); //Result in B for immediate use
 
I

.include   "xc.inc"
.globl      doubledabble
;----------------------------------------------------
.section    qdoubledabble,code
;----------------------------------------------------
arg_ValueL      = w0
arg_ValueH      = w1
ptr             = w2
x               = w3
y               = w4
zero            = w5
accblow         = w6

doubledabble:
    ;init:  saturation off, align value32 to 39:32
    bclr    CORCON,#SATA
    bclr    CORCON,#SATB
    bset    CORCON,#ACCSAT
    lac.d   arg_ValueL,#-8,A
    clr     B
    clr     zero
    mov     #ACCBL,accblow
    ;- - - - - - - - - - - - - - - -
    ;3 x 72bit left shift
    do      #3-1,1f
    btst    ACCAU,#7
    sftac   A,#-1
    sftac   B,#-1
1:  bsw     [accblow],zero
    nop
    ;- - - - - - - - - - - - - - - -
    ;32bits - 3 already done
    do      #32-3-1,fin
    ;- - - - - - - - - - - - - - - -
    ;dabble 10 nibbles
    mov     #ACCBL,ptr
    do      #5-1,dabble_end
    ;- - - - - - - - - - - - - - - -
    ;low nibble
    mov.b   [ptr],x
    and     x,#0xf,y
    cp      y,#5
    bra     ltu,high
    add     #3,y
    and     #0xf,y
    and     #0xf0,x
    ior     x,y,x
    ;- - - - - - - - - - - - - - - -
high:
    ;high nibble
    lsr     x,#4,y
    and     #0xf,y
    cp      y,#5
    bra     ltu,$+4
    add     #0x30,x
    ;- - - - - - - - - - - - - - - -
 dabble_end:
    mov.b   x,[ptr++]
    ;- - - - - - - - - - - - - - - -
    ;72bit shift left
    btst    ACCAU,#7
    sftac   A,#-1
    sftac   B,#-1
fin:bsw     [accblow],zero
    nop
    return
;----------------------------------------------------
.end

If the number is signed negative make the number positive.
     
;make value pos if signed
    btsc    arg_Flag,#QFMT_UNSIGNED
    bra     signend
    btss    arg_ValueH,#15
    bra     signend
    subr    arg_ValueL,#0,arg_ValueL
    subbr   arg_ValueH,#0,arg_ValueH
    ;- - - - - - - - - - - - - - - -

post edited by Gort2015 - 2019/11/15 18:50:47

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#1

2 Replies Related Threads

    MBedder
    Circuit breaker
    • Total Posts : 6804
    • Reward points : 0
    • Joined: 2008/05/30 11:24:01
    • Location: Zelenograd, Russia
    • Status: offline
    Re: Double Dabble DSC 2019/11/16 01:56:45 (permalink)
    0
    How many instruction cycles does this take?
    #2
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 3333
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: Double Dabble DSC 2019/11/16 09:31:13 (permalink)
    0
    It's quite fast, 20 instructions per 29 iterations.
    It's effective for large 32bit numbers.
     
    It will always produce 10 bcd digits
    0000000042
     
    qvalue32(4294967295UL,QFMT_GROUP,0);
    -1
    qvalue32(-1,QFMT_GROUP|QFMT_POLSIGN|QFMT_UNSIGNED,0);
    +4,294,967,295
     
     
     
     
     
     
     

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #3
    Jump to:
    © 2019 APG vNext Commercial Version 4.5