MEMCOPY

Top  Previous  Next

Action

Copies a block of memory

 

 

Syntax

bts = MEMCOPY(source, target , bytes[ , option])

 

 

Remarks

bts

The total number of bytes copied. This must be a word or integer

source

The first address of the source variable that will be copied.

target

The first address of the target variable that will be copied to.

bytes

The number of bytes to copy from "source" to "target"

option

An optional numeric constant with one of the following values :

1 - only the source address will be increased after each copied byte

2 - only the target address will be increased after each copied byte

3 - both the source and target address will be copied after each copied byte

 

By default, option 3 is used as this will copy a block of memory from one memory location to another location. But it also possible to fill an entire array of memory block with the value of 1 memory location. For example to clear a whole block or preset it with a value.

And with option 2, you can for example get a number of samples from a register like PINB and store it into an array.

 

See also

NONE

 

 

ASM

NONE

 

 

Example

'-----------------------------------------------------------------------

'name                     : MEMCOPY.BAS

'copyright                : (c) 1995-2006, MCS Electronics

'purpose                  : show memory copy function

'suited for demo          : yes

'commercial addon needed  : no

'use in simulator         : possible

'----------------------------------------------------------------------

$regfile = "m88def.dat"                                   ' specify the used micro

$crystal = 8000000                                         ' used crystal frequency

$baud = 19200                                               ' use baud rate

$hwstack = 32                                               ' default use 32 for the hardware stack

$swstack = 16                                               ' default use 10 for the SW stack

$framesize = 40

 

Dim Ars(10) As Byte                                       'source bytes

Dim Art(10) As Byte                                       'target bytes

Dim J As Byte                                             'index

For J = 1 To 10                                             'fill array

Ars(j) = J

Next

 

J = Memcopy(ars(1) , Art(1) , 4)                           'copy 4 bytes

 

Print J ; " bytes copied"

For J = 1 To 10

Print Art(j)

Next

 

J = Memcopy(ars(1) , Art(1) , 10 , 2)                     'assign them all with element 1

 

Print J ; " bytes copied"

For J = 1 To 10

Print Art(j)

Next

 

 

Dim W As Word , L As Long

W = 65511

J = Memcopy(w , L , 2)                                     'copy 2 bytes from word to long

End