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,F LOOP: SKPNC ADDWF PRODHI,F RRF PRODHI,F RRF PRODLO,F 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:
i dont get the BSF count,3 line.James Newton of MassMind replies: Bit number 3 is the 4th bit in COUNT. Think of it this way, BSF COUNT,0 would set the 1st bit. Setting the first bit, makes COUNT 8.+
i am seeing...
clear result file and count file.
set count bit(s) for desired number of loops.
enter loop, decrement count file 1 bit, skip if clear.
add result to original, shift one place left.
repeat.
setting bit 3 only gives me five loops dont it? 0100= 4. shouldnt it be 000-0111, aka bits 3,2,1, for 8 loops in total? or bit 4? im also confused if i count 0 as a cycle or not :)
or am i not seeing something/not understanding something here?
i must be, noone else is saying anything!
The destination (where the values are stored) are missing in Andrew Warren's multiplication script, MPLAB told me during the compilation that it will use the default destinations. Is this correct or can anybody tell me the correct destinations (f or w) for all the script lines where a destination should be inserted to specify where the calculation output should be saved?James Newton of Massmind replies: As the documentation says, the output is save in PRODHI:PRODLO. You decide what those labels point to by assigning the labels values in your code.+
Thanks for your help
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.
Comments:
Hello again!+
The code works with the destination "f", I also did some tests, it seems the default destination is everytime the register itself, the W register is never changed by instructions with missing destination.
So we can say (for example): "RRF registername,1" is eqal to "RRF registername" and also "RRF registername,f", the only thing is that some compilers/linkers don't like the shorter instruction code and produce an information message.
Thanks again for your help.
Hello James!James Newton of Massmind replies: Ah, ok... based on the fact that the macro example uses ",f" as the destination, I assume the original code should also use that as the destination. I've edited the page to make that correction. I'm not sure what MPLAB uses as the default destination, but if it is the file register and not W, then the code would work fine as originally written.+
Thanks for the reply, I know about the fact where the result of the multiplication will be stored.
Sorry that my question was not well formulated, so I try again. Some instuctions for the PIC microprocessor like ADDWF need a destination, normally the W register or the register where the value comes from. So the full syntax of this command would be ADDWF PRODHI,0 when the result of the calculation should be stored in the W register or ADDWF PRODHI,1 if the result should overwrite the old value stored in the PRODHI register. That's what my question is about, this destination is missing in the code example from Andrew Warren and my compiler (MPLAB/MPLINK) told me that the default destination was used, maybe this is wrong and so the calcualtion wouldn't work.
file: /Techref/microchip/math/mul/8x8.htm, 7KB, , updated: 2019/3/4 12:50, local time: 2024/8/31 17:38,
3.144.243.168:LOG IN
|
©2024 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? <A HREF="http://www.piclist.com/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 @none found - 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: Gregg Rew. on-going support is MOST appreciated! * Contributors: Richard Seriani, Sr. |
Welcome to www.piclist.com! |
.