[Coco] BASIC: order of operations query, and PRINT MEM
William Astle
lost at l-w.ca
Fri Jul 8 02:57:55 EDT 2022
That extra 26 bytes is the stack and several bytes that mark an empty
program. The variable table takes zero space unless you actually define
a variable. Note that there's also a slop factor used in the calculation
for OM errors that MEM doesn't take into account so the maximum usable
memory is about 30 bytes less than what MEM says.
You different in results is a distribution problem in your
non-parenthesized line.
A + B - C + D
is NOT the same as
(A + B) - (C + D)
You need the latter because the two bytes being added together are a
single number. Without the parens, you would have to distribute the
negative:
A + B - C - D
So basically you made an elementary arithmetic error.
On 2022-07-07 22:52, Allen Huffman via Coco wrote:
> In BASIC, you can get the 16-bit value from two 8-bit values in memory like this:
>
> PRINT PEEK(25)*256+PEEK(26)
>
> That is the start of where a BASIC program goes.
>
> On a non-disk 32K Extended BASIC machine it prints 7681.
>
> BASIC can grow from there to the start of reserved string space:
>
> PRINT PEEK(33)*256+PEEK(34)
>
> On the same machine, that prints 32566.
>
> Max BASIC program would be 32566 - 7681 = 24885.
>
> But that’s about 26 bytes different from what PRINT MEM shows (24871) so there’s probably some overhead for variable tables and such.
>
> I noticed when I did the calculation in one line:
>
> PRINT PEEK(33)*256+PEEK(34)-PEEK(25)*256+PEEK(26)
>
> …I got 24887.
>
> At first I thought maybe some memory was being used to create the calculation. But when I did it again, enclosing each side with parenthesis:
>
> PRINT (PEEK(33)*256+PEEK(34))-(PEEK(25)*256+PEEK(26))
>
> ...I got 24885 — two bytes different.
>
> That made me think it was an order of operations thing.
>
> The 25/26 location/value should not change. Neither should the start of string space 34/35.
>
> PRINT PEEK(x)*256+PEEK(y)
>
> produces the same value as
>
> PRINT (PEEK(x)*256+PEEK(y))
>
> What is the obvious thing that is happening that I am not seeing?
>
> Thanks, much.
>
> --
> Allen Huffman - PO Box 7634 - Urbandale IA 50323 - 515-999-0227 (vmail/TXT only)
> http://www.subethasoftware.com - https://www.facebook.com/subethasoftware
>
>
>
--
William Astle
More information about the Coco
mailing list