[cc65] Stack usage optimization

From: Jakub <debski.jakub1wp.pl>
Date: 2010-09-13 17:00:11
Hi,

The following code:

void fun_a()
{
  unsigned char index;
  index=0x12;
}

void fun_b()
{
  unsigned char index;
  index=0x24;
}

void main(void)
{
  fun_a();
  fun_b();
}

CC65 with -Cl option generates:

.segment "CODE"
.proc _fun_a: near
.segment "BSS"
L0003:
 .res 1,$00
.segment "CODE"
; index=0x12;
 lda     #$12
 sta     L0003
 rts
.endproc
;
.proc _fun_b: near
.segment "BSS"
L0007:
 .res 1,$00
.segment "CODE"
; index=0x24;
 lda     #$24
 sta     L0007
 rts
.endproc

.proc _main: near
 jsr     _fun_a
 jmp     _fun_b
.endproc

In this case one byte is wasted, while both functions could use the same 
stack space. In bigger programs it can eat up to a few hunderd bytes. What 
about computing graph of function calls and automatically allocate same 
addresses for local variables of function that do not call each other?

regards,
Jakub 

----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Mon Sep 13 17:00:20 2010

This archive was generated by hypermail 2.1.8 : 2010-09-13 17:00:24 CEST