Positron Compiler Documentation

Subtract '-'

Positron16 · Revision 1.1.3.5 · PDF page 77

Assignment Variable = Variable - Variable

Subtracts variables and/or constants, returning an unsigned or signed 8, 16, 32-bit or floating point result.

Variables may be constants, variables or expressions. Assignment Variable can be any valid variable type.

Subtract works exactly as you would expect with signed and unsigned integers as well as floating point.

  Device = 24FJ64GA002           ' Select the device to compile for
  Declare Xtal = 16      ' Tell the compiler the device will be operating at 16MHz
  Declare Hserial1_Baud = 9600
  Declare Hrsout1_Pin = PORTB.14

  Dim MyWord1 as Word
  Dim MyWord2 as Word

  PPS_Output(cOut_Pin_RP14, cOut_Fn_U1TX)  ' Make Pin RB14 U1TX

  MyWord1 = 1000
  MyWord2 = 999
  MyWord1 = MyWord1 - MyWord2   ' Subtract the values.
  HrsoutLn Dec MyWord1            ' Display the result

' 32-bit subtraction
  Device = 24FJ64GA002           ' Select the device to compile for
  Declare Xtal = 16      ' Tell the compiler the device will be operating at 16MHz
  Declare Hserial1_Baud = 9600
  Declare Hrsout1_Pin = PORTB.14

  Dim MyWord as Word
  Dim MyDword as Dword

  MyWord = 1575
  MyDword = 9763647
  MyDword = MyDword - MyWord      ' Subtract the values.
  HrsoutLn Dec MyDword            ' Display the result

' 32-bit signed subtraction
  Device = 24FJ64GA002           ' Select the device to compile for
  Declare Xtal = 16      ' Tell the compiler the device will be operating at 16MHz
  Declare Hserial1_Baud = 9600
  Declare Hrsout1_Pin = PORTB.14

  Dim MyDword1 as SDword
  Dim MyDword2 as SDword

  PPS_Output(cOut_Pin_RP14, cOut_Fn_U1TX)  ' Make Pin RB14 U1TX

  MyDword1 = 1575
  MyDword2 = 9763647
  MyDword1 = MyDword1 - MyDword2  ' Subtract the values.
  HrsoutLn SDec MyDword1         ' Display the result
View original PDF page 77Open page in PDFOriginal PDF page 77