In SX Microcontrollers, SX/B Compiler and SX-Key Tool, Sparks-R-Fun wrote: Rsadeika, I have been trying to understand how to best utilize memory and variable space myself. So here is what I have concluded based upon what others are saying. That is this. The key to this problem will likely be found in the understanding of where your variables reside in relation to the SX memory and how to access them properly when using assembly language subroutines. All of the mental gymnastics involving in tracking memory locations and banks is conveniently handled when using pure SX/B code. Jumping to assembly sometimes requires this to be known and sometimes not. Here is what I did to try to coax the program you supplied into working properly. 1.) I made the changes I recommended previously creating independent variables for each UART and placed them together into a 16 byte array, a.k.a. a bank. This bank is selected by the UART code with "[B]BANK Serial[/B]" commands that were already in place. 2.) I added a "[B]BANK tix[/B]" command at the start of your SIRCS subroutine to select the memory bank holding the tix variable (and hopefully all of the other SIRCS variables as well) and a "[B]BANK 0[/B]" at the end to place the bank selection back to 0. My hope was that all of the SIRCS variables would conveniently happen to reside within the same bank. Unfortunately, they did not as evidenced by "File register not in current bank" compiler errors. This is where the whole trick to getting everything to work together comes into play. You need to understand where your variables are when you access then in assembly. (I am so glad SX/B takes care of this automatically!) If you want to see what I am talking about, download the attached program but move the variable assignments for tmpB1 and tmpW1 back to their previous location, which was right after the SIRCS variable definitions and just before the interrupt statement. Then examine the compiler listing (CTRL-L) of the modified program. You should see the following: (NOTE: Any other program will likely produce a different output.) [CODE] 161 =0000000F tix EQU 0x0F ;tix var word 162 =0000000F tix_LSB EQU tix 163 =00000010 tix_MSB EQU tix+1 [/CODE] You can see that when arranged as I just described tix begins at address $0F, the last address of Bank 0. (The Most Significant Byte (MSB) of tix actually resides one address higher at the start of the next bank!) The rest of the SIRCS variables also reside in the next bank, which is not quite so convenient for quick and easy access. 3.) What I did to provide a "quick fix" for this ("fixing" was not really required as there are ways to deal with variables in different banks) was to move the variable assignments for tmpB1 and tmpW1 so that they occurred earlier in the program listing. That way when variable space is being assigned, all the SIRCS variables happen to fall into the same memory bank! That makes things more convenient, a key element to keeping things simple when using assembly subroutines. 4.) I moved the bit flags for the UARTS to a byte within the same array as Step 1. 5.) Since there are now two UARTS I created duplicated subroutines to access them. This is probably not the most compact way to access them but it was a "quick fix." :smilewinkgrin: I do not know if the modified program I have supplied actually works. I hope you will let us know. - Sparks ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=182347#m183223 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2007 (http://www.dotNetBB.com)