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 2017980
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T09:02:11+00:00 2026-05-17T09:02:11+00:00

I am trying to understand the practical difference during the execution of a program

  • 0

I am trying to understand the practical difference during the execution of a program in Decode and dispatch interpretation and Threaded interpretation.

Example of both will really help.

I understand how Java bytecode works and how an assembly language works. But where does DDI and TI fit in?

Context: Virtual machines: versatile platforms for systems and processes

  • 1 1 Answer
  • 6 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. Editorial Team
    Editorial Team
    2026-05-17T09:02:21+00:00Added an answer on May 17, 2026 at 9:02 am

    (Note: I’ll assume that by “decode and dispatch” you mean a switch-based interpreter.)

    The difference between a switch-based and a threaded interpreter at run time is, basically, the number of jumps that are performed.

    In a switch-based interpreter, instructions are decoded at some central location, and based on the result of the decoding, a jump is performed to the piece of code that handles the decoded instruction. Once that piece of code has finished interpreting the instruction, it jumps back to the centralized decoding code, which proceeds with the next instruction. This means that (at least) two jumps are performed per interpreted instruction. The following piece of C code illustrates what such an interpreter might look like:

    typedef enum {
      add, /* ... */
    } instruction_t;
    
    void interpret() {
      static instruction_t program[] = { add /* ... */ };
      instruction_t* pc = program;
      int* sp = ...; /* stack pointer */
      for (;;) {
        switch (*pc++) {
          case add:
            sp[1] += sp[0];
            sp++;
            break;
            /* ... other instructions */
        }
      }
    }
    

    In a threaded interpreter, the decoding code is not centralized, but rather duplicated at the end of each piece of code that handles an instruction. This means that once an instruction has been interpreted, instead of jumping back to some centralized decoding code, the interpreter decodes the next instruction and immediately jumps to it. Implementing threaded code efficiently in ANSI-C is not really possible, but GCC’s “computed goto” extension works very well for that. Here is a threaded version of the previous interpreter:

    void interpret() {
      void* program[] = { &&l_add, /* ... */ };
      int* sp = ...;
      void** pc = program;
      goto **pc; /* jump to first instruction */
     l_add:
      sp[1] += sp[0];
      ++sp;
      goto **(++pc); /* jump to next instruction */
      /* ... other instructions */
    }
    

    Apart from saving a jump, such threaded interpreters are also more efficient because the replicated indirect jump (to the next instruction) can be predicted better by modern CPUs. Anton Ertl has some interesting papers on his home page, especially the one called “The Structure and Performance of Efficient Interpreters”, from which the above pieces of code were adapted.

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

Sidebar

Related Questions

I trying to understand if a isset is required during form processing when i
I'm trying to understand the difference between Ruby threads pre-1.9 and 1.9 (in the
I'm trying to understand the basics of practical programming around character encodings. A few
I am trying understand ViewModels deeper and I have read many articles and blogs
Trying to understand what's the correct way of implementing OpenID authentication with Spring Security.
Trying to understand the Deezer API. When I visit: http://connect.deezer.com/oauth/auth.php?app_id=MY_APP_ID&redirect_uri=http://mydomain.me&perms=basic_access I end up at
Trying to understand PNG format. Consider this PNG Image: The Image is taken from
Trying to understand the options for will_paginate's paginate method: :page — REQUIRED, but defaults
Trying to understand Ruby a bit better, I ran into this code surfing the
Trying to understand something. I created a d:\svn\repository on my server. I committed folders

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.