Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

arrethmatic operations by pic

Status
Not open for further replies.

besho741

New Member
hi all
i want to multiply two numbers by pic
nigel told me that
To multiple by two (or powers of 2) you can simply shift the required number of times (you can divide by powers of 2 in the same way). Anything else, you need to use loops.
are sure nigel of that because i allready develope away to perform that with shift only loops depend on number of bits in word
to do this



CCCC=A2A1*B2B1
CCCC=0
B2B1=B4B3B2B1 WHERE B4B3=00
N=16 BIT(ANY)
RRF A2<<<<<<<<<<<<<<<LOOP2
RRF A1
BTFSC STATUS,C
GOTO >>>>>>>>>>>>>>>>LOOP1
CCCC=CCCC+B4B3B2B1
BCF STATUS,C
RLF B1<<<<<<<<<<<<<<<<LOOP1
RLF B2
RLF B3
RLF B4
DECFSZ N
GOTO>>>>>>>>>>>>>>>>>LOOP2
END SUB


EXAMPLE
Let AA=1001Dec=9
Let BB=1101Dec=13
N=4 BIT
A*B=9*13=117
IF I USED ADD AA to it self BB times then we need 13 loop its big problem
by using this sub
RRF AA
STATS C(SC)=1
CCCCC=CCCCC+BBBB00001101
LET SC =0
RLF BBBBB= 00011010
N=3
RRF AA
STATS C(SC)=0
RLF BBBBB 00110100
N=2
RRF AA
STATS C(SC)=0
RLF BBBBB 01101000
N=1
RRF AA
STATS C(SC)=1
CCCCC=CCCCC+BBBB01110101
LET SC =0
RLF BBBBB= 11010000
N=0
END
RESULT =CCCC=01110101=1+4+16+32+64=117 RIGHT
TRY TO TEST WITH MORE BITS ITIS REALY FINE
 
hi nigel
to make program from zero(using assemply) is more better to be understand it may take time at first but after it will be easy
at any way do have free software to write program pls.insert link for piclist

pls try to test dely program and tell me if itis ok or not
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top