From Andrew Warren
Posted to the PICList
; Enter with multiplier in W-Reg, multiplicand in "PRODLO". ; Exits with product in PRODHI:PRODLO. MPY8X8: CLRF PRODHI CLRF COUNT BSF COUNT,3 RRF PRODLO LOOP: SKPNC ADDWF PRODHI RRF PRODHI RRF PRODLO DECFSZ COUNT GOTO LOOP
This can also be unrolled for an even faster (and not much larger version)
;***************************************************************************
;** time efficient multiplication 8 bit x 8 bit = 16 bit (unsigned)
;**
;** company: elektronik 21 GmbH
;** programmer: Martin Schaefer (idea from Andrew Warren)
;**
;** execution time: fixed 38 cycles (with jump in and jump out) !!!
;** code length: 35 words
;** multiplier: w
;** multiplicand: resultlo
;** result: resulthi:resultlo
;***************************************************************************
MUL8X8 CODE
Mul8x8 ;* 2 cycles for call - instruction
GLOBAL Mul8x8, resulthi, resultlo
mult MACRO
btfsc STATUS,C
addwf resulthi,F
rrf resulthi,F
rrf resultlo,F
ENDM
clrf resulthi ;* 1 cycle
rrf resultlo,F ;* 1 cycle
mult ;* 4 cycles
mult ;* 4 cycles
mult ;* 4 cycles
mult ;* 4 cycles
mult ;* 4 cycles
mult ;* 4 cycles
mult ;* 4 cycles
mult ;* 4 cycles
retlw 0 ;* 2 cycles
;***************************************************************************
See also:
Questions:
write an algorithm in PIC16F874 assembly to 8x8 bit unsigned multiplication . Multiplies M1 & M2 leaving the result in Rhi & Rlo .James Newton replies: "It puts the book on its table and it reads it in..."+
It loops through the addition of M2 to itself M1 times.
| file: /techref/microchip/math/mul/8x8.htm, 2KB, , updated: 2008/4/1 15:15, local time: 2008/11/21 22:56,
38.103.63.59: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://piclist.org/techref/microchip/math/mul/8x8.htm"> PIC Microcontoller Math Method Multiply 8 x 8 bits</A> |
| Did you find what you needed? |
|
o List host: MIT, Site host massmind.org, Top posters @20081121 Apptech, Jinx, Xiaofan Chen, olin piclist, Vitaliy, William \Chops\ Westfield, Tamas Rudnai, Alan B. Pearce, JonnyMac, 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, Timothy Weber, on-going support is MOST appreciated! * Contributors: Richard Seriani, Sr. |
|
.