Shop OBEX P1 Docs P2 Docs Learn Events
How much Hub RAM remains? — Parallax Forums

How much Hub RAM remains?

It appears that the Hub RAM memory is zero above some point corresponding to the last cell of memory used by the code. If we start initially by prefilling the empty cells with a known value then allow the code to run we can at any time determine the extent of free memory by examining it from its highest address backwards until we encounter a non "known value" occurance. The rub lies in the choice of value, any arbitrary value can be valid data and if it should happen to be the at the end of the active memory area we would erroneously consider it free space. The pseudo random series used by the Stack Length object does not eliminate this possibility either, it just minimizes the probability that a valid data value equal to the pseudo random number would happen to exist in a particular memory location. Which is to say that Stack Length's output can be wrong, but I digress.

The two attached spin files are a first attempt at a solution to determining how much Hub RAM is unused at any given time, based upon the above concept and using Stack Length's approach to the problem. My tests with it have been successful thus far and I hope to get some feedback on the idea and possible alternatives from folks here. My reading of the forums has indicated that questions regarding memory available and stack lengths are an ongoing issue. Also there are apparently numerous reserved registers in Hub RAM that could shed some light on the problem if a concise compilation of these could be located (eg: WORD[10] being initial stack frame).

Thanks in advance

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2015-11-24 22:45
    Here's some of the documentation on the format of a Spin program as loaded into hub RAM. It's been posted several times over the years, but here it is again. There's an initial stack frame pushed into the stack during Spin interpreter initialization. It contains a return address to a COGSTOP(COGID) compiled into the Spin interpreter in ROM.
  • Thanks Mike
  • Mike Green wrote: »
    Here's some of the documentation on the format of a Spin program as loaded into hub RAM. It's been posted several times over the years, but here it is again. There's an initial stack frame pushed into the stack during Spin interpreter initialization. It contains a return address to a COGSTOP(COGID) compiled into the Spin interpreter in ROM.

    Thanks! Where did that document originate from? Was it all by one person or have people been adding to it over time? It's still missing a lot. Can I upload it to github (as a plain text file) so people can collaborate on it?
  • Here are a couple of files from my archives. They're RTF format, but could be converted to plain text.
  • AribaAriba Posts: 2,690
    edited 2015-11-25 00:29
    Mike Green wrote: »
    Here's some of the documentation on the format of a Spin program as loaded into hub RAM. It's been posted several times over the years, but here it is again. There's an initial stack frame pushed into the stack during Spin interpreter initialization. It contains a return address to a COGSTOP(COGID) compiled into the Spin interpreter in ROM.

    Thanks! Where did that document originate from? Was it all by one person or have people been adding to it over time? It's still missing a lot. Can I upload it to github (as a plain text file) so people can collaborate on it?

    It's a document from Hippy, he has these all discovered alone, at a time we had no source code of the interpreter and loader.
    The original was a plain textfle.

Sign In or Register to comment.