Skip to content
Rodion Gorkovenko edited this page Dec 25, 2018 · 2 revisions

This page describes the memory layout.

Both program and data are stored in RAM. However program is saved into non-volatile memory (either Flash or Eeprom) on save or before run.

Array dataSpace in RAM is used to store both data and program. If we have two constants, say, PROG_SPACE_SIZE and VARS_SPACE_SIZE to describe the amounts of memory for program and data respectively, then dataSpace size equals to their sum.

First part of dataSpace (equaling to VARS_SPACE_SIZE bytes) is for data (variables and arrays).

Memory for variables is organized as cells of size 2 + sizeof(numeric) bytes, so it can hold variable name (two letters) or array name (single letter and array flag) and value (data offset in case of array).

Array bodies are kept after all declared variables, according to their offsets. When new variable or array is added, new cell is inserted in this space (maintaining alphabetic order of variables), shifting other data as necessary, and array body (if any) is added to the end.

Execution stack resides in the same area as variables, but it grows from end. So it's first cell will be at

dataSpace + VARS_SPACE_SIZE - sizeof(numeric)

And it can collide with variables eventually if not enough free space left :(

Program space resides in the second part (i.e. starting at dataSpace + VARS_SPACE_SIZE). The first two bytes here describe the program length. Further text lines follows, each preceded by two bytes line number.

Line being entered in interfactive mode has its own buffer, with spare space to perform encoding to tokens.

Clone this wiki locally