Bank switching, variable names, the "file register not in current bank" error?
![Zoot](https://forums.parallax.com/uploads/userpics/559/nW4UO23UEIWZ4.png)
To my knowledge the following works.... because I'm using the technique right now in a program.
Each element in a bank is the same "name" so I can use register assignments with MOV, ADD, etc, and only switch the BANK to grab, say, "speed" from bank $30, or "speed" from bank $50, etc.
So two questions.
1. is it *absolutely* the case that an instruction like MOV *only* uses the lowest 5/4 bits of the operand? So that the upper bits are *always* "don't care"?
2. when using this technique, SASM generates a "file register not in current bank" error. Should I presume that is a "you had better know what you are doing error" that can essentially be disregarded?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
Each element in a bank is the same "name" so I can use register assignments with MOV, ADD, etc, and only switch the BANK to grab, say, "speed" from bank $30, or "speed" from bank $50, etc.
So two questions.
1. is it *absolutely* the case that an instruction like MOV *only* uses the lowest 5/4 bits of the operand? So that the upper bits are *always* "don't care"?
2. when using this technique, SASM generates a "file register not in current bank" error. Should I presume that is a "you had better know what you are doing error" that can essentially be disregarded?
motorLeft VAR Byte(16) motorRight VAR Byte(16) motor CON motorLeft speed CON motor+0 ramp CON motor+1 ASM BANK motorLeft MOV W, speed ADD W, ramp MOV speed, W BANK motorRight MOV W, speed ' this generates file reg. not in current bank, but bit5-7 (sx28) are "don't care" so it works ADD W, ramp MOV speed, W ENDASM
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
Comments
If you use mov fsr,#MotorRight instead of bank MotorRight, the warning might disappear.
But mov fsr,# occupies 2 words and alters w.
regards peter
Ah... for once I'm with you or even one step ahead... that will not suppress the warning -- I tested a lot of variations and even if there are conditional bank statements, w/ or w/o the literal, the warning is generated. Even if you do it via FSR you'll get the warning because SASM seems to just use whatever the most previous bank statement is (top down).
I know it works, so I wasn't too worried, but curious. Also because of some the @ schemes for banking and variable assignment in the beta, I think that a lot more "proper" SX/B and ASM code will generate those warnings for users.
In my case I'm doing an FSR load in some portions where a single bit determines the bank, so at the top of a two count loop, so I made a SETBANK macro that goes like this:
I had tried this, but then I realized I would need a NOP? so I did the above for my sanity. But your notion of keeping W free is a good one, so maybe I'll go back to this:
Because
(that took me quite a while to find and figure out)
Thanks, as always!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
Post Edited (Zoot) : 8/25/2008 6:23:26 AM GMT
I just tried it in SXB 1.51.03
Changing Bank MotorRight into mov fsr,#MotorRight
makes the warning disappear.
I also tried it in the sx/b beta, but then you must also change
motor con MotorLeft into motor con @MotorLeft.
Then the warning also disappears.
regards peter
No matter -- it's a warning
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
regards peter
Generates the warning... from SASM. That said, I've done a bit of tricky aliasing so I can use the registers in SX/B the way I want and in ASM the way I want.
I posted code here if you are curious... http://forums.parallax.com/showthread.php?p=745562
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
In that thread I posted an updated version that resolves the warnings.
regards peter
·
the "file register not in current bank" error has been introduced as a warning in SASM a while ago as a good aid to protect a commonly made error in SASM by addressing a variable w/o selecting the correct bank before. In your case, you know what you are doing, and I like this trick so address a group of variables in different banks with the same code by just switching to another bank.
mov fsr, #variable may or may not remove the warning. In the end, this is similar to a bank instruction but requires two clock cacles, and modifies W.
I'm not sure if there is a switch in SASM, like LIST=something to suppress the warning. Peter Montgomery could help here.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Greetings from Germany,
G
Loading the FSR rather than loading the higher bits of the FSR with a bank instruction will eliminate the warnings. I like BANK though because it's a single instruction. Thanks.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
But for the SX48/52 please remember that BANK only works on its lower 4 bits... so banks 0 through 7 . A switch from/to the upper group, banks 8 through F, must be manually effected by clr/set of bit7 of fsr, or, of course, loading a mov fsr,w.
Cheers,
Peter (pjv)