See also:
Archive:
; 4x4 bit multiply
; result in W
; by John Payson
movlw 0
bcf C
btfss n1,0
addwf n2,w
rlf n2,f
btfss n1,1
addwf n2,w
rlf n2,f
btfss n1,2
addwf n2,w
rlf n2,f
btfss n1,3
addwf n2,w
rlf n2,f
swapf n2,f
; 15 cycles, putting the result in W and
; leaving n1 and n2 untouched at the end.
; Striking the requirement that n2 be untouched would save the
; last two cycles.
; Note that if n1<=15 and n1*n2<=255 this routine will ; produce a correct result even if n2>15;
; the value in n2 will be trashed in such a case, though.
; 4x4 bit multiply
; by John Payson
; result in n2...
swapf n1,w ; Assume top 4 bits zero
btfss n2,0
addwf n2,f
rrf n2,f
If we have Cy=1 before entering this code fragment and we skip first addition we'll got error.
btfss n2,0
addwf n2,f
rrf n2,f
btfss n2,0
addwf n2,f
rrf n2,f
btfss n2,0
addwf n2,f
rrf n2,f
; 13 cycles, leaving the result in n2.
; This one won't work if either factor is oversized.
; 4x4 bit multiply
; by Ray Gardiner
; X*Y ; result left in W
; X and Y are 4 bits
;
;
CLRW ; Clear Result
CLRC ; Clear Carry for RLF later ;
BTFSC Y,0 ; ?*1
ADDWF X,W ; W = ?X
RLF X,F ; X = 2X
;
BTFSC Y,1 ; ?*2
ADDWF X,W ; W = ?X + ?2X
RLF X,F ; W = 4X
BTFSC Y,2 ; ?*4
ADDWF X,W ; W = ?X + ?2X + ?4X
RLF X,F ; W = 8X
BTFSC Y,3 ; ?*8
ADDWF X,W ; ?X + ?2X + ?4X + ?8X
;;;;;;;;;;;;;;;;;;;;;;;;;
13 cycles result in W 13 bytes of code space
Looking back, I now realise that is what John Payson has already
posted. Albeit in a different form. Sigh(!)
; 4 X 4 multiplication
; by Dmitry Kiryashov
movfw x ;0000abcd
addwf x,F
btfss y,0 ;0000efgh
movlw 0
btfsc y,1
addwf x,W
rlf x,F
btfsc y,2
addwf x,W
rlf x,F
btfsc y,3
addwf x,W ;result in W
; 12 clocks/words
See:
32-bit signed integer math routines. add, subtract, multiply, divide, round, sqrt, bin2dec, dec2bin. By Peter Hemsley. +
| file: /techref/microchip/math/mul/index.htm, 7KB, , updated: 2008/4/14 09:26, local time: 2008/7/5 06:23,
38.103.63.16:LOG IN
|
| ©2008 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? Please DO link to this page! Digg it! <A HREF="http://www.piclist.com/techref/microchip/math/mul/index.htm"> PIC Microcontoller Basic Math Multiplication Methods</A> |
| Did you find what you needed? |
|
o List host: MIT, Site host massmind.org, Top posters @20080705 Apptech, Jinx, Xiaofan Chen, Alan B. Pearce, David VanHorn, Bob Axtell, William \Chops\ Westfield, Cedric Chang, olin piclist, Gerhard Fiedler, * Page Editors: James Newton, David Cary, and YOU! * Roman Black of Black Robotics donates from sales of Linistep stepper controller kits. * Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters. * Monthly Subscribers: Shultz Electronics, Larry Williams, David VanHorn, Bryan Whitehouse, Timothy Weber, David Challis. Peter Todd. on-going support is MOST appreciated! * Contributors: Neil Narwani, David Cary, Elemer AM Nyiry, Philip J Taylor, Gus Calabrese of Omegadogs.com, Gautama Venegas, Patrick B. Murphy, William Chops Westfield, Peter Todd, Leslie Ellis |
|
.