cancel
Showing results for 
Search instead for 
Did you mean: 

[STM8] When use memcpy() will copy the contents to the wrong address

Jeffy Zhou
Associate II
Posted on September 08, 2017 at 10:55

When the destination memory block is locate in zero page which the address is often rang from 0x0 to 0xff. For instance, if a destination memory start address is 0x0, the memory() will copy the contents to address from 0x100. The memory() disassembly instructions like:

      LDW X, &sharpLength

loop: LD  A, (scr + X)

      LD (dst + X), A

      DECW X

      JRNE loop

      RET

The value of 'scr' and 'dst' is the address before 1 of start address of memory block. e.g. If the start address of 'destination parameter' of memcpy() is 0x80, then the 'dst' should be 0x7f, and if the start address of it is 0x0, the 'dst' will be 0xff, then the contents will copy to the memory from 0x100.

I thinks this should be a compiler issue. 

#stm8-assembly #memcpy
3 REPLIES 3
luca239955_stm1_st
Senior II
Posted on September 08, 2017 at 17:06

Hello,

what compiler?

Please post a minimum C code that shows the problem so that we can reproduce it.

Regards,

Luca

Posted on September 11, 2017 at 06:10

Hi Luca,

Attached stvd demo project, and a capture image descripts the result of running in my environment.

Environment:

Win10

STVD: version 4.3.10

Cosmic: CxSTM8 4.3.5

Posted on September 11, 2017 at 16:40

Hello,

the address 0 is used by the compiler to indicate the NULL pointer value, and that implies that there are a few things you cannot do with it, including using memcpy.

I would suggest to declare another variable before your array, so that it does not start at 0 anymore and you can access it safely in whatever way you want, but if you absolutely need to use memcpy at address 0 you can write your own version of it and use it instead of the default one.

Regards,

Luca (Cosmic)