Shop OBEX P1 Docs P2 Docs Learn Events
Bank switching, variable names, the "file register not in current bank" error? — Parallax Forums

Bank switching, variable names, the "file register not in current bank" error?

ZootZoot Posts: 2,227
edited 2008-08-25 16:23 in General Discussion
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?

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

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2008-08-25 05:57
    That's right. It is·actually·a warning, not·an error.
    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
  • ZootZoot Posts: 2,227
    edited 2008-08-25 06:18
    Peter Verkaik said...
    That's right. It is actually a warning, not an error.
    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:

    ; equiv to if ( moto = 0 ){ bank motorleft } else { bank motorright }, 4 instructions
    MOV W, #motorLeft
    SNB moto  ; = 0 if left, =1 if right
    MOV W, #motorRight
    MOV FSR, W
    
    



    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:

    BANK motorLeft
    SNB moto  ; = 0 if left, =1 if right
    BANK motorRight
    NOP
    
    



    Because
    docs said...
    An exception to this rule are skip instructions that are immediately followed by a BANK or PAGE
    instruction. Here (provided that the tested condition is true), two instructions will be skipped, i.e. the
    BANK or PAGE instruction plus the next one. This is useful for conditional branching to another page
    where a PAGE instruction precedes a JMP. If several PAGE and BANK instructions immediately follow
    a skip instruction then they are all skipped plus the next instruction and a clock cycle is consumed for
    each.

    (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
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2008-08-25 06:52
    Zoot,
    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
  • ZootZoot Posts: 2,227
    edited 2008-08-25 07:26
    The warning is only for the *assembly* context, not SX/B context. Indeed, with @ I can do top down bankswitches in SX/B without dropping to assembly, but my assembly routines generate the warning regardless (top down based on most previous bank instruction).

    No matter -- it's a warning nono.gif and my work with this technique over the last week has been bug free so I'm pretty happy.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2008-08-25 07:30
    Strange, I do not get warnings, either from sx/b or sasm.

    regards peter
  • ZootZoot Posts: 2,227
    edited 2008-08-25 07:47
    Ahhh...

          BANK motorLeft            
          MOV ticks, __PARAM1       
          BANK motorRight           
          MOV ticks, __PARAM2       
          CALL @__CHECK_MD22   ; returns default bank
    

    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
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2008-08-25 08:12
    Zoot,
    In that thread I posted an updated version that resolves the warnings.

    regards peter
    ·
  • Guenther DaubachGuenther Daubach Posts: 1,321
    edited 2008-08-25 09:35
    Hi all,

    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
  • ZootZoot Posts: 2,227
    edited 2008-08-25 10:27
    said...
    mov fsr, #variable

    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
  • pjvpjv Posts: 1,903
    edited 2008-08-25 16:23
    Hi All;

    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)
Sign In or Register to comment.