Positron Compiler Documentation

Pop

Positron16 · Revision 1.1.3.5 · PDF pages 341–342

Pop Variable, {Variable, Variable etc}

Pull a single variable or multiple variables from the microcontroller’s stack.

Variable is a user defined variable of type Bit, Byte, Word, Dword, Float, Array, or String.

The amount of bytes pushed on to the stack varies with the variable type used. The list below shows how many bytes are pushed for a particular variable type, and their order. The microcontroller’s stack is word orientated, therefore all operations are accomplished using 16-bits.

Bit2 Bytes are popped containing the value of the bit pushed.
Byte2 Bytes are popped containing the value of the byte pushed.

Byte Array 2 Bytes are popped containing the value of the byte pushed.

Word 2 Bytes are popped. Low Byte then High Byte containing

the value of the word pushed. Word Array 2 Bytes are popped. Low Byte then High Byte containing the value of the word pushed. Dword Array 4 Bytes are popped. Low Byte, Mid1 Byte, Mid2 Byte then High Byte containing the value of the dword pushed. Float Array 4 Bytes are popped. Low Byte, Mid1 Byte, Mid2 Byte then High Byte containing the value of the dword pushed.

Dword 4 Bytes are popped. Low Byte, Mid1 Byte, Mid2 Byte then High Byte

containing the value of the dword pushed.

Float 4 Bytes are popped. Low Byte, Mid1 Byte, Mid2 Byte then High Byte

containing the value of the float pushed.

String 2 Bytes are popped. Low Byte then High Byte that point to the

start address of the string previously pushed.

' Push two variables on to the stack then retrieve them

  Device = 24HJ128GP502        ' Select the device to compile for
  Declare Xtal = 16
  Declare Stack_Size = 90   ' Increase the stack to hold extra words

  Dim MyWord as Word     ' Create a Word variable
  Dim MyDword as Dword    ' Create a Dword variable

 MyWord = 1234       ' Load the Word variable with a value
 MyDword = 567890      ' Load the Dword variable with a value
  Push MyWord, MyDword    ' Push the Word variable then the Dword variable

  Clear MyWord        ' Clear the Word variable
  Clear MyDword       ' Clear the Dword variable

  Pop MyDword, MyWord     ' Pop the Dword variable then the Word variable
  Print Dec MyWord, "  ", Dec MyDword ' Display the variables as decimal
View original PDF page 341Open page in PDFOriginal PDF page 341
' Push a String on to the stack then retrieve it

  Device = 24HJ128GP502             ' Select the device to compile for
  Declare Xtal = 16
  Declare Stack_Size = 90           ' Increase the stack to hold extra words

  Dim SourceString as String * 20   ' Create a String variable
  Dim DestString as String * 20   ' Create another String variable

  SourceString = "Hello World"      ' Load the String variable with characters

  Push SourceString               ' Push the String variable's address

  Pop DestString   ' Pop the previously pushed String into DestString
  Print DestString ' Display the string, which will be "Hello World"
' Push a Quoted character string on to the stack then retrieve it

  Device = 24HJ128GP502             ' Select the device to compile for
  Declare Xtal = 16
  Declare Stack_Size = 90           ' Increase the stack to hold extra words

  Dim DestString as String * 20   ' Create a String variable

  Push "Hello World" ' Push the Quoted String of Characters on to the stack

  Pop DestString   ' Pop the previously pushed String into DestString
  Print DestString ' Display the string, which will be "Hello World"

Unlike the 8-bit PIC® microcontroller’s, the PIC24® and dsPIC33® types have a true stack that occupied RAM and stores call and return data as well as data pushed onto it. This is a valuable resource for saving and restoring variables or SFRs than would otherwise be altered.

There are two declares for use with the stack. These are:

Declare Stack_Size = 20 to n (in words) The compiler sets the default size of the microcontroller’s stack to 60 words (120 bytes). This can be increased or decreased as required, as long as it fits within the RAM available. The compiler places a minimum limit of 20 for stack size. If the stack overflows or underflows, the microcontroller will trigger an exception.

Declare Stack_Expand = 1 or 0 or On or Off Whenever an interrupt handler is used within a BASIC program, it must context save and restore critical SFRs and variables that would otherwise get overwritten. It uses the microcontroller’s stack for temporary storage of the SFRs and variables, therefore the stack will increase with every interrupt handler used within the program. If this behaviour is undesirable, the above declare will disable it. However, the user must make sure that the stack is large enough to accommodate the storage, otherwise an exception will be triggered by the microcontroller.

See also : Push.

View original PDF page 342Open page in PDFOriginal PDF page 342