variable memory
I am writing a program using the SX28 that requires many variables.· Where can I place new variables after location 1F?· And how do I make sure the program accesses that location instead of the first page?· Thanks.
Comments
Remember however, no matter what bank you are in, you ALWAYS have access to variables $08 ~ $0F if using the SX 28, and as long as you·NEVER switch banks, you also ALWAYS have access to $10 ~ 1F.
Once you switch to another bank, you no longer have access to $10 ~ $1F until you turn the bank back on.
Other banks that are available are:
$30
$50
$70
$90
$B0
$D0
$F0
Below is a snippet from a program on an SX28 using different banks.
Directly below you can see I have defined variables such as loopcnt, flag, mm, etc.....and I put a comment showing what address the variable belongs to. As you can see, I used up everything in the first bank , up to $1F
org $08
main equ $· ;give a the name "main" to the first bank....bank 0
ken ds 1 ; 08
X
X
X
loopcnt·ds·1·;15
flag·ds·1·;16.not needed but will keep for now
mm·ds·2·;17 & 18 - 17 is most significan byte
mx·ds·4·;19, 1a, 1b, & 1c
b3·ds·1·;1d
b2·ds·1·;1e
b1·ds·1·;1f
NEXT......to access the·another bank, I have the comment "define new bank for ADC conversion go BCD"
org $30 ;this line "defines the bank".....
adccalc equ $......this simply gives a name to the bank "$30" to make the programming more intuitive when I later switch to that bank in my program....
You can see that starting at org $30, I defined some more variables, again showing the·address [noparse][[/noparse]30 ~ 37]
;----[noparse][[/noparse]define new bank for ADC conversion to BCD]
org·$30
adccalc··equ·$
adczhigh·ds·1·;[noparse][[/noparse]30] adc zero cal low byte
adczlow··ds·1·;[noparse][[/noparse]31]adc zero cal high byte
adcshigh·ds·1·;[noparse][[/noparse]32] adc span cal low byte
adcslow··ds·1·;[noparse][[/noparse]33] adc span cal high byte
adcahigh·ds·1·;[noparse][[/noparse]34]
adcalow··ds·1·;[noparse][[/noparse]35]
denominator·ds·2·;[noparse][[/noparse]36low 37high] result of adc span minus adc zero
NEXT
I have a seperate bank for doing multiplication,
;----[noparse][[/noparse]define test bank for doing multiplication]
org·$50
multiply·equ·$
;fpr accums, operands, & mults, 4 is the msbyte
accumulator_4·· DS·1·;[noparse][[/noparse]50]32 bit <accumulator> for
accumulator_3·· DS·1·;[noparse][[/noparse]51]add32/subtract32/multiply32.
accumulator_2·· DS·1·;[noparse][[/noparse]52]aliased as <numerator> when doing divide32.
accumulator_1·· DS·1·;[noparse][[/noparse]53]aliased as <remainder> after divide32
Now, when I want to put data into the variable adcslow (location $33), my program must turn on that bank by writing....
BANK adccalc··; this makes the SX change banks
mow w,#$44
mov adcslow,w· ;adcslow now has the value $44
Once I am done with my business in this bank....I must change back to the bank that is needed for the next group of variables I will change.
Ideally, I believe it is best to group the same types of variables into seperate banks.
For example, all my ADC variables are in one bank, all variables that deal with mutiplication in another bank, and so on.
Remember, variables at address $08 ~ $0F (sx28) are "global" and can be accessed ANYTIME from ANYWHERE.
If you use more than one bank, you define it.....and give it an intuitive name
org $30
adcstuff equ $
Hope this helps more than it confuses........
check out http://www.parallax.com/detail.asp?product_id=70002
which is where I learned about banking...
Ken
as Ken already pointed out, when it comes to working with variables in different banks, it is very important to make sure that the right bank is selected (or is still selected) when you access a variable.
Similar to Ken, I give banks "speaking" names. Since a while, I also prefix all variable names in a specific bank with the bank name, like in
·········· org····· $08
Comm·· equ····· $
Comm_TxCount ds 1
Comm_TxData·· ds 1
Comm_RxCount ds 1
Comm_RxData·· ds 1
········· org······ $30
ADC···· equ····· $
ADC_Acc········ ds 1
ADC_Timer······ ds 1
This makes is easy when reading the source code to know which variable is in what bank, and code like this is obviously suspicious:
······· bank····· ADC
······· mov······ w, ADC_Acc
······· mov······ Comm_TxData, w··· ; !!!
As bank ADC is still selected, the last instuction above causes that the contents of w is written to ADC_Timer, and not to Comm_TxData, where this code
······· bank····· ADC
······· mov······ w, ADC_Acc
······· bank····· Comm
······· mov······ Comm_TxData, w
works as ecxpected.
Instead of writing (the bad code) like this
······· mov······ w, ADC_Acc
······· mov······ Comm_TxData, w
you might consider using a compound instruction, i.e.
······· mov······ Comm_TxData, ADC_Acc
which is a nogo here (and as far as I can remember, SASM generates an error in this case) because you don't have the chance correctly switching banks here.
There is another important thing to know, concerning skip and bank instructions:
······· stz·································· ; just for demonstation
······· sz
······· bank······ Comm
······· mov······· x, Comm_TxData
As the zero flag is set, the sz instruction will execute a skip. Here, the SX automatically skips the bank instruction plus the next mov instruction which makes a lot sense, as just skipping the bank instruction would directly lead into chaos.
In general, when any skip instruction is immediately followed by one or more subsequent bank instructions all these bank instructions are skipped plus the next non-bank instruction. The same is true for page instructions.
Good luck,
Günther
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
· SUB SPoint, #16
NoWrap· Xtra code
Sorry about the double spacing, the editor insisting on doing it. I don't know if this info would be of any use to you, but perhaps it would be to someone else.
Paul Baker
(edited 11/1/04, decrement code had some bugs in it)
PS. This is only for SX28 and below, there are no problems with bank 0 remapping in the SX48/52.
Post Edited (Paul Baker) : 11/1/2004 3:35:52 PM GMT
Thanks for another tip, that will certainly help me read my spaghetti code.
Ken