In SX Microcontrollers, SX/B Compiler and SX-Key Tool, rwatts wrote: I have an SX/B project that has filled up the SX-28 program memory, so I need to optimize. Because of the number of variables I needed, I had to create several arrays. Variables in these arrays have to be accessed indirectly and this has contributed quite a few words to the program size. I've come up with a scheme to eliminate much of this indirect addressing and I wanted to run it by the group. Here it is: 1. Group all (or substantially all) the variables for a code segment, such as a subroutine, into an array, such as: sub1Data VAR BYTE(16) 2. Create "aliases" for these variables as byte or word variables addressed in Bank 0, addresses $10-1F. For example, define a new variable such as sub1Byte0 at address $10 to correspond to the real data at sub1Data(0). Repeat this for each element of the sub1Data array. These "alias" variables can be defined using SX/B declarations by paying careful attention to aliasing and order of appearance in the source code. 3. At the beginning of the code segment add the SX/B directive: BANK sub1Data and at the end of the segment add the directive: BANK 0 4. Within this code segment, refer to the sub1Data variables by their Bank 0 alisases. Commands will compile with direct addressing and will reference the correct sub1Data addresses. RAM addresses $10-1F cannot be accessed within the code segement without inserting additional BANK directives. Care must be taken to ensure that execution flow does not enter the segment without executing the BANK sub1Data instruction and does not exit the segment without executing the BANK 0 instruction. Does anyone see a problem with this? Can anyone suggest a better approach? Thanks. ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=146212 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2006 (http://www.dotNetBB.com)