Adding 8 Times a 10bit Number

Status
Not open for further replies.

Suraj143

Active Member
Hi I want to add a 10 bit number 8 times & place them in two bytes.

Ex:345 X 8 = 2760

Does anybody have any math routine for that I searched in piclist but I couldn't find such a one.
 
You can use the RLF instruction.
Code:
;put 345 into Acc
	movlw	low .345
	movwf	AccLo
	movlw	high .345
	movwf	AccHi
;now multiply by 8
	bcf	STATUS,C	;gets shifted into bit 0 of AccLo
	rlf	AccLo,f
	rlf	AccHi,f		;*2
	bcf	STATUS,C
	rlf	AccLo,f	
	rlf	AccHi,f		;*4
	bcf	STATUS,C
	rlf	AccLo,f	
	rlf	AccHi,f		;*8
;AccHi/AccLo now contain 2760.

HTH

Mike.
 
Hi Mike Thanks for your input I'm wondering how can I use this for 16F PICs the maximum value it can hold is 255.

Thanks
 
The code I posted is for 16F Pics. By combining two bytes the maximum value becomes 65535.

Mike.
 
Hi thanks mike !

But i have a small question.

When I multiply 345 X 2 = 690
1010110010 That is correct

But when I double this 690 it will be = 1380
10101100100

Can you tell how this bit0 will be get set in the AccHi register.
 
An RFL instruction moves all bits left one place. The bottom bit gets the value that was in the carry flag and the top bit gets placed in the carry flag.

Can you answer your question now?

Mike.
 
I have attached the number pattern the green cell is my problem how will it be set?
 

Attachments

  • 8 Times.JPG
    23.1 KB · Views: 153
Hi mike after reading lot of times now I got understood. I got what I was expected.

What I’m doing with your routine?

I’m going to sample my AD value 8 times & going to divide by 8 to get the average.

Thank you very much mike
 
I just got a point. The bottom bit gets the carry bit value after the instruction completed I believe.
Ex after the RLF completed the bottom bit will get sets.

Now I understood

thanks again mike.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…