Everyone After my recent posting of a working 32x8 bit multiplication algorithm, = I decided to modify it "slightly" to handle 64x8 bit multiplication. It = will multiply a 64 bit number by a 8 bit number, and return a 64 bit = number, but throwing away the carry value. Values of up to 56 bits can = be multiplied, providing the full result, but more than 56 bits might = cause a "overflow" where any bits higher than 64 is not = calculated/returned. The variables take 22 bytes of RAM. Please note = that even though the 64 bit variables are named XXXLo:4 and XXXHi:4, = they are referenced by the Lo variable, in the form of XXXLo+0 to = XXXLo+7. They were split in two to assist "watching" them in MPLab to = ensure that everything was working. The variable definitions are as follow: cblock 0x30 Mult64Lo:4 Mult64Hi:4 Prod64Lo:4 Prod64Hi:4 Multiplier MultiCount endc The routine is as follow: Multiply64x8 ; Clear Product clrf Prod64Lo clrf Prod64Lo+1 clrf Prod64Lo+2 clrf Prod64Lo+3 clrf Prod64Lo+4 clrf Prod64Lo+5 clrf Prod64Lo+6 clrf Prod64Lo+7 ; Test for an 0 multiplier movf Multiplier, W btfsc STATUS, Z return ; Setup the counter for 8 bits movlw 0x08 movwf MultiCount MultiplyLoop64 bcf STATUS, C rlf Multiplier, F btfss STATUS, C goto ShiftLoop64 movf Mult64Lo+0, W addwf Prod64Lo+0, F btfsc STATUS, C call Carry64Byte1 movf Mult64Lo+1, W addwf Prod64Lo+1, F btfsc STATUS, C call Carry64Byte2 movf Mult64Lo+2, W addwf Prod64Lo+2, F btfsc STATUS, C call Carry64Byte3 movf Mult64Lo+3, W addwf Prod64Lo+3, F btfsc STATUS, C call Carry64Byte4 movf Mult64Lo+4, W addwf Prod64Lo+4, F btfsc STATUS, C call Carry64Byte5 movf Mult64Lo+5, W addwf Prod64Lo+5, F btfsc STATUS, C call Carry64Byte6 movf Mult64Lo+6, W addwf Prod64Lo+6, F btfsc STATUS, C call Carry64Byte7 movf Mult64Lo+7, W addwf Prod64Lo+7, F ShiftLoop64 decfsz MultiCount, F goto $+2 return bcf STATUS, C rlf Prod64Lo+0, F=20 rlf Prod64Lo+1, F=20 rlf Prod64Lo+2, F=20 rlf Prod64Lo+3, F=20 rlf Prod64Lo+4, F=20 rlf Prod64Lo+5, F=20 rlf Prod64Lo+6, F=20 rlf Prod64Lo+7, F=20 goto MultiplyLoop64 Carry64Byte1 incfsz Prod64Lo+1, F return Carry64Byte2 incfsz Prod64Lo+2, F return Carry64Byte3 incfsz Prod64Lo+3, F return Carry64Byte4 incfsz Prod64Lo+4, F return Carry64Byte5 incfsz Prod64Lo+5, F return Carry64Byte6 incfsz Prod64Lo+6, F return Carry64Byte7 incf Prod64Lo+7, F return One of the tests I performed used this code: movlw 0x27 movwf Mult64Lo+0 movlw 0xBC movwf Mult64Lo+1 movlw 0xA9 movwf Mult64Lo+2 movlw 0x2F movwf Mult64Lo+3 movlw 0xFA movwf Mult64Lo+4 movlw 0x01 movwf Mult64Lo+5 movlw 0x00 movwf Mult64Lo+6 movlw 0xDB movwf Mult64Lo+7 movlw 0xA2 movwf Multiplier=20 call Multiply64x8 This does a calculation of 0xDB0001FA2FA9BC27 x 0xA2, resulting in = 0x96014052296910AE. Note that the bits higher than 64 is lost. This = calculation took 268 instruction cycles. A full blown 0xFFFFFFFFFFFFFFFF = x 0xFF takes 501 instruction cycles (0.1 ms at 20Mhz) to provide the = answer of 0xFFFFFFFFFFFFFF01. I'm also considering to write 32x16 with a 48 bit result, and 32x32 with = a 64 bit result, but I'll leave that for another day. I hope someone can use this code. Cheers Werner -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu