<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns:MadCap="http://www.madcapsoftware.com/Schemas/MadCap.xsd" MadCap:lastBlockDepth="6" MadCap:lastHeight="94" MadCap:lastWidth="853" MadCap:disableMasterStylesheet="true" MadCap:tocPath="" MadCap:InPreviewMode="false" MadCap:PreloadImages="false" MadCap:RuntimeFileType="Topic" MadCap:TargetType="WebHelp" lang="en-us" xml:lang="en-us" MadCap:PathToHelpSystem="../../../" MadCap:HelpSystemFileName="Default.xml" MadCap:SearchType="Stem"> <head><title>PUT</title> <link href="../../SkinSupport/MadCap.css" rel="stylesheet" /> <link href="../../Resources/Stylesheets/BSE_Help.css" rel="stylesheet" /> <script src="../../SkinSupport/MadCapAll.js" type="text/javascript"> </script> </head> <body> <h1 class="code">PUT</h1> <div class="ImagePlusCaption"> <div class="Col2"> <p> <img src="../../graphics/pgm_icon2e.gif" border="0" alt="BS2e icon" title="BS2e icon" /> <img src="../../graphics/pgm_icon2sx.gif" border="0" alt="BS2sx icon" title="BS2sx icon" /> <img src="../../graphics/pgm_icon2p.gif" border="0" alt="BS2p icon" title="BS2p icon" /> <img src="../../graphics/pgm_icon2pe.gif" border="0" alt="BS2pe icon" title="BS2pe icon" /> <img src="../../graphics/pgm_icon2px.gif" border="0" alt="BS2px icon" title="BS2px icon" /> </p> </div> <p style="text-align: right;"><a href="../ExampleTopics/GetPutEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">GET / PUT Examples</a> </p> <p> </p> </div> <p class="clear"> </p> <p> </p> <p class="PlainText">Syntax: <span class="keyword_in_text">PUT</span> <![CDATA[ ]]><i>Location</i>, {<i>WORD</i>}<i> Value</i>{,<i><![CDATA[ ]]></i>{<i>WORD</i>}<i> Value ...</i>}</p> <h2>Function</h2> <p class="PlainText">Write one or more values to the Scratchpad RAM, starting at <i>Location</i> and building upward. </p> <ul> <li value="1"><b><i>Location</i></b> 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.</li> <li value="2"><b><i>Value</i></b> is a variable/constant/expression to store in RAM.*</li> </ul> <p class="PlainText">*Note: The optional arguments require PBASIC 2.5.</p> <h2>Quick Facts</h2> <table width="100%" cellpadding="4" cellspacing="0" border="1"> <tr> <td width="24%" align="center" bgcolor="#CFCFCF"> </td> <td width="38%" align="center" bgcolor="#CFCFCF">BS2e and BS2sx</td> <td width="38%" align="center" bgcolor="#CFCFCF">BS2p, BS2pe, and BS2px</td> </tr> <tr> <td align="center" bgcolor="#CFCFCF">Scratchpad RAM size and organization</td> <td align="center">64 bytes (0 – 63). Organized as bytes only.</td> <td align="center">136 bytes (0 – 135). Organized as bytes only.</td> </tr> <tr> <td align="center" bgcolor="#CFCFCF">General purpose locations</td> <td align="center">0 - 62</td> <td align="center">0 – 126</td> </tr> <tr> <td align="center" bgcolor="#CFCFCF">Special use location</td> <td align="center">Current program slot number in read-only location 63.</td> <td align="center">Current program slot number in lowest nibble of read-only location 127. Current read/write slot number in highest nibble of location 127. </td> </tr> <tr> <td align="center" bgcolor="#CFCFCF">Additional locations</td> <td align="center">None</td> <td align="center">Locations 128 - 135 (read-only) hold state of polled input pins.</td> </tr> <tr> <td align="center" bgcolor="#CFCFCF">Related Commands</td> <td align="center"><a href="GET.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">GET</a> </td> <td align="center"><a href="GET.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">GET</a>, <a href="STORE.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">STORE</a></td> </tr> <tr> <td align="center" bgcolor="#CFCFCF">PBASIC 2.5 Syntax Options</td> <td align="center" colspan="2"> <p colspan="2" align="center">Multiple sequential variables may be read from the Scratchpad RAM. </p> <p colspan="2" align="center">The optional WORD modifier may be specified to retrieve 16-bit values.</p> </td> </tr> </table> <h2>Explanation</h2> <p class="PlainText">The <span class="keyword_in_text">PUT</span> 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.</p> <p class="PlainText">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 <span class="keyword_in_text">GET</span> and display it:</p> <p class="PlainText">The following example illustrates this:<br></br></p><pre class="BScode" xml:space="preserve"> temp VAR Byte Main: PUT 25, 100 GET 25, temp DEBUG DEC temp END </pre> <p class="PlainText">When using $PBASIC 2.5 syntax, Word-sized variables can be written to the Scratchpad RAM with a single <span class="keyword_in_text">PUT</span> statement, as well as multiple items to consecutive locations. The Word modifier writes the low-byte first, then the high-byte (<i>"Little Endian"</i>).</p> <p> <img src="../../graphics/bsesxppepx_inline.gif" border="0"> </img> </p><pre class="BScode" xml:space="preserve"> ' {$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 </pre> <p class="PlainText">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 <span class="keyword_in_text">READ</span> and <span class="keyword_in_text">WRITE</span> commands. Any values written to this location will be ignored.</p> <div class="Col2"> <div class="MasterFoot"> <p MadCap:conditions="BSEconditions.BSEWebHelp (Primary)-INCLUDE"><a href="../../HomeTopics/HomePage.htm">Go to Welcome page</a> </p> </div> </div> <div class="Col2"> <div class="MasterFoot"> <p style="text-align: right;"><span class="ContactInfoProjectName">BASIC Stamp Help</span> <![CDATA[ ]]><span class="ContactInfoVersion#">Version 2.5.4</span> <![CDATA[ ]]></p> <p style="text-align: right;">Copyright © <span class="ContactInfoCompanyName">Parallax Inc.</span></p> <p style="text-align: right;"><span class="SystemShortDate">8/8/2012</span> </p> </div> </div> <script type="text/javascript">/* <![CDATA[ */ var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-285614-1']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); /* ]]> */</script> <script type="text/javascript" src="../../SkinSupport/MadCapBodyEnd.js"> </script> </body> </html>