Searching \ for 'A Multiply Routine' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/method/math.htm?key=multiply
Search entire site for: 'A Multiply Routine'.

Truncated match.
PICList Thread
'A Multiply Routine'
1994\12\05@083956 by crocontroller discussion list

flavicon
face
Dear pic guru's:

I've been struggling with this multiply routine, and I think that I've got
it working now.  It should take an unsigned 24 bit integer value and
multiply it by an unsigned 24 bit floating point value with the result
being a 24 bit integer.  I still think that I need to limit the number of
right shifts that it performs in the end, but I haven't thought of any
clever ways to do this yet.

This is kind of a specialize multiply, but I thought that I would post it
to see if anyone can find some mistakes or make use of it.

Please inform me of any errors!

Oh yeah, It also makes use of a 24 bit integer addition routine.  Any
critiques will be greatly appreciated.

Take care,

Derrick Early (still a rookie)

================================================================================
===
F_mpy

; 24 bit integer * 24 bit floating point = 24 bit integer

; a*b*2^b3 -> d

; Where a is made up of a1 a2 and a3.  b is (b1 b2) * 2^b3.
; And, d is d1 d2 d3.  If d overflows to the left, then the
; _overflow bit will be set.

       clrf    d1
       clrf    d2
       clrf    d3
       bcf     _overflow
       movlw   d'16'
       movwf   temp
do_temp_gt_0
       btfsc   b1,7
       call    add_a_to_d
       btfsc   _overflow
       goto    done_F_mpy
       bcf     _carry
       rlf     b2
       rlf     b1
       incf    b3,f
       bcf     _carry
       rrf     a1
       rrf     a2
       rrf     a3
while_temp_gt_0
       decfsz  temp            ; while (temp>0)
       goto    do_temp_gt_0
end_temp_gt_0
       decf    b3,f

; Shift the result in d to an integer value.

       btfss   b3,7
       goto    shift_left
shift_right
       btfsc   _z
       goto    done_F_mpy
       bcf     _carry
       rrf     d1
       rrf     d2
       rrf     d3
       incf    b3,f
       goto    shift_right
shift_left
       btfsc   _z
       goto    done_F_mpy
       bcf     _carry
       rlf     d3
       rlf     d2
       rlf     d1
       decf    b3,f
       btfss   _carry
       goto    shift_left
       bsf     _overflow
done_F_mpy
       return

add_a_to_d

; a+d -> d  this is a 24 bit addition routine

       bcf     _overflow
       movf    a3,w
       addwf   d3,f
       btfss   _carry
       goto    add_byte_2
       incfsz  d2,same
       goto    add_byte_2
       incfsz  d1,same
       goto    add_byte_2
       bsf     _overflow
add_byte_2
       movf    a2,w
       addwf   d2,f
       btfss   _carry
       goto    add_byte_1
       incfsz  d1,same
       goto    add_byte_1
       bsf     _overflow
add_byte_1
       movf    a1,w
       addwf   d1,f
       btfsc   _carry
       bsf     _overflow
       return

More... (looser matching)
- Last day of these posts
- In 1994 , 1995 only
- Today
- New search...