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.

multiply operation in PIC problem

Status
Not open for further replies.

manba

New Member
hi,

i wanna to multiply tow numbers and store the result in a GPR register, but i face problem if the result is bigger than FFh how to solve this problem.:confused:

Code:
this code is ok if the result > 256

; i have a test if the FIRST_NUM = 0
MULTI:
MOVF      RESULT,W
ADDWF    SECOND_NUM,F
DECFSZ   FIRST_NUM
GOTO      MULTI
RETURN
 
Last edited:
When you multi two number (< 256) you need two location to store result one for lower 256 and one for higher than 256
ex:
you have SECOND_NUM to store lower, and over256 to store higher
100*100=10000 =hex 2710 then
SECOND_NUM=0x10 (16 dec)
over256=0x27 (39 dec)
Code:
	clrf	over256
MULTI:
MOVF      RESULT,W
ADDWF    SECOND_NUM,F

	btfsc	STATUS,C ;is > 256 (carry bit set)
	incf	over256    ; so add 1

DECFSZ   FIRST_NUM
GOTO      MULTI
RETURN
 
Status
Not open for further replies.

Latest threads

Back
Top