BASIC Stamp Architecture – Aliases and Modifiers
Page 54 • BASIC Stamp Programming Manual 2.0b • www.parallaxinc.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
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:
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
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)
2
2
2
Table 4.3: BS2, BS2e, BS2sx and
BS2p Variable Modifiers.