Shop OBEX P1 Docs P2 Docs Learn Events
scratch pad RAM question — Parallax Forums

scratch pad RAM question

ArchiverArchiver Posts: 46,084
edited 2001-03-16 17:02 in General Discussion
hello,
I was wondering how i can have a variable in one probram bank be able
to be used in the other program banks (0-7) is there some special
instruction for this?

lets say the variable was called steve
steve var word
steve = 1234

how do i get all 8 banks of memory to recognise the variable steve?

pleas help...give example code if possible!
thanks
steve

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2001-03-15 01:12
    [font=arial,helvetica]In a message dated 3/14/01 6:48:36 PM Central Standard Time,
    sznavor23@hotmail.com writes:


    I was wondering how i can have a variable in one probram bank be able
    to be used in the other program banks (0-7) is there some special
    instruction for this?

    lets say the variable was called steve
    steve var word
    steve = 1234

    how do i get all 8 banks of memory to recognise the variable steve?

    pleas help...give example code if possible!



    No and Yes. ·Since "No" is not the answer you want, let's get to "Yes."

    If you have the same variable definitions in all eight banks, your variables
    will remain intact. ·Since this is not usually practical (the "No" part from
    above), you have to use the Scratchpad RAM to share variables.

    You write data in the SPRAM with PUT. ·This works like WRITE, that is, it
    writes a byte to the scratchpad. ·You can retrieve a byte from SPRAM with
    GET. ·In your case, with a word-sized variable, you'll need two PUTs and two
    GETs. ·Like this:

    ' Pgm 0

    PUT 0,steve.LowByte
    PUT 1,steve.HighByte
    RUN 1


    ' Pgm 1

    GET 0,steve.LowByte
    GET 1,steve.HighByte




    [/font]
  • ArchiverArchiver Posts: 46,084
    edited 2001-03-15 03:02
    One fine point Jon,

    What you say is true. However, one way to make sure this is OK is to quit
    letting the BS2 assign variables. Do it yourself.

    So if you say:

    steve var w1
    al var b0


    Just make sure you understand that b0,b1 = w0; b2,b3 = w1, etc. etc.

    Now if all the programs use the same it all works.


    So I agree with Jon, No if you auto assign variables, yes if you do it
    yourself.

    Regards,

    Al Williams
    AWC
    * Spring break special: http://www.al-williams.com/awce



    I was wondering how i can have a variable in one probram bank be able
    to be used in the other program banks (0-7) is there some special
    instruction for this?

    lets say the variable was called steve
    steve var word
    steve = 1234

    how do i get all 8 banks of memory to recognise the variable steve?

    pleas help...give example code if possible!


    No and Yes. Since "No" is not the answer you want, let's get to "Yes."

    If you have the same variable definitions in all eight banks, your variables
    will remain intact. Since this is not usually practical (the "No" part from
    above), you have to use the Scratchpad RAM to share variables.

    You write data in the SPRAM with PUT. This works like WRITE, that is, it
    writes a byte to the scratchpad. You can retrieve a byte from SPRAM with
    GET. In your case, with a word-sized variable, you'll need two PUTs and two
    GETs. Like this:

    ' Pgm 0

    PUT 0,steve.LowByte
    PUT 1,steve.HighByte
    RUN 1


    ' Pgm 1

    GET 0,steve.LowByte
    GET 1,steve.HighByte





    Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
  • ArchiverArchiver Posts: 46,084
    edited 2001-03-16 17:02
    >I was wondering how i can have a variable in one probram bank be able
    >to be used in the other program banks (0-7) is there some special
    >instruction for this?
    >lets say the variable was called steve
    >steve var word
    >steve = 1234
    >how do i get all 8 banks of memory to recognise the variable steve?
    >pleas help...give example code if possible!
    >thanks
    >steve


    Hi Steve,

    Make it the first variable you define in each and every bank:

    ' this is program steve.bsx, bank 0
    '{$Stamp bs2sx,steve1.bsx,steve2.bsx}
    steve var word
    steve=1234
    run 1

    ' this is program steve1.bsx, bank 1
    ' {$stamp bs2sx}
    steve var word
    debug ?steve
    run 2

    ' this is program steve2.bsx, bank 2
    ' {$stamp bs2sx}
    steve var word
    steve=steve+1
    pause 500
    run 1

    It is easy to handle word variables in this way, because the Stamp
    software assigns word variables first in memory in the order they are
    defined. Bytes, nibs and bits are a bit trickier. You should define
    them as aliases to chunks of word variables. E.g.

    steve var word
    znavor var word
    zna var znavor.byte1
    vorA var znavor.byte0.nib1
    vor0 var znavor.byte0.bit0
    ' etc. keeps bytes, nibs and bits in controlled locations

    That gives you the most flexibility. "Local" variable definitions
    can follow the globals, for temporary use in a bank without trashing
    the "global" ones.

    I have a writeup on this approach to defining cross-bank variables on
    my web site at
    http://www.emesystems.com/BS2SX.htm

    That is just one way to do it. As Al pointed out, the predefined
    variables (w0--w12 or b0--b25) point directly to the 25 sequential
    bytes in the main memory and bypass the Stamp's automatic memory
    management, and as Jon pointed out, the scratchpad memory also is
    addressed as a linear memory array.

    The main point is that the contents of the RAM memory is unaffected
    by the RUN command.

    -- regards,
    Tracy Allen
    electronically monitored ecosystems
    http://www.emesystems.com
Sign In or Register to comment.