The real savings if you've got more than one place
that this is done is that you could just initialize the pertinent data in each
location :
> TSM_Curr2Ptr:
> ; ldi counter,5 ;a register such as r17
>
> ldi xl,low(TSM_Data_Curr) ;Setup origin
> ldi xl,high(TSM_Data_Curr)
>
> ldi yl,low(TSM_Data_Ptr) ;Setup destination
> ldi yl,high(TSM_Data_Ptr)
> ; ldi counter,5 ;a register such as r17
>
> ldi xl,low(TSM_Data_Curr) ;Setup origin
> ldi xl,high(TSM_Data_Curr)
>
> ldi yl,low(TSM_Data_Ptr) ;Setup destination
> ldi yl,high(TSM_Data_Ptr)
Then jump to the common cleanup to complete the
subroutine :
> lp:
> ld TSM_Temp, x+ ;Get data and increment x
> st y+, TSM_Temp ;Store data and increment
> dec counter
> brne lp
> ret
> ld TSM_Temp, x+ ;Get data and increment x
> st y+, TSM_Temp ;Store data and increment
> dec counter
> brne lp
> ret
----- Original Message -----From: Andrew LimSent: Thursday, December 16, 2004 9:04 AMSubject: Re: [AVR-Chat] More efficient and space saving codeHey Les,Thanks for pointing out. Its surely a shorter code from John...hahaha...Thanks again.Good job John !!Regards,Hi John,
Last time I looked, LDS and STS were 2 words each so the original
routine was 21 words... ;-) And your new routine is only 10 words so
it looks like a worthwhile saving... :-)
Regards,
Les.
On 10 Dec 2004 at 15:43, John Samperi wrote:
>
> At 06:52 PM 9/12/04 -0800, you wrote:
> > Hi guys, Is there anyone who can make this code more efficient?
>
> Use 2 of the index registers as pointers with auto increment.
> May not save much as your routine is only 10 words long.
>
> TSM_Curr2Ptr:
> ldi counter,5 ;a register such as r17
>
> ldi xl,low(TSM_Data_Curr) ;Setup origin
> ldi xl,high(TSM_Data_Curr)
>
> ldi yl,low(TSM_Data_Ptr) ;Setup destination
> ldi yl,high(TSM_Data_Ptr)
>
> lp:
> ld TSM_Temp, x+ ;Get data and increment x
> st y+, TSM_Temp ;Store data and increment
> dec counter
> brne lp
> ret
>
> Actually it's not shorter :-((.... but it would be shorter if you had lots
> more
> data to move. Perhaps there is a genius out there with a better solution :-))
>
> >TSM_Curr2Ptr:
> > lds TSM_Temp, TSM_Data_Curr
> > sts TSM_Data_Ptr, TSM_Temp
> > ; lds TSM_Temp, TSM_Data_Curr+! 1
> > sts TSM_Data_Ptr+1, TSM_Temp
> > lds TSM_Temp, TSM_Data_Curr+2
> > sts TSM_Data_Ptr+2, TSM_Temp
> > lds TSM_Temp, TSM_Data_Curr+3
> > sts TSM_Data_Ptr+3, TSM_Temp
> > lds TSM_Temp, TSM_Data_Curr+4
> > sts TSM_Data_Ptr+4, TSM_Temp
> > ret ; Exit ; Regards, Andrew
>
>
> Regards
>
> John Samperi
>
> ******************************************************
> Ampertronics Pty. Ltd.
> 11 Brokenwood Place Baulkham Hills, NSW 2153 AUSTRALIA
> Tel. (02) 9674-6495 Fax (02) 9674-8745
> Email: samperi@ampertronics.com.au
> Website http://www.ampertronics.com.au
> * Electronic Design * Custom Products * Contract Assembly
> ******************************************************
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
-------------------------------------------------------------
Les Grant. VK2KYJ. Phone: 02 9896 7150 Fax: 02 9896 7153
Grantronics Pty Ltd Int'l: +612 9896 7150, +612 9896 7153
ABN 46 070 123 643
PO Box 275, Wentworthville. NSW. 2145. Australia.
http://www.grantronics.com.au mailto:info@grantronics.com.au
Microcontroller Hardware and Software development: Atmel AVR
8051 derivatives, 80C196 family, C, ASM, Digital and analogue
-------------------------------------------------------------
Australian distributor for:
o Dunfield Development Systems low cost development tools
o ImageCraft AVR and Motorola Windows-hosted C compilers
o ELNEC Device Programmers (E)EPROMs, Flash, Micros, PLDs
o CAN-BUS Hardware and Software from LAWICEL
o Logical Systems Programming, Prototyping & Production Adaptors
-------------------------------------------------------------Do you Yahoo!?
The all-new My Yahoo! Get yours free!