CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

ASM routine for multiplication

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
acid
Guest







ASM routine for multiplication
PostPosted: Mon May 26, 2003 8:24 am     Reply with quote

Hello
I have downloaded this routine from www.piclist.com
<a href="http://www.piclist.com/cgi-bin/constdivmul.exe" TARGET="_blank">http://www.piclist.com/cgi-bin/constdivmul.exe</a>
it multiplies 1.333 * int

; Round = no

; ALGORITHM:
; Clear accumulator
; Add input * 1 to accumulator
; Add input / 4 to accumulator
; Add input / 16 to accumulator
; Add input / 64 to accumulator
; Move accumulator to result
;
; Approximated constant: 1.32813, Error: 0.365716 \%

; Input: ACC0, 8 bits
; Output: ACC0 .. ACC1, 9 bits
; Code size: 16 instructions

; cblock
; ACC0
; ACC1
; endc

;copy accumulator to temporary
movf ACC0, w


;shift accumulator right 2 times
clrc
rrf ACC0, f
clrc
rrf ACC0, f

;add temporary to accumulator
addwf ACC0, f

;shift accumulator right 2 times
rrf ACC0, f
clrc
rrf ACC0, f

;add temporary to accumulator
addwf ACC0, f

;shift accumulator right 2 times
rrf ACC0, f
clrc
rrf ACC0, f

;add temporary to accumulator
addwf ACC0, f
clrf ACC1
rlf ACC1, f

But I have problems. CCS not compile the code it return an error for clrc and cblock instruction
Can you help me ?
THANK!!
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514761
Tomi
Guest







Re: ASM routine for multiplication
PostPosted: Mon May 26, 2003 8:59 am     Reply with quote

clrc = Clear Carry
You can do this (16F877):
#define clrc bcf 0x03,0 in assembler
or
bit_clear(*0x03,0) in C

If you have another PIC (e.g. any 18F ) then check the address of the STATUS register.

You don't need cblock instruction. It reserves space for internal accumulators. Instead of this, declare ACC0 and ACC1 at the normal C part (e.g. char ACC0,ACC1; ). Then you can use these variables by names in assy parts.

:=Hello
:=I have downloaded this routine from www.piclist.com
:= <a href="http://www.piclist.com/cgi-bin/constdivmul.exe" TARGET="_blank"> <a href="http://www.piclist.com/cgi-bin/constdivmul.exe" TARGET="_blank">http://www.piclist.com/cgi-bin/constdivmul.exe</a></a>
:=it multiplies 1.333 * int
:=
:=; Round = no
:=
:=; ALGORITHM:
:=; Clear accumulator
:=; Add input * 1 to accumulator
:=; Add input / 4 to accumulator
:=; Add input / 16 to accumulator
:=; Add input / 64 to accumulator
:=; Move accumulator to result
:=;
:=; Approximated constant: 1.32813, Error: 0.365716 \%
:=
:=; Input: ACC0, 8 bits
:=; Output: ACC0 .. ACC1, 9 bits
:=; Code size: 16 instructions
:=
:=; cblock
:=; ACC0
:=; ACC1
:=; endc
:=
:=;copy accumulator to temporary
:= movf ACC0, w
:=
:=
:=;shift accumulator right 2 times
:= clrc
:= rrf ACC0, f
:= clrc
:= rrf ACC0, f
:=
:=;add temporary to accumulator
:= addwf ACC0, f
:=
:=;shift accumulator right 2 times
:= rrf ACC0, f
:= clrc
:= rrf ACC0, f
:=
:=;add temporary to accumulator
:= addwf ACC0, f
:=
:=;shift accumulator right 2 times
:= rrf ACC0, f
:= clrc
:= rrf ACC0, f
:=
:=;add temporary to accumulator
:= addwf ACC0, f
:= clrf ACC1
:= rlf ACC1, f
:=
:=But I have problems..Css not compile the code it return un error for clrc and cblock istruction
:=Can you help me ?
:=THANK!!
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514764
acid
Guest







Re: ASM routine for multiplication
PostPosted: Tue May 27, 2003 6:20 am     Reply with quote

ok!
It save 57 word in the my program!
THANKS

:=clrc = Clear Carry
:=You can do this (16F877):
:=#define clrc bcf 0x03,0 in assembler
:=or
:=bit_clear(*0x03,0) in C
:=
:=If you have another PIC (e.g. any 18F ) then check the address of the STATUS register.
:=
:=You don't need cblock instruction. It reserves space for internal accumulators. Instead of this, declare ACC0 and ACC1 at the normal C part (e.g. char ACC0,ACC1; ). Then you can use these variables by names in assy parts.
:=
:=:=Hello
:=:=I have downloaded this routine from www.piclist.com
:=:= <a href="http://www.piclist.com/cgi-bin/constdivmul.exe" TARGET="_blank"> <a href="http://www.piclist.com/cgi-bin/constdivmul.exe" TARGET="_blank"> <a href="http://www.piclist.com/cgi-bin/constdivmul.exe" TARGET="_blank">http://www.piclist.com/cgi-bin/constdivmul.exe</a></a></a>
:=:=it multiplies 1.333 * int
:=:=
:=:=; Round = no
:=:=
:=:=; ALGORITHM:
:=:=; Clear accumulator
:=:=; Add input * 1 to accumulator
:=:=; Add input / 4 to accumulator
:=:=; Add input / 16 to accumulator
:=:=; Add input / 64 to accumulator
:=:=; Move accumulator to result
:=:=;
:=:=; Approximated constant: 1.32813, Error: 0.365716 \%
:=:=
:=:=; Input: ACC0, 8 bits
:=:=; Output: ACC0 .. ACC1, 9 bits
:=:=; Code size: 16 instructions
:=:=
:=:=; cblock
:=:=; ACC0
:=:=; ACC1
:=:=; endc
:=:=
:=:=;copy accumulator to temporary
:=:= movf ACC0, w
:=:=
:=:=
:=:=;shift accumulator right 2 times
:=:= clrc
:=:= rrf ACC0, f
:=:= clrc
:=:= rrf ACC0, f
:=:=
:=:=;add temporary to accumulator
:=:= addwf ACC0, f
:=:=
:=:=;shift accumulator right 2 times
:=:= rrf ACC0, f
:=:= clrc
:=:= rrf ACC0, f
:=:=
:=:=;add temporary to accumulator
:=:= addwf ACC0, f
:=:=
:=:=;shift accumulator right 2 times
:=:= rrf ACC0, f
:=:= clrc
:=:= rrf ACC0, f
:=:=
:=:=;add temporary to accumulator
:=:= addwf ACC0, f
:=:= clrf ACC1
:=:= rlf ACC1, f
:=:=
:=:=But I have problems..Css not compile the code it return un error for clrc and cblock istruction
:=:=Can you help me ?
:=:=THANK!!
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514777
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group