![]() |
Forum Index : Microcontroller and PC projects : CMM2 (& PicoMite ?): MEMORY COPY and overlapping regions
Author | Message | ||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
Peter, What is the expected behaviour of MEMORY COPY (which is still not in the manual) for overlapping source and destination, or is it simply undefined as it is for the C memcpy() function ? Best wishes, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10310 |
Same |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
Hi Peter, FYI according to the limited unit-test coverage I have written, MEMORY COPY on the CMM2 works correctly for overlapping regions where the destination address is less than the source address, but not where the destination address is greater in which case data already copied gets duplicated. MMB4L alpha 3 will handle it "correctly", or at least according to the semantics of C's standard memmove(). If you were so inclined it should (microcontroller memory weirdness aside) be possible to do it "correctly" on the CMM2 too by comparing psrc and pdst and if pdst > psrc then copy the data in reverse order, i.e. from highest address to lowest address. Best wishes, Tom Edited 2022-01-04 08:18 by thwill MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7937 |
On the ancient Nascom we had an intelligent memory copy - same thing really! It subtracted the source & destination values to decide whether to start the copy at the beginning or end. That way you could safely copy a block over itself to move it. The Z80 was pretty good at shifting memory around. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |