User variables
Archiver
Posts: 46,084
On 28 Nov 00 at 16:02, Forbesits@y... wrote:
> ...I have some code that looks similar to the following:
>
> Read 0,B24
> Read 1,B25
> For Rec=2 to W12 Step 3
> addr(Rec)=addr(Rec)+1
> debug DEC W12,CR
> loop
> For some reason, the value of W12 keeps changing. I'm not using
> the B24 or B25 variables anywhere else in my program and only use
> W12 for comparisons. Is it possible for my variables to overwrite
> the general purpose variables (W0-W12)?
There is one and only one general purpose variable space consisting
of 26 bytes=13 words, so writing to any variable must overwrite
somewhere in the general purpose variables (W0-W12). It's very
possible that the operations on your addr array, for instance, are
writing over the variable space designated as W12/B24-B25.
Steve
> ...I have some code that looks similar to the following:
>
> Read 0,B24
> Read 1,B25
> For Rec=2 to W12 Step 3
> addr(Rec)=addr(Rec)+1
> debug DEC W12,CR
> loop
> For some reason, the value of W12 keeps changing. I'm not using
> the B24 or B25 variables anywhere else in my program and only use
> W12 for comparisons. Is it possible for my variables to overwrite
> the general purpose variables (W0-W12)?
There is one and only one general purpose variable space consisting
of 26 bytes=13 words, so writing to any variable must overwrite
somewhere in the general purpose variables (W0-W12). It's very
possible that the operations on your addr array, for instance, are
writing over the variable space designated as W12/B24-B25.
Steve
Comments
I do not use the W0-W12 and B0-B25 variables much but I am now.
I have some code that looks similar to the following:
Read 0,B24
Read 1,B25
For Rec=2 to W12 Step 3
addr(Rec)=addr(Rec)+1
debug DEC W12,CR
loop
For some reason, the value of W12 keeps changing. I'm not using the
B24 or B25 variables anywhere else in my program and only use W12 for
comparisons. Is it possible for my variables to overwrite the
general purpose variables (W0-W12)? Did I completely misunderstand
the use of these variables.
Thanks, FS
>Hello All, yet another question,
>
>I do not use the W0-W12 and B0-B25 variables much but I am now.
>I have some code that looks similar to the following:
>
>Read 0,B24
>Read 1,B25
>For Rec=2 to W12 Step 3
> addr(Rec)=addr(Rec)+1
> debug DEC W12,CR
>loop
>
>For some reason, the value of W12 keeps changing. I'm not using the
>B24 or B25 variables anywhere else in my program and only use W12 for
>comparisons. Is it possible for my variables to overwrite the
>general purpose variables (W0-W12)? Did I completely misunderstand
>the use of these variables.
That's possible, but it is suggested that you use you own names to prevent
"collisions" with areas used by the Editor/Interpreter. If you use your own
names, they are always allocated outside of system areas. Alternative to
that reason, if too many variables (too much space is allocated) an error
message is produced. Data areas also can not be condensed if you use the
fixed location; thus, memory management suffers.
Finally, this (from Page 217) about says it all:
"We recommend that you avoid using the fixed variables in most situations.
Instead, let PBASIC2 allocate variables as described in the next
section. The host software will organize your storage requirements to
make optimal use of the available memory.
Why have fixed variables at all? First, for a measure of compatibility
with the BS1, which has only fixed variables. Second, for power users
who may dream up some clever hack that requires the use of fixed
variables. You never know... "
If you seek information on array storage and how easy it can be, take a
look around Pages 217-219. Other areas of interest are Pages 226-227.
That SHOULD get you started, and keep you out of harms way : )
>Thanks, FS
Sure
Regards,
Bruce Bates
> Hello All, yet another question,
>
> I do not use the W0-W12 and B0-B25 variables much but I am now.
> I have some code that looks similar to the following:
>
> Read 0,B24
> Read 1,B25
> For Rec=2 to W12 Step 3
> addr(Rec)=addr(Rec)+1
> debug DEC W12,CR
> loop
>
> For some reason, the value of W12 keeps changing. I'm not using
the
> B24 or B25 variables anywhere else in my program and only use W12
for
> comparisons. Is it possible for my variables to overwrite the
> general purpose variables (W0-W12)? Did I completely misunderstand
> the use of these variables.
>
> Thanks, FS
I agree that it is far better to use user-defined names for
variables, but just to clear up your problem... you understand the
B24 and B25 are part of W12?
Another way to have written this would be:
address var word
highaddr var word.highbyte
lowaddr var word.lowbyte
Read 0,highaddr
Read 1,lowaddr
For Rec=2 to address Step 3
addr(Rec)=addr(Rec)+1
debug DEC address,CR
next
This allow StampW to assign the memory location, and you to be able
manipulate the high and low byte of it directly.
(which is probably what is covered in those pages pointed out in
another message).
-Martin
http://www.selmaware.com