MEMPUT: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
(Created page with "{{DISPLAYTITLE:_MEMPUT}} The _MEMPUT statement writes data to a portion of a designated memory block at an OFFSET position. {{PageSyntax}} : _MEMPUT {{Parameter|memoryBlock}}, {{Parameter|bytePosition}}, {{Parameter|sourceVariable}} [AS {{Parameter|type}}] {{Parameters}} * {{Parameter|memoryBlock}} is a _MEM variable type memory block name created by _MEMNEW or the _MEM function. * {{Parameter|bytePosition}} is the {{Parameter|...")
 
No edit summary
Line 9: Line 9:
{{Parameters}}
{{Parameters}}
* {{Parameter|memoryBlock}} is a [[_MEM]] variable type memory block name created by [[_MEMNEW]] or the [[_MEM (function)|_MEM]] function.
* {{Parameter|memoryBlock}} is a [[_MEM]] variable type memory block name created by [[_MEMNEW]] or the [[_MEM (function)|_MEM]] function.
* {{Parameter|bytePosition}} is the {{Parameter|memoryBlock}}.[[OFFSET]] start position plus any bytes needed to read specific values.  
* {{Parameter|bytePosition}} is the {{Parameter|memoryBlock}}.[[OFFSET]] start position plus any bytes needed to read specific values.
* The {{Parameter|sourceVariable}} type designates the size and {{Parameter|bytePosition}} it should be written to. It can be a variable, [[arrays|array]] or user defined type.
* The {{Parameter|sourceVariable}} type designates the size and {{Parameter|bytePosition}} it should be written to. It can be a variable, [[arrays|array]] or user defined type.
* {{Parameter|bytePosition}} can be converted [[AS]] a specific variable ''[[TYPE|type]]'' before being written to the {{Parameter|memoryBlock}} as bytes.
* {{Parameter|bytePosition}} can be converted [[AS]] a specific variable ''[[TYPE|type]]'' before being written to the {{Parameter|memoryBlock}} as bytes.
Line 17: Line 17:
* The _MEMPUT statement is similar to the [[PUT]] file statement, but {{Parameter|bytePosition}} is required.
* The _MEMPUT statement is similar to the [[PUT]] file statement, but {{Parameter|bytePosition}} is required.
* The {{Parameter|memoryBlock}}.[[OFFSET]] returns the starting byte position of the block. Add bytes to move into the block.
* The {{Parameter|memoryBlock}}.[[OFFSET]] returns the starting byte position of the block. Add bytes to move into the block.
* The variable type held in the memory block can determine the next ''byte position'' to write a value.  
* The variable type held in the memory block can determine the next ''byte position'' to write a value.
* [[LEN]] can be used to determine the byte size of numerical or user defined variable [[type]]s regardless of the value held.
* [[LEN]] can be used to determine the byte size of numerical or user defined variable [[type]]s regardless of the value held.
* [[STRING]] values should be of a defined length. Variable length strings can actually move around in memory and not be found.
* [[STRING]] values should be of a defined length. Variable length strings can actually move around in memory and not be found.
Line 24: Line 24:
{{PageDescription}}
{{PageDescription}}
''Example:'' _MEMPUT can be used just like [[POKE]] without [[DEF SEG]].
''Example:'' _MEMPUT can be used just like [[POKE]] without [[DEF SEG]].
{{CodeStart}} '' ''
{{CodeStart}}
{{Cl|DIM}} o {{Cl|AS}} {{Cl|_MEM}}
{{Cl|DIM}} o {{Cl|AS}} {{Cl|_MEM}}
o = {{Cl|_MEM (function)|_MEM}}(d&)
o = {{Cl|_MEM (function)|_MEM}}(d&)
Line 30: Line 30:
v = {{Cl|_MEMGET (function)|_MEMGET}}(o, o.OFFSET + 1, {{Cl|_UNSIGNED}} {{Cl|_BYTE}}) 'PEEK
v = {{Cl|_MEMGET (function)|_MEMGET}}(o, o.OFFSET + 1, {{Cl|_UNSIGNED}} {{Cl|_BYTE}}) 'PEEK
{{Cl|PRINT}} v 'prints 3
{{Cl|PRINT}} v 'prints 3
{{Cl|PRINT}} d& 'print 768 because the 2nd byte of d& has been set to 3 or 3 * 256 '' ''
{{Cl|PRINT}} d& 'print 768 because the 2nd byte of d& has been set to 3 or 3 * 256
{{CodeEnd}}
{{CodeEnd}}



Revision as of 02:05, 23 January 2023

The _MEMPUT statement writes data to a portion of a designated memory block at an OFFSET position.


Syntax

_MEMPUT memoryBlock, bytePosition, sourceVariable [AS type]


Template:Parameters

  • memoryBlock is a _MEM variable type memory block name created by _MEMNEW or the _MEM function.
  • bytePosition is the memoryBlock.OFFSET start position plus any bytes needed to read specific values.
  • The sourceVariable type designates the size and bytePosition it should be written to. It can be a variable, array or user defined type.
  • bytePosition can be converted AS a specific variable type before being written to the memoryBlock as bytes.


Description

  • The _MEMPUT statement is similar to the PUT file statement, but bytePosition is required.
  • The memoryBlock.OFFSET returns the starting byte position of the block. Add bytes to move into the block.
  • The variable type held in the memory block can determine the next byte position to write a value.
  • LEN can be used to determine the byte size of numerical or user defined variable types regardless of the value held.
  • STRING values should be of a defined length. Variable length strings can actually move around in memory and not be found.


Description

Example: _MEMPUT can be used just like POKE without DEF SEG.

DIM o AS _MEM
o = _MEM(d&)
_MEMPUT o, o.OFFSET + 1, 3 AS _UNSIGNED _BYTE  'POKE
v = _MEMGET(o, o.OFFSET + 1, _UNSIGNED _BYTE) 'PEEK
PRINT v 'prints 3
PRINT d& 'print 768 because the 2nd byte of d& has been set to 3 or 3 * 256


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link