• Please review our updated Terms and Rules here

Format of Variables in BASIC?

AAGDOS

Experienced Member
Joined
Jul 4, 2018
Messages
104
Location
Hartford, CT
I am confused on how the BASIC Interpreter is formatting the values of integers? They do not seem to be either straight binary or BCD?? I typed in and ran a very simple BASIC program...

10 N=2
20 END

Start of Basic (SOB) is correct at $0801. The code ends with 3 zeros at $0810. On Using the ML monitor to look at the variable "N" in memory, I see $0811 - $0817 as.....
4E ,0, 82, 0 ,0, 0, 0 82 is correct with Hi bit set for integer, and the "2" in binary.

If I change the code to

10 N=3
20 END

The ML monitor shows the variable in memory $0801-$0817...
4E, 0, 82, 40, 0, 0, 0

Why is this not 4E, 0, 83, 0, 0, 0, 0 ......??????

I tried N=4, N=5, N=6 and got a similar confusion!

Any thoughts would be appreciated!

Anthony G
 
I'd suggest looking at the book that has the TRS-80 Level II Basic disassembly. Everything is explained in there.
 
It's called "single precision floating point". Commodore-era BASICs use 5-byte floats, and no other types except string. The 4E00 is the first and second bytes of the variable name. I think strings and arrays are marked by the high bits in the variable name.

The 82 is the exponent, and the other four bytes are the mantissa. IIRC the first "1" bit is implied. 8200 means 1.0 x 2^1 and 8240 means 1.1 (binary) x 2^1. (The 80 bit of the second byte is the sign bit.) I'm guessing that 4, 5, and 6 should be 8300 8320 and 8340 respectively.
 
Thanks to Robbert and Bruce for the good information! I will follow up and get to the bottom of this.!!!! I have the books by Mark Andrews and Jim Butterfield, but had not yet really dug into the variables' values being expressed in floating point numbers! It was hard to "reverse engineer" from the binary.

Anthony G
 
Back
Top