|
|
View previous topic :: View next topic |
Author |
Message |
acid Guest
|
ASM routine for multiplication |
Posted: Mon May 26, 2003 8:24 am |
|
|
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 |
Posted: Mon May 26, 2003 8:59 am |
|
|
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 |
Posted: Tue May 27, 2003 6:20 am |
|
|
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 |
|
|
|
|
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
|