Shop OBEX P1 Docs P2 Docs Learn Events
bs2p: jumping to different banks resets variables?!? — Parallax Forums

bs2p: jumping to different banks resets variables?!?

trendtrend Posts: 112
edited 2004-12-02 11:44 in BASIC Stamp
Hello, I have a bs2p24 project in which the code is so large, we had to use 4 banks. Bank 0 has the main routine.. and a couple of subroutines. banks 1,2,3 have all subroutines.


The way the main routine accesses the subroutines (between different banks) is:

com = 1 (1 of course can be different depending on what subroutine I need to access)
RUN 2· (this is different depending on what bank I need to access)


and

in banks 1,2, and 3.. I have something like this:


Main:
IF com = 1 THEN PBScan········· 'from Bank 0 Main
IF com = 2 THEN contactscan
IF com = 3 THEN contactscan1
IF com = 5 THEN contactscan3



Of course, I have to declare the variables in each bank (?) so I do so like: com············ VAR···· Byte

my problem is that everytime the routine goes to a bank, the "com" is set/reset to 255... and thus doesn't run any of the subroutines.. I know it is 255 because I do a "debug ? com, cr"




do you'll have any ideas? is it because I am redeclaring the variable com in each bank? (I thought that.. but i do a debug ? cmd, cr before com gets first declared.. and it says com is 0.. i believe itwas 0.. it definitly wasn't 255)


thanks for any pointers! Lee

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-12-02 02:59
    If you want to preserve your variables when switching banks YOU MUST declare all the variables the same in each of the banks. The easiest way to do this is to copy (all of) your variable declarations from bank 0 to bank 1, bank 2, etc. Note that the declarations must be EXACTLY the same; the same names, sizes, and in the same order. The reason is because the compiler assigns RAM space by size, not by name.

    If you need more variables and don't want to do all the copying, have a look at this article I wrote on how to put subroutines into extra program banks:

    http://www.parallax.com/dl/docs/cols/nv/vol3/col/nv87.pdf

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • trendtrend Posts: 112
    edited 2004-12-02 06:19
    Yep, that was the problem. Thanks so much for your quick response.. I would of never figured that out.. Honestly, I don't see myself ever guessingabout something like that :/

    thanks!
    Lee
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-12-02 11:44
    In the Help file, under the RUN command, there is a section called "What Happens to IO Pins and RAM When Using RUN?" that gives a short explanation and demo of mystery variable changes when the assignments from bank-to-bank don't match.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
Sign In or Register to comment.