avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Now to do Tail Recursions?


From: Douglas Dotson
Subject: Re: [avr-gcc-list] Now to do Tail Recursions?
Date: Mon, 30 Aug 2004 17:14:38 -0700 (PDT)

This only works when the only thing on the stack is
the return address. High level languages like C
establish a stack frame that includes local varbs,
parameters, registers, etc.

Doug

--- Bob Paddock <address@hidden> wrote:

> 
> Some gcc targets have an option of "-mtail-call" to
> optimize
> calls followed immediately by a return into a jump
> to the subroutine.
> 
> Example:
> 
> rcall hex8
> ret
> 
> becomes
> 
> rjmp hex8
> 
> I tried -mtail-call with avr-gcc and I get "invalid
> option" from cc1.
> 
> Did I not use it correctly, or more likely it is is
> not implemented?
> 
> Anyone have a AWK or perl script that does it the
> hard way at hand already?
> 
> In a related size question why are there two 'ret'
> instructions, one right  
> after
> the other?  'ret ret' wastes two bytes.
> 
>    22:hexprint.c    **** uint8_t convert_to_hex(
> uint8_t a ) /* Return hex  
> character of passed nibble */
>    23:hexprint.c    **** {
>    78                 .LM1:
>    79                 /* prologue: frame size=0 */
>    80                 /* prologue end (size=0) */
>    24:hexprint.c    ****     if( a < 10 )
>    82                 .LM2:
>    83 0000 8A30               cpi r24,lo8(10)
>    84 0002 18F4               brsh .L2
>    25:hexprint.c    ****      return( (uint8_t) (a +
> (uint8_t) '0') );             /* 0 ->  
> 9 */
>    86                 .LM3:
>    87 0004 805D               subi r24,lo8(-(48))
>    88 0006 9927               clr r25
>    89 0008 0895               ret
>    90                 .L2:
>    26:hexprint.c    ****     else
>    27:hexprint.c    ****      return( (uint8_t) ((a + 7)
> + (uint8_t) '0') );   /*  
> A -> F */
>    92                 .LM4:
>    93 000a 895C               subi r24,lo8(-(55))
>    94 000c 9927               clr r25
>    28:hexprint.c    **** }
>    96                 .LM5:
>    97 000e 0895               ret
>    98                 /* epilogue: frame size=0 */
>    99 0010 0895               ret
>   100                 /* epilogue end (size=1) */
>   101                 /* function convert_to_hex size
> 9 (8) */
> 
> 
> 
> 
> _______________________________________________
> avr-gcc-list mailing list
> address@hidden
> http://www.avr1.org/mailman/listinfo/avr-gcc-list
> 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]