bytefill and bytemove
nicolad76
Posts: 164
Hi,
readingfrom Prop Manual:
[...]
Using BYTEFILL
BYTEFILL is a great way to clear large blocks of byte-sized memory. For example:
VAR
byte Buff[100]
PUB Main
bytefill(@Buff, 0, 100) 'Clear Buff to 0
[...]
and
[...]
BYTEMOVE is a great way to copy large blocks of byte-sized memory. For example:
VAR
byte Buff1[100]
byte Buff2[100]
PUB Main
bytemove(@Buff2, @Buff1, 100) 'Copy Buff1 to Buff2
[...]
So, in order to extract a substring I wrote the following code:
output is
COMMAND 1: 1234567890
COMMAND 2: 1234567890
CMD: 1234567890
if i try (bcs I was desperate and I tried all permutations....)
the output will be:
COMMAND 1: 1234567890
COMMAND 2: 123
CMD: 123
which looks fine but the original value of the variable "command" seems to be corrupted.
Why all this happens?
Thanks
Nicola
readingfrom Prop Manual:
[...]
Using BYTEFILL
BYTEFILL is a great way to clear large blocks of byte-sized memory. For example:
VAR
byte Buff[100]
PUB Main
bytefill(@Buff, 0, 100) 'Clear Buff to 0
[...]
and
[...]
BYTEMOVE is a great way to copy large blocks of byte-sized memory. For example:
VAR
byte Buff1[100]
byte Buff2[100]
PUB Main
bytemove(@Buff2, @Buff1, 100) 'Copy Buff1 to Buff2
[...]
So, in order to extract a substring I wrote the following code:
var byte command[56] byte cmd[4] byte params[51] PUB Main pst.Start(115_200) repeat pst.StrIn(command) pst.Str(String(pst#NL, pst#NL, "COMMAND 1: ")) pst.Str(command) bytemove(@cmd,@command,3) ' copy 3 bytes from command to cmd bytefill(@cmd+3,0,1) ' add zero-termination string pst.Str(String(pst#NL, pst#NL, "COMMAND 2: ")) pst.Str(command) pst.Str(String(pst#NL, pst#NL, "CMD: ")) pst.Str(cmd)
output is
COMMAND 1: 1234567890
COMMAND 2: 1234567890
CMD: 1234567890
if i try (bcs I was desperate and I tried all permutations....)
bytemove(cmd,command,3) ' copy 3 bytes from command to cmd bytefill(cmd+3,0,1) ' add zero-termination string
the output will be:
COMMAND 1: 1234567890
COMMAND 2: 123
CMD: 123
which looks fine but the original value of the variable "command" seems to be corrupted.
Why all this happens?
Thanks
Nicola
Comments
thanks, it worked!!!!
Nicola