Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 117333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:19:10+00:00 2026-05-11T03:19:10+00:00

I’ve read the article on Wikipedia on the Duff’s device , and I don’t

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T03:19:11+00:00Added an answer on May 11, 2026 at 3:19 am

    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:

    int count;                        // Set to 20 {     int n = (count + 7) / 8;      // n is now 3.  (The 'while' is going                                   //              to be run three times.)      switch (count % 8) {          // The remainder is 4 (20 modulo 8) so                                   // jump to the case 4      case 0:                       // [skipped]              do {                 // [skipped]                  *to = *from++;   // [skipped]     case 7:      *to = *from++;   // [skipped]     case 6:      *to = *from++;   // [skipped]     case 5:      *to = *from++;   // [skipped]     case 4:      *to = *from++;   // Start here.  Copy 1 byte  (total 1)     case 3:      *to = *from++;   // Copy 1 byte (total 2)     case 2:      *to = *from++;   // Copy 1 byte (total 3)     case 1:      *to = *from++;   // Copy 1 byte (total 4)            } while (--n > 0);     // N = 3 Reduce N by 1, then jump up                                   //       to the 'do' if it's still     }                             //        greater than 0 (and it is) } 

    Now, start the second pass, we run just the indicated code:

    int count;                        // {     int n = (count + 7) / 8;      //                                   //      switch (count % 8) {          //                                   //      case 0:                       //              do {                 // The while jumps to here.                  *to = *from++;   // Copy 1 byte (total 5)     case 7:      *to = *from++;   // Copy 1 byte (total 6)     case 6:      *to = *from++;   // Copy 1 byte (total 7)     case 5:      *to = *from++;   // Copy 1 byte (total 8)     case 4:      *to = *from++;   // Copy 1 byte (total 9)     case 3:      *to = *from++;   // Copy 1 byte (total 10)     case 2:      *to = *from++;   // Copy 1 byte (total 11)     case 1:      *to = *from++;   // Copy 1 byte (total 12)            } while (--n > 0);     // N = 2 Reduce N by 1, then jump up                                   //       to the 'do' if it's still     }                             //       greater than 0 (and it is) } 

    Now, start the third pass:

    int count;                        // {     int n = (count + 7) / 8;      //                                   //      switch (count % 8) {          //                                   //      case 0:                       //              do {                 // The while jumps to here.                  *to = *from++;   // Copy 1 byte (total 13)     case 7:      *to = *from++;   // Copy 1 byte (total 14)     case 6:      *to = *from++;   // Copy 1 byte (total 15)     case 5:      *to = *from++;   // Copy 1 byte (total 16)     case 4:      *to = *from++;   // Copy 1 byte (total 17)     case 3:      *to = *from++;   // Copy 1 byte (total 18)     case 2:      *to = *from++;   // Copy 1 byte (total 19)     case 1:      *to = *from++;   // Copy 1 byte (total 20)            } while (--n > 0);     // N = 1  Reduce N by 1, then jump up                                   //       to the 'do' if it's still     }                             //       greater than 0 (and it's not, so bail) }                                 // continue here... 

    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++.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.