Shop OBEX P1 Docs P2 Docs Learn Events
Memory usage within SX/B - Memory Map — Parallax Forums

Memory usage within SX/B - Memory Map

Tony LeylandTony Leyland Posts: 71
edited 2005-11-04 07:14 in General Discussion
Hi,

I've come back to developing on the SX after a 6 month break and now find SX/B to be a fantastic product. So much
so that I've now switched from developing completely in Assember, to using SX/B as my main environment and using
Assember routines where needed.

I'd like to ask, is there some documentation somewhere that explains the locations in memory that are used within SX/B
for variable storage and any other memory used for the inner workings of SX/B ?

The reason I ask is that I have (within a ASM -> ENDASM section) memory management routines that allow me to allocate
a contigous logical block of memory (like an array - up to 100bytes on the SX28) that I can access from Assember or SX/B.
The memory bank switching is done all for me in the background, when I'm accessing elements in the logical block. At the moment
memory allocation grows down from the topmost memory location (like a Stack).

So if I ask the memory manager to allocate 30 bytes for me, then the last byte of this logical array is situated at the topmost memory
location of the SX device and the 1st one 30 bytes down in memory from there. If I then ask for another 40 bytes, then the end of this new logic
array is the memory location just before that of the 1st byte of the previously allocated logical array.

Sorry for the long explaination, but I wanted to explain what I'm trying to acheive, as I do not want to overwrite any memory
locations that SX/B uses itself. I was wondering, if there was a read only parameter that I could read to obtain the last memory
location SX/B is currently using - due to the various VAR declarations).

I'm under the impression that SX/B uses memory certain locations at top of RAM for I/O port parameters. If I could ask if anyone
knows anything about this, then I would appreciate it as I'd be able to adjust my memory manager to set it's topmost area of available
storage to the byte just below the space used internally by SX/B. I would then also stop arrays from being created that come down and interfere
with the storage for the VARS in SX/B.

Thanks for you help,
Tony

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-11-03 14:35
    The cool thing about SX/B is that nothing is hidden; you can look at the compiled output and see exactly what's going on. In order to make it a bit PBASIC-like, SX/B keeps "shadow" registers at the high-end of RAM. These registers allow SX/B to keep track of the TRIS registers, for example, so that when a command affects an IO pin the others can be maintained (HIGH and LOW make the pins outputs, etc.).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • BeanBean Posts: 8,129
    edited 2005-11-03 14:50
    Tony,
    On the SX28 SX/B uses the global page and the 1st bank for "normal" (non-array) variables.
    All the other banks are used for arrays. But SX/B will not span banks that is why the largest array is 16 elements (on the SX28).
    SX/B allocates arrays from lowest memory address to highest memory address.

    You said "So if I ask the memory manager to allocate 30 bytes for me, then the last byte of this logical array is situated at the topmost memory". By "topmost" do you mean lowest memory address or highest memory address ?

    As Jon said the TRIS shadow registers are at the highest memory address of the highest bank.

    If you can manage it, the SX/B on the SX48 allows large arrays.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

    http://www.parallax.com/detail.asp?product_id=30012
    Product web site: www.sxvm.com
    Available now... SX-Video OSD module $59.95 www.sxvm.com

    Those that would give up freedom for security will have neither.
    ·
  • Tony LeylandTony Leyland Posts: 71
    edited 2005-11-03 17:04
    Hi Bean,

    I've attached a screen grab and coloured the memory locations (SX28) that get assigned for the 30 byte array (in red) and the 40 byte array (in cyan).

    The 30 byte array has it's first array element at location D2 and the last one (topmost as I called it in the last post) at location FF.
    The 40 byte array has it's first array element at location 7A and the last one (topmost as I called it in the last post) at location D1.

    Now the next time I call my memory management routine to ask for another array to be allocated (say 12 bytes), the first array element
    will be at location 5E and the last one at location 79.

    What I would like to now please is: What are the exact memory locations used for the storage of TRIS register etc that Jon mentioned in high address
    in the hight bank.

    That way I can adjust my memory management routine to stay away from this area when allocating memory for my arrays (SX28). As an example, if the TRIS etc
    is using locations FA to FF then my 30 byte array mentioned above would move 'down' in memory and have it's 1st array element at location BC and end at F9.
    The 40 byte array would also move 'down' respectfully. In that way I never interfere with the 'reserved' locations used by SX/B. I would also
    of course need to keep a track of the address of the LAST variable that I have defined in SX/B, so that my arrays cannot be assigned into this area.

    Thanks for pointing out advantages of SX48 to me, I'll certainly consider using them.

    Tony
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-11-03 17:09
    Here' you go,·right out of the output file·(use Ctrl-L to view) -- this is on an SX28:

    ··· 32· =000000FA······ __TRISA······ EQU· $FA
    ··· 33· =000000FA······ TRIS_A······· EQU· $FA
    ··· 34· =000000FB······ __TRISB······ EQU· $FB
    ··· 35· =000000FB······ TRIS_B······· EQU· $FB
    ··· 36· =000000FC······ __TRISC······ EQU· $FC
    ··· 37· =000000FC······ TRIS_C······· EQU· $FC
    ··· 38· =000000F5······ __INTPARAMFSR EQU· $F5

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • BeanBean Posts: 8,129
    edited 2005-11-03 17:16
    Tony,
    Just as a note SX/B also uses locations $F5 to $F9 to store __PARAM1..4 during an interrupt.
    If you would first create a dummy array of 11 elements that should prevent it from using SX/B reserved memory locations.

    Also in your asm routines you are free to use __PARAM1..4. These are global memory locations and are very handy to use.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

    http://www.parallax.com/detail.asp?product_id=30012
    Product web site: www.sxvm.com
    Available now... SX-Video OSD module $59.95 www.sxvm.com

    Those that would give up freedom for security will have neither.


    Post Edited (Bean (Hitt Consulting)) : 11/3/2005 5:27:20 PM GMT
  • Tony LeylandTony Leyland Posts: 71
    edited 2005-11-04 07:14
    Thanks guys very much for your help, I now see what you mean by SX/B does not hide anything - the LST file
    shows it all !

    Tony
Sign In or Register to comment.