piclist 2001\01\19\174655a >
Thread: Maths Problem
face BY : Don Hyde email (remove spam text)

Multiplying by 10 in binary can be quite fast and simple:

10 = 8+2 = 2^3 + 2

Multiplication by a power of two can be accomplished by shifting, so in C

result = input*10;

can be written

result = input<<3 + input<<1;

or, more efficiently on some machines (such as PIC's):

result = ((input<<2)+input)<<1;

For 16 bits in assembler:

       cblock  0x20
       input:2 ;little-endian, i.e. least significant byte first

       movfw   input                   ;result = input
       movwf   result
       movfw   input+1
       movwf   result+2

       clrc                            ;result = result<<2
       rlf     result,f
       rlf     result+1,f
       rlf     result,f
       rlf     result+1,f

       movfw   input                   ;result += input
       addwf   result,f
       incf    result+1,f              ;carry
       movfw   input+1
       addwf   result+1,f

       clrc                            ;result <<=1;
       rlf     result,f
       rlf     result+1,f

> {Original Message removed}
<117EC968C6D8D211A9520020AF155EB23A8B72@ISERVER> quoted-printable

See also: www.piclist.com/techref/microchip/math/index.htm?key=math
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) Maths Problem

month overview.

new search...