If you actually need to multiply a two-byte number in the range 0..30000 by the constant 328 you could simply take advantage of the fact that: x * 328 = 256 + 64 + 8 we evaluate this as follows: ans = arg << 3; // arg * 8 ans += arg; // arg * 9 ans <<= 3; // arg * 72 ans += arg << 8; // arg * 328 This is likely to be rather faster than a general 16x16 multiply. The code is directly below. Bob Ammerman RAm Systems CBLOCK 0x?? ans:4 ; 4 byte answer, LSByte first arg:2 ; 2 byte arg, LSByte first ENDC ; ***** WARNING: This code is neither tested nor optimized! ; set ans = arg * 2 by shifting as we copy mul_by_328: clrc rlf arg+0,w movwf ans+0 rlf arg+1,w movwf ans+1 clrf ans+2 rlf ans+2,f clrf ans+3 ; set ans = arg * 8 by shifting left 2 call left_shift call left_shift ; set ans = arg * 9 by adding in arg ; note that no carry can occur out of the third byte movf arg+0,w addwf ans+0 movf arg+1,w skpnc incfsz arg+1,w addwf ans+1,f skpnc incf ans+2,f ; set ans = arg * 72 by shifting left 3 clrc call left_shift call left_shift call left_shift ; set ans = arg * 328 by adding in arg * 256 movf arg+0,w addwf ans+1 movf arg+1,w skpnc incfsz arg+1,w addwf ans+2,f skpnc incf ans+3,f return ; Multiply ans by 2 (assuming carry is clear) left_shift: rlf ans+0,f rlf ans+1,f rlf ans+2,f return ----- Original Message ----- From: "Andrew Warren" To: Sent: Friday, December 21, 2001 11:15 AM Subject: Re: [PIC]: Microchip MATH multiplication routines > Antonio Sergio Sena wrote: > > > I investigated the AN526 application note in the Microchip handbook, > > and used the DBL_MPYS.asm ( 16x16=32) with unsigned multiplication. > > > > The results i got, though, were far from what i was expecting. I am > > multiplying a constant (d'328') by a variable (max: d'30000'), and when > > my variable is > 199, i get strange results... > > > > I dont have any idea what problem the Microchip routines may have. > > > > Hints ? ideas ?? did someone ever use this routines ? > > Antonio: > > When I last looked at them, the Microsoft math routines were just > horrible. Since 199 * 328 is less than 65536 and 200 * 328 is > greater than 65536, I suspect that the routine you're using has > problems propogating the carry from the second byte of the result > to > the third and fourth. > > Many of us have posted math routines to the list; there's a whole > library of them at http://www.piclist.com . > > -Andy > > === Andrew Warren -- aiw@cypress.com > === Principal Design Engineer > === Cypress Semiconductor Corporation > === > === Opinions expressed above do not > === necessarily represent those of > === Cypress Semiconductor Corporation > > -- > http://www.piclist.com#nomail Going offline? Don't AutoReply us! > email listserv@mitvma.mit.edu with SET PICList DIGEST in the body > > -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body