Thanks Scott, I think I only need to shift a max of 4 times, with the multiplier being only 4 bits, I need to do this longhand on paper to get my head round it! Thanks for the help:-) mike. scott@DATTALO.COM on 09/01/2002 23:56:58 Please respond to PICLIST@MITVMA.MIT.EDU@INTERNET@wtgw To: PICLIST@MITVMA.MIT.EDU@INTERNET@wtgw cc: Paper Mail: Subject: Re: [PIC]: 12x4 multiply needed. (16f8XX) *** WARNING *** This mail has originated outside your organization, either from an external partner or the Global Internet. Keep this in mind if you answer this message. On Tue, 8 Jan 2002, Mike Blakey wrote: > I am looking for a *smart* 12bit by 4bit unsigned multiply. I have seen several > methods, some of which I can follow and some that I don't yet fully understand as > they are un commented I would prefer the execution time to be the same length for > all number combinations (including zero x zero). any help in understanding this > would be most appreciated. A simple unrolled multiplication is probably what you want: ;multiply x(12bits) times y (bits) clrf resH ; result goes here ; clrf resL ; Don't need to clear resL movf xL,w ; First multiply lower 8 bits btfsc y,0 addwf resH,F clrc ;in case we didn't add rrf resH,F rrf resH,F btfsc y,1 addwf resH,F rrf resH,F rrf resL,F btfsc y,2 addwf resH,F rrf resH,F rrf resL,F btfsc y,3 addwf resH,F rrf resH,F rrf resL,F ; Now for the high nibble swapf xH,w ;Shift xH "right" 4 bits to match andlw 0xf0 ;the four shifts above. btfsc y,0 addwf resH clrc ;in case we didn't add rrf resH,F rrf resL,F btfsc y,1 addwf resH,F rrf resH,F rrf resL,F btfsc y,2 addwf resH,F rrf resH,F rrf resL,F btfsc y,3 addwf resH,F rrf resH,F rrf resL,F This, of course, is untested. The only way I can think of explaining it is by saying that it's just a clasic shift-and-add multiply routine that takes advantage of the weird bit sizes of the operands. Scott -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details. ******************************************************************** This email and any attachments are confidential to the intended recipient and may also be privileged. If you are not the intended recipient please delete it from your system and notify the sender. You should not copy it or use it for any purpose nor disclose or distribute its contents to any other person. ******************************************************************** -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body