So few variables
Escamoteur
Posts: 12
Hi,
this is my first project on a BS2. So far I always programmed on bigger CPUs like DSP or ARM in C++
Iwas a little bit shocked about the limited space for variables.
Do I have to declare them all at the beginning of my programm or can I declare them also in a subroutine?
How can I reuse the same RAM space with another variable name if I don't need a variable over the whole program but want to use meaningful identifiers.
What about arrays? In the Reference Manual it's described how to use them, but not how they fit into the RAM?
Any help on how to get started in this different way of programming would be helpful. It almmost feels as if I have to manage memory and registers as when programming assembly.
All the best
Thomas
this is my first project on a BS2. So far I always programmed on bigger CPUs like DSP or ARM in C++
Iwas a little bit shocked about the limited space for variables.
Do I have to declare them all at the beginning of my programm or can I declare them also in a subroutine?
How can I reuse the same RAM space with another variable name if I don't need a variable over the whole program but want to use meaningful identifiers.
What about arrays? In the Reference Manual it's described how to use them, but not how they fit into the RAM?
Any help on how to get started in this different way of programming would be helpful. It almmost feels as if I have to manage memory and registers as when programming assembly.
All the best
Thomas
Comments
The manual discusses something called an "alias". This is just a renaming of a variable, possibly referencing just a portion of the variable like a 4-bit nibble or a single bit. It's often used so a variable can be shared by different parts of a program.
Arrays are just a group of adjacent simple variables. The same limited storage is used.
Because of the limited amount of variable space, it may be better to think of them as registers. The underlying PIC processor (for the BS2) uses them as registers.
There is limited program space as well. If you use a lot of text in DEBUG statements or have lots of long I/O statements like SERIN / SEROUT, you can run out more quickly than you might think. For most applications, it's not a problem.