PUT Location, Value {, Value, ... }

Function
Copy Value(s) into RAM, beginning at Location.

Explanation
The PUT instruction provides a convenient method of moving multiple values into consecutive locations in RAM. For example,

  clock(0) = hrs                                ' copy hrs to clock(0)
  clock(1) = mins                               ' copy mins to clock(1)
  clock(2) = secs                               ' copy mins to clock(2)

Can be simplified to a single line of code:

  PUT clock(0), hrs, mins, secs 

Note that array elements are internally represented by RAM addresses. To use PUT with consecutive bytes that are not part of an array, you must explicitly declare the address of the first variable using the @ symbol:

  PUT @hrs, 12, 34, 56                          ' hrs = 12, mins = 34, secs = 56

When Value is a word, its LSB is written from Location and its MSB to Location + 1. For example:

loVal    VAR     Byte
hiVal    VAR     Byte

Start:
  PUT @loVal, $F00A                             ' loVal = $0A, hiVal = $F0

PUT can be used to load string characters into a byte array:

  PUT msg, "Hello", 0

Using PUT With Address Parameters
When a variable is passed to a subroutine (declared with SUB) by address (using @), as in:

  Some_Routine @aValue                          ' pass address of 'aValue'

... PUT can be used to place a value into the address that was passed to the subroutine:

Some_Routine:
  rtnAddr = __PARAM1                            ' save return address
  GET rtnAddr, theValue                         ' get value from address
  ...                                           ' do something with the value
  PUT rtnAddr, newValue                         ' update value at passed address
  RETURN

This technique is useful for allowing a subroutine to modify a variable. Note that for single-parameter instances, the __RAM() system array may be used in place of GET and PUT:

Some_Routine:
  rtnAddr = __PARAM1                            ' save return address
  theValue = __RAM(rtnAddr)                     ' get value from address
  ...                                           ' do something with the value
  __RAM(rtnAddr) = newValue                     ' update value at passed address
  RETURN


Related instruction: GET