From: Ullrich von Bassewitz (uz_at_musoftware.de)
Date: 2004-01-22 19:23:32
Hi! On Thu, Jan 22, 2004 at 05:22:02PM +0100, Benjamin Bahnsen wrote: > I sometimes use global variables for loops and math stuff, because they seem > to be faster than local variables. Using #pragma staticlocals (on); would probably be a better idea in this case. > But i am not able to declare them as > register variables to gain even more speed. The register-command does only > seem to work within functions. That is correct. One problem is that there is limited space in the zeropage register bank. Since all modules would use this limited space, chances are that the linker detects an overflow. To resolve this overflow, the linker would have to change the generated code (not to use the zeropage), which is not possible. > I tried to declare a pointer to a zeropage adress, like > > unsigned char *c = (unsigned char*)0xFF; > > but if i want to write something into c, with "*c = 100", the compiler > doesn't recognize, that c points to the zeropage and uses the same code as > for a "normal" address. This is ok, since the compiler doesn't know if c = (unsigned char*) 0x8000; is executed at some other place in the code. c is a variable, so it can be changed (besides that, cc65 is not very good in tracking variable contents, so this may even happen when c is not a global variable). > Is there a way to globally declare variables, so that are located at the > zero page? There are two ways, but neither will cause the compiler to use the variable for addressing. That is, you will get shorter code when loading from and storing to the variable, but the variable will not be used as a pointer in a similar way as "real" register variables. 1. Use a numeric address: #define c (*(unsigned char*)0xFF) 2. Define the variable in an assembler file, declare them as external in your C file, and use #pragma zpsym("name") to import it as zeropage symbol in the generated assembler module. Regards Uz -- Ullrich von Bassewitz uz_at_musoftware.de ---------------------------------------------------------------------- To unsubscribe from the list send mail to majordomo_at_musoftware.de with the string "unsubscribe cc65" in the body(!) of the mail.
This archive was generated by hypermail 2.1.3 : 2004-01-22 19:23:54 CET