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.

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.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…