# GET / PUT Examples

Syntax: GET, PUT

NOTE: This is written for the BS2sx and will also run on the BS2e, BS2p, BS2pe, and BS2px. Modify the $STAMP directive (as required) before downloading to the BS2e, BS2p, BS2pe, or BS2px.

    ' GET_PUT1.BSX
    ' This example demonstrates the use of the GET AND PUT commands.  First,
    ' slot location is read using GET to display the currently running program
    ' number.  Then a set of values are written (PUT) into locations 0 TO 9.
    ' Afterwards, program number 1 is RUN.  This program is a BS2SX project
    ' consisting of GET_PUT1.BSX and GET_PUT2.BSX, but will run on the BS2e,
    ' BS2p, BS2pe, and BS2px without modification.

    ' {$STAMP BS2sx, GET_PUT2.BSX}
    ' {$PBASIC 2.5}

    #SELECT $STAMP
      #CASE BS2
        #ERROR "BS2e or greater required."
      #CASE BS2E, BS2SX
        Slot        CON     63
      #CASE BS2P, BS2PE, BS2PX
        Slot        CON     127
    #ENDSELECT

    value           VAR     Byte
    idx             VAR     Byte

    Setup:
      GET Slot, value
      DEBUG "Program Slot #", DEC value.NIB0, CR

    Main:
      FOR idx = 0 TO 9
        value = (idx + 3) * 8
        PUT idx, value
        DEBUG "  Writing: ", DEC2 value, " to location: ", DEC2 idx, CR
      NEXT
      DEBUG CR
      RUN 1
      END

    ' GET_PUT2.BSX
    ' This example demonstrates the use of the GET and PUT commands.  First,
    ' the Slot location is read using GET to display the currently running
    ' program number.  Then a set of values are read (GET) from locations
    ' 0 to 9 and displayed on the screen for verification.  This program is a
    ' BS2SX project consisting of GET_PUT1.BSX and GET_PUT2.BSX, but will run
    ' on the BS2e, BS2p, BS2pe, and BS2px without modification.

    ' {$STAMP BS2sx}
    ' {$PBASIC 2.5}

    #SELECT $STAMP
      #CASE BS2
        #ERROR "BS2e or greater required."
      #CASE BS2E, BS2SX
        Slot        CON     63
      #CASE BS2P, BS2PE, BS2PX
        Slot        CON     127
    #ENDSELECT

    value           VAR     Byte
    idx             VAR     Byte

    Setup:
      GET Slot, value
      DEBUG "Program Slot #", DEC value.NIB0, CR

    Main:
      FOR idx = 0 TO 9
        GET idx, value
        DEBUG "  Reading: ", DEC2 value, " from location: ", DEC2 idx, CR
      NEXT
      END

Go to Welcome page

BASIC Stamp Help Version 2.5.4

Copyright © Parallax Inc.

8/8/2012