BASIC stamp manual v2.2

BASIC Stamp Architecture – Aliases and Modifiers
Page 90 BASIC Stamp Syntax and Reference Manual 2.2 www.parallax.com
Symbol Definition
LOWBYTE low byte of a word
HIGHBYTE high byte of a word
BYTE0 byte 0 (low byte) of a word
BYTE1 byte 1 (high byte) of a word
LOWNIB low nibble of a word or byte
HIGHNIB high nibble of a word or byte
NIB0 nib 0 of a word or byte
NIB1 nib 1 of a word or byte
NIB2 nib 2 of a word
NIB3 nib 3 of a word
LOWBIT low bit of a word, byte, or nibble
HIGHBIT high bit of a word, byte, or nibble
BIT0 bit 0 of a word, byte, or nibble
BIT1 bit 1 of a word, byte, or nibble
BIT2 bit 2 of a word, byte, or nibble
BIT3 bit 3 of a word, byte, or nibble
BIT4 … BIT7 bits 4 though 7 of a word or byte
BIT8 … Bit15 bits 8 through 15 of a word
Table 4.3: Variable Modifiers for all
BS2 models.
The common sense 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:
rhino VAR Word ' A 16-bit variable
head VAR rhino.HIGHBYTE ' Highest 8 bits of rhino
rhino = 13567
DEBUG ? head ' Display alias variable head
DEBUG ? rhino.HIGHBYTE ' rhino.HIGHBYTE works too
STOP
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)
All
2