In SX Microcontrollers, SX/B Compiler and SX-Key Tool, g_daubach wrote: Letting the variables "overflow" into the next bank can cause you a lot of sleepless nights. Here is an example: [code] org $8 aaa ds 1 bbb ds 1 ccc ds 1 ddd ds 1 eee ds 1 fff ds 1 ggg ds 1 hhh ds 1 iii ds 1 org $10 jjj ds 1 [/code] When you look at the list file, you will notice that the assembler has defined address $10 for variable iii due to "overflowing" the bank border but it also has defined address $10 for variable jjj as it is defined immediately following the org $10 directive. SASM does not generate an error because in general, it is absolutely legal referring to one value by more than one symbol. The disaster will come up when you indeed assume that iii and jjj are two different variables occupying different RAM locations. As this is not the case, modifying the contents of variable iii also changes the contents of variable jjj, and vice-versa, which is not what you might expect. Therefore, it's a good idea to check the list file for such possible pitfalls. BTW, the same is true for code-generation across page boundaries. [code] org $2f3 ClearVars clr !wdt sb fsr.4 setb fsr.3 clr ind incsz fsr jmp ClearVars bank PWM mov PWM_Prescaler, #PWMPeriod mov !option, #INT_ON :MainLoop bank Analog mov w, Analog_ADCresult mov rb, w bank PWM mov PWM_DutyCycle, w jmp :MainLoop [/code] When you assemble this code, and look at the list file, you will notice that code generation "overflows" into the next page, i.e. the instruction code for "mov w, Analog_ADCResult" will be located at $02ff, and the instruction code for "mov rb, w" is at $300, with the next instruction codes following at subsequent locations in page $0300. To make the disaster complete, see what happens when the final "jmp :MainLoop" is executed. As the SX-internal program counter is simply incremented as long as no skips, jumps, or calls are executed, there is no problem, crossing the page when this code is executed the very first time. But the final jmp instruction targets to a location which is not in the page currently addressed by the program counter. So, this jump will not go back to address $2fe, the first instruction following the label ":MainLoop" but the jump will go to $3FE instead, i.e. right into "nowhere land". Here is a "trick" to let the assembler generate an error on such situations: Place nop instructions at the very first location of each page, as long as you don't need that page for "real" code. When you follow the lines of this sample code with org $300 nop SASM will generate an "Overwriting same program counter location" error in this case. ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=94182#m94408 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2005 (http://www.dotNetBB.com)