On Commodore machines featuring CBM BASIC v2, the FRE()
function to query the amount of memory available to BASIC returns a negative number when the result exceeds 32767 bytes:
This quirk does not exist on machines with CBM BASIC v4, v3.5, or v7.
I already understand, on a purely technical level, why a negative value is returned: the free memory is calculated as an unsigned 16-bit integer, but the FRE()
routine interprets the result of this calculation as a signed 16-bit integer (which it goes on to convert to floating point). My question is whether this behaviour is by design or a bug. I don't recall any contemporary programming guides claiming it is a bug, and Commodore's own documenation doesn't refer to it as such. (The Commodore 64 User Guide, for example, simply says, "Note that FRE(X) will read out n negative numbers [sic] if the number of unused bytes is over 32K."
If this behaviour is by design, what benefit does it bring? Was it simply more expedient for the CBM BASIC interpreter programmers to have implemented it that way, or did they have some benefit for the end user in mind?
38911 Bytes Free