View Full Version : Forth Variable types
MKEARNY
07-26-04, 05:58 PM
I'm looking over the Max-Forth glossary trying to make sense of the variable types (http://www.ee.ualberta.ca/~rchapman/MFwebsite/V50/Alphabetical/Brief/index.html)
I can see by the variable declaration words that there are 3 variable types:
2VARIABLE: double length word
DVARIABLE: seems to work but isn't dosumented
FVARIABLE: Floating Point variable
VARIABLE: Single Length variable
And since I'm at it theres also the Constant declaration words:
2CONSTANT
DCONSTANT
FCONSTANT
CONSTANT 16
MKEARNY
07-26-04, 06:04 PM
Looks like I hit send too soon here ;)
I'm looking over the Max-Forth glossary trying to make sense of the variable types (http://www.ee.ualberta.ca/~rchapman...rief/index.html)
I can see by the variable declaration words that there are 3 variable types:
2VARIABLE: double length word
DVARIABLE: seems to work but isn't dosumented
FVARIABLE: Floating Point variable
VARIABLE: Single Length variable
And since I'm at it theres also the Constant declaration words:
2CONSTANT
DCONSTANT
FCONSTANT
CONSTANT
What variable type (signed integer, unsigned integer, or floating point) and size (1 byte, 2 byte, 4 byte) is each variable type?
Thanks,
Mike Kearny
I'm not sure where you got DVARIABLE or DCONSTANT from, but they don't exist. As for the storage types, there are integers, double integers and floats. Any can be signed or unsigned. As matter of fact, the responsibility for knowing the type is left with the programmer as there is no compiler enforced typing. A variable or constant will contain the biggest integer for that platform. If you are on a 16 bit micro like the HC12, it will be 16 bits. If you are on a 32 bit micro like the MCore, then it will be 32 bits. Double integers are twice as big as integers. Floats are the IEEE 32 bit floats in both cases except on the HC11 where they are in a different 48-bit higher precision format.
If you are comparing addresses which are unsigned, then you should use U< instead of <. There are read and write operators for the different variables: @, 2@ and F@, !, 2! and F!. SF@ and SF! are synonyms for F@ and F! on all platforms except HC11.
Rob
MKEARNY
07-27-04, 02:44 PM
"I'm not sure where you got DVARIABLE or DCONSTANT from, but they don't exist."
I found them on the IsoMax™ V0.6 Words Listing:
http://www.newmicros.com/store/product_manual/words06.pdf
I hope I'm posting in the right spot here.
I'm using an IsoPodX with Motorola DSP56F805 with a 16 data bus, so a VARIABLE and CONSTANT should be 16 bits.
nmitech
07-27-04, 03:44 PM
They are listing here,
http://www.newmicros.com/store/product_manual/IsomaxGlossary.pdf
from the 'Pod download page,
http://www.newmicros.com/store/product_details/download.html
Ah the IsoPod. Yes that does have DVARIABLE and DCONSTANT. They are just synonyms for 2VARIABLE and 2CONSTANT. And you are right the DSP is 16 bit so CONSTANT and VARIABLE will be 16 bit while 2VARIABLE and 2CONSTANT will contain 32 bit values.
Since the stack is 16 bits wide these 32 bit values will occupy two stack items with the upper 16 bits on top and lower 16 bits on bottom. For instance if you type in:
HEX 1234.5678 2CONSTANT X X . .
You will get the two values back but separately to print both as one just use:
X D.
The '.' dot in 1234.5678 can occur anywhere and it tells the number parser to treat the number as a double number instead of a single number. It is a nice way to write the longer numbers. Otherwise you would write it as:
5678 1234
Rob
vBulletin v3.0.7, Copyright ©2000-2010, Jelsoft Enterprises Ltd.