# PUT

GET / PUT Examples

Syntax: PUT Location, {WORD} Value{,{WORD} Value ...}

## Function

Write one or more values to the Scratchpad RAM, starting at Location and building upward.

- Location is a variable/constant/expression (0 – 62 for BS2e and BS2sx, and 0 – 126 for BS2p, BS2pe, and BS2px) that specifies the Scratchpad RAM location to write to.
- Value is a variable/constant/expression to store in RAM.*

*Note: The optional arguments require PBASIC 2.5.

## Quick Facts

| BS2e and BS2sx | BS2p, BS2pe, and BS2px
Scratchpad RAM size and organization | 64 bytes (0 – 63). Organized as bytes only. | 136 bytes (0 – 135). Organized as bytes only.
General purpose locations | 0 - 62 | 0 – 126
Special use location | Current program slot number in read-only location 63. | Current program slot number in lowest nibble of read-only location 127. Current read/write slot number in highest nibble of location 127.
Additional locations | None | Locations 128 - 135 (read-only) hold state of polled input pins.
Related Commands | GET | GET, STORE
PBASIC 2.5 Syntax Options | Multiple sequential variables may be read from the Scratchpad RAM. The optional WORD modifier may be specified to retrieve 16-bit values.

## Explanation

The PUT command writes a value into the specified Scratchpad RAM location(s). All values in the general-purpose locations can be written to from within any of the eight program slots.

Scratchpad RAM is useful for passing data to programs in other program slots and for additional workspace. It is different than regular RAM in that symbol names cannot be assigned directly to locations and each location is always configured as a byte only. The following code will write the value 100 to location 25, read it back out with GET and display it:

The following example illustrates this:

    temp    VAR     Byte

    Main:
      PUT 25, 100
      GET 25, temp
      DEBUG DEC temp
      END

When using $PBASIC 2.5 syntax, Word-sized variables can be written to the Scratchpad RAM with a single PUT statement, as well as multiple items to consecutive locations. The Word modifier writes the low-byte first, then the high-byte ("Little Endian").

    ' {$PBASIC 2.5}

    value   VAR     Word
    value2  VAR     Word
    addr    VAR     Word                    ' EEPROM address
    test    VAR     Byte                    ' test byte read back

    Main:
      value = $11
      value2 = $2003
      PUT 0, value, Word value2             ' write value to SP location 0
                                            '  and value2 to SP locations 1 & 2

      value = $FF                           ' modify variables
      value2 = $FFFF

      GET 0, value, Word value2             ' retrieve from Scratchpad

      DEBUG HEX2 ? value                    ' display
      DEBUG HEX4 ? value2
      END

Most Scratchpad RAM locations are available for general use. The highest location (63 for BS2e/BS2sx and 127 for BS2p/BS2pe) is a special, read-only, location that always contains the number of the currently running program slot. On the BS2p/BS2pe, the upper nibble of location 127 also contains the current program slot that will be used for the READ and WRITE commands. Any values written to this location will be ignored.

Go to Welcome page

BASIC Stamp Help Version 2.5.4

Copyright © Parallax Inc.

8/8/2012