Positron Compiler Documentation

Aliases

Source: Positron16 Compiler User Manual, PDF page 37

The Symbol directive is the primary method of creating an alias, however Dim can be used to create an alias to a variable. This is extremely useful for accessing the separate parts of a variable.

Dim Fido as Dog
                           ' Fido is another name for Dog
Dim Mouse as Rat.LowByte
                           ' Mouse is the first byte (low byte) of word Rat
Dim Tail as Rat.HighByte
                           ' Tail is the second byte(high byte) of word Rat
Dim Flea as Dog.0
                           ' Flea is bit-0 of Dog, which is aliased to Fido

There are modifiers that may also be used with variables. These are HighByte, LowByte,

Byte0, Byte1, Byte2, Byte3, Word0, Word1, HighSByte, LowSByte, SByte0, SByte1,

SByte2, SByte3, SWord0, and SWord1,

Word0, Word1, Byte2, Byte3, SWord0, SWord1, SByte2, and SByte3 may only be used in conjunction with 32-bit Dword or SDword type variables.

HighByte and Byte1 are one and the same thing, when used with a Word or SWord type variable, they refer to the unsigned High byte of a Word or SWord type variable: -

  Dim MyWord as Word
                              ' Create an unsigned Word variable
  Dim MyWord_Hi as MyWord.HighByte
' MyWord_Hi now represents the unsigned high byte of variable MyWord

Variable MyWord_Hi is now accessed as a Byte sized type, but any reference to it actually alters the high byte of MyWord.

HighSByte and SByte1 are one and the same thing, when used with a Word or SWord type variable, they refer to the signed High byte of a Word or SWord type variable: -

  Dim MyWord as SWord
                              ' Create a signed Word variable
  Dim MyWord_Hi as MyWord.SByte1
' MyWord_Hi now represents the signed high byte of variable MyWord

Variable MyWord_Hi is now accessed as an SByte sized type, but any reference to it actually alters the high byte of MyWord.

However, if Byte1 is used in conjunction with a Dword type variable, it will extract the second byte. HighByte will still extract the high byte of the variable, as will Byte3. If SByte1 is used in conjunction with an SDword type variable, it will extract the signed second byte. HighSByte will still extract the signed high byte of the variable, as will SByte3.

The same is true of LowByte, Byte0, LowSByte and SByte0, but they refer to the unsigned or signed Low Byte of a Word or SWord type variable: -

  Dim MyWord as Word
                              ' Create an unsigned Word variable
  Dim MyWord_Lo as MyWord.LowByte
' MyWord_Lo now represents the low byte of variable MyWord

Variable MyWord_Lo is now accessed as a Byte sized type, but any reference to it actually alters the low byte of MyWord. The modifier Byte2 will extract the 3rd unsigned byte from a 32-bit Dword or SDword type variable as an alias. Likewise Byte3 will extract the unsigned high byte of a 32-bit variable.

Dim Dwd as Dword
                         ' Create a 32-bit unsigned variable named Dwd
Dim Part1 as Dwd.Byte0 ' Alias unsigned Part1 to the low byte of Dwd
Dim Part2 as Dwd.Byte1 ' Alias unsigned Part2 to the 2nd byte of Dwd
Dim Part3 as Dwd.Byte2 ' Alias unsigned Part3 to the 3rd byte of Dwd
Dim Part4 as Dwd.Byte3 ' Alias unsigned Part3 to the high 4th byte of Dwd

The modifier SByte2 will extract the 3rd signed byte from a 32-bit Dword or SDword type variable as an alias. Likewise SByte3 will extract the signed high byte of a 32-bit variable.

Dim sDwd as SDword
                           ' Create a 32-bit signed variable named sDwd
Dim sPart1 as sDwd.SByte0 ' Alias signed Part1 to the low byte of sDwd
Dim sPart2 as sDwd.SByte1 ' Alias signed Part2 to the 2nd byte of sDwd
Dim sPart3 as sDwd.SByte2 ' Alias signed Part3 to the 3rd byte of sDwd
Dim sPart4 as sDwd.SByte3 ' Alias signed Part3 to the 4th byte of sDwd

The Word0 and Word1 modifiers extract the unsigned low word and high word of a Dword or SDword type variable, and is used the same as the Byten modifiers.

Dim Dwd as Dword
                           ' Create a 32-bit unsigned variable named Dwd
Dim Part1 as Dwd.Word0
                           ' Alias unsigned Part1 to the low word of Dwd
Dim Part2 as Dwd.Word1
                           ' Alias unsigned Part2 to the high word of Dwd

The SWord0 and SWord1 modifiers extract the signed low word and high word of a Dword or SDword type variable, and is used the same as the SByten modifiers.

Dim sDwd as SDword
                              ' Create a 32-bit signed variable named sDwd
Dim sPart1 as sDwd.SWord0
                              ' Alias Part1 to the low word of sDwd
Dim sPart2 as sDwd.SWord1
                              ' Alias Part2 to the high word of sDwd

Subtopics