I've read the article on Wikipedia on the Duff's device, and I don't get it. I am really interested, but I've read the explanation there a couple of times and I still don't get it how the Duff's device works.
What would a more detailed explanation be?
There are some good explanations elsewhere, but let me give it a try. (This is a lot easier on a whiteboard!) Here's the Wikipedia example with some notations.
Let's say you're copying 20 bytes. The flow control of the program for the first pass is:
Now, start the second pass, we run just the indicated code:
Now, start the third pass:
20 bytes are now copied.
Note: The original Duff's Device (shown above) copied to an I/O device at the
to
address. Thus, it wasn't necessary to increment the pointer*to
. When copying between two memory buffers you'd need to use*to++
.