Confusion over the use of word variables and corresponding byte variables

fastgrandad

New Member
Am I right in thinking that once I have started using a word variable, I cannot then use its constituent byte variables for anything else, e.g. w0, b0 and b1?

If I put 'write 0,b0 write 1,b1' to save the word variable w0 for a future 'read', can I no longer allocate b0 and b1 to anything else, even if I clear them before the read takes place?

You might be asking, why would you want to do this but I'm getting short on byte variables.
 

Technical

Technical Support
Staff member
w0 is made up on b0 and b1.
It's sometimes easier to consider w0 as just a shorthand way of writing (256 x b1) + b0

So if you have saved both b1 and b0 in EEPROM via a write, you can then reuse b1, b0 (and hence w0) as you wish. They are no longer needed (as the original value in them has been saved in EEPROM) and so can be reused safely for something else.
 

SAborn

Senior Member
There is no problem in re-using variables, as long as they dont conflict with a use somewhere else in the program.

I often call a variable "working " or "temp" that i use over and over in a program for short time uses in loops or calculations or data transfer applications, etc.
 

lbenson

Senior Member
Note also that there are "general purpose" variables available above the named ones (b0, etc.). These can be accessed with peek and poke, or @bptr. See page 11 in Manual 1. In addition, on the X2 parts you have scratchpad storage space, available with get and put and @ptr. And for M2 parts there are "system variables"--the word variables s_w1 through s_w6 which you can use.

None of these has the write restrictions which EEPROM storage has, so you can write to them as often as you need without worrying about burning them out (e.g. one or more times a second).

The special advantage of EEPROM is that values stored there will persist through a power cycle.
 
Last edited:

PaulRB

Senior Member
Hi FG,

By the way, you can even more easilly do:

Write 0, word w0

To save the whole word in one go. And you can use "word" when reading back also.

But I would avoid doing this just to free up variables. The eeprom has a limited number of write cycles, albeit a very large number. As ibenson says, unlike ram, it will wear out if you continually write to it over and over in your program.

Paul
 

fastgrandad

New Member
Thanks. I'm only writing to the EEROM very occasionally and probably only once or twice as its a user setup parameter which, once they find a value they like, will probably be left alone.
I'm going to have to a lot more disciplined in 'declaring' my variables like we used to have to do with ALGOL circa late 1960's! At least now we don't have to prepare punch cards, but the discipline was good.

Paul
 
Top