Specifications

BASIC Stamp II
Parallax, Inc. • BASIC Stamp Programming Manual 1.8 • Page 223
2
The commonsense rule for combining modifiers is that they must get
progressively smaller from left to right. It would make no sense to
specify, for instance, the low byte of a nibble, because a nibble is smaller
than a byte! And just because you can stack up modifiers doesn’t mean
that you should unless it is the clearest way to express the location of
the part you want get at. The example above might be improved:
rhino var word ‘ A 16-bit variable.
eye var rhino.bit9 ‘ A bit.
Although we’ve only discussed variable modifiers in terms of creating
alias variables, you can also use them within program instructions.
Example:
rhino var word ‘ A 16-bit variable.
head var rhino.highbyte ‘ Highest 8 bits of rhino.
rhino = 13567
debug ? head ‘ Show the value of alias variable head.
debug ? rhino.highbyte ‘ rhino.highbyte works too.
stop
You’ll run across examples of this usage in application notes and sample
programs—it’s sometimes easier to remember one variable name and
specify parts of it within instructions than to define and remember
names for the parts.
Modifiers also work with arrays; for example:
myBytes var byte(10) ‘ Define 10-byte array.
myBytes(0) = $AB ‘ Hex $AB into 0th byte
debug hex ? myBytes.lownib(0) ‘ Show low nib ($B)
debug hex ? myBytes.lownib(1) ‘ Show high nib ($A)
If you looked closely at that example, you probably thought it was a
misprint. Shouldn’t myBytes.lownib(1) give you the low nibble of byte
1 of the array rather than the high nibble of byte 0? Well, it doesn’t. The
modifier changes the meaning of the index value to match its own size.
In the example above, when myBytes() is addressed as a byte array, it
has 10 cells numbered 0 through 9. When it is addressed as a nibble
array, using myBytes.lownib(), it has 20 cells numbered 0 through 19.
You could also address it as individual bits using myBytes.lowbit(), in
which case it would have 80 cells numbered 0 through 79.