indirect jmp

Discussion in 'C Programming' started by ganeshb@gmail.com, Oct 10, 2005.

  1. Guest

    Hi,

    What C statement(s) would translate to indirect jmp in assembly? I know
    that function pointer invocation would translate to indirect 'call'
    instruction, but I am not sure what will lead to indirect jmp (eg. jmp
    <register>).

    Ganesh
     
    , Oct 10, 2005
    #1
    1. Advertising

  2. In article <>,
    <> wrote:

    >What C statement(s) would translate to indirect jmp in assembly? I know
    >that function pointer invocation would translate to indirect 'call'
    >instruction, but I am not sure what will lead to indirect jmp (eg. jmp
    ><register>).


    longjump() would be the closest. Not that it's particularily close,
    but it's all that there is.

    In particular, you cannot take the address of a label or of
    a statement block or of any executable element other than a routine,
    and (as you note) there is no goto a routine.

    Depending on what you are trying to do, you might want to look
    into techniques that people have developed for emulating
    "co-routines".
    --
    Watch for our new, improved .signatures -- Wittier! Profounder! and
    with less than 2 grams of Trite!
     
    Walter Roberson, Oct 10, 2005
    #2
    1. Advertising

  3. writes:
    > What C statement(s) would translate to indirect jmp in assembly? I know
    > that function pointer invocation would translate to indirect 'call'
    > instruction, but I am not sure what will lead to indirect jmp (eg. jmp
    > <register>).


    There is no direct equivalent. A switch statement comes close.

    What are you trying to do? An indirect jump is a technique, not a
    problem; what problem are you trying to solve?

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Oct 10, 2005
    #3
  4. SM Ryan Guest

    wrote:
    # Hi,
    #
    # What C statement(s) would translate to indirect jmp in assembly? I know
    # that function pointer invocation would translate to indirect 'call'
    # instruction, but I am not sure what will lead to indirect jmp (eg. jmp
    # <register>).

    No direct equivalent in ANSI C. gcc has label variables.


    --
    SM Ryan http://www.rawbw.com/~wyrmwif/
    So basically, you just trace.
     
    SM Ryan, Oct 10, 2005
    #4
  5. Guest

    I am not trying to solve any problem. I am just wondering why indirect
    jmp is kept in an instruction set.
     
    , Oct 10, 2005
    #5
  6. Flash Gordon Guest

    wrote:
    > I am not trying to solve any problem. I am just wondering why indirect
    > jmp is kept in an instruction set.


    This group is nothing to do with the whats and whys of processor
    instruction sets, only to do with the C language. So, as far as I can
    see, any such wondering is not relevant here.
    --
    Flash Gordon
    Living in interesting times.
    Although my email address says spam, it is real and I read it.
     
    Flash Gordon, Oct 10, 2005
    #6
  7. Guest

    I will re-state my problem. Name a C statement(s) that would certainly
    make any compiler to generate indirect jmp instruction? (BTW, I am yet
    to look into the co-routine suggestion given by one of the posters).

    Ganesh
     
    , Oct 10, 2005
    #7
  8. Flash Gordon Guest

    wrote:
    > I will re-state my problem. Name a C statement(s) that would certainly
    > make any compiler to generate indirect jmp instruction?


    None. For a start, there is nothing to say C cannot be implemented on a
    processor which does not support indirect jumps. The same answer applies
    to any other instruction.

    We do not deal with system specifics here.

    > (BTW, I am yet
    > to look into the co-routine suggestion given by one of the posters).


    They are also off topic here since they are not part of standard C.
    --
    Flash Gordon
    Living in interesting times.
    Although my email address says spam, it is real and I read it.
     
    Flash Gordon, Oct 10, 2005
    #8
  9. In article <>,
    <> wrote:
    >I will re-state my problem. Name a C statement(s) that would certainly
    >make any compiler to generate indirect jmp instruction?


    There is no such statement. C may be implimented on machines whose
    processor lacks indirect branches.

    On some architectures, with some compilers, with some code patterns,
    C compilers have been known to generate indirect branches for some switch
    statements.

    >(BTW, I am yet
    >to look into the co-routine suggestion given by one of the posters).


    That was me, and my suggestion to look at co-routines was in
    the opposite direction completely: it was a suggestion to look
    at a particular field of programming in which people have worked
    on techniques to get around the *lack* of an indirect branch.
    That is, if you had a particular problem in which you were thinking,
    "Gee, I'm not sure how to solve this without using an indirect
    branch", then you could look at successful co-routine implementations
    to see how they got around the lack of an indirect branch.
    --
    University of Calgary researcher Christopher Auld has found that
    milk is the most "rational addiction" amongst the several studied.
     
    Walter Roberson, Oct 10, 2005
    #9
  10. wrote:
    >
    > I am not trying to solve any problem. I am just wondering why indirect
    > jmp is kept in an instruction set.


    Umm... Because they're useful?

    Even if no C compiler in the world ever used an indirect jump, they would
    still be useful to people who program in something other than C.

    If you're looking for a C construct which _might_ generate an indirect
    jump on a system which has such an instruction, look at switch/case.

    And finally, read some of the multitude of posts on this list which show
    how to properly use Google's broken interface to reply.

    --
    +-------------------------+--------------------+-----------------------------+
    | Kenneth J. Brody | www.hvcomputer.com | |
    | kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
    +-------------------------+--------------------+-----------------------------+
    Don't e-mail me at: <mailto:>
     
    Kenneth Brody, Oct 10, 2005
    #10
  11. In article <>,
    Kenneth Brody <> wrote:

    >If you're looking for a C construct which _might_ generate an indirect
    >jump on a system which has such an instruction, look at switch/case.


    Also, consider that C *does* have something corresponding to an
    indirect subroutine call.

    -- Richard
     
    Richard Tobin, Oct 10, 2005
    #11
  12. (Richard Tobin) writes:
    > In article <>,
    > Kenneth Brody <> wrote:
    >
    >>If you're looking for a C construct which _might_ generate an indirect
    >>jump on a system which has such an instruction, look at switch/case.

    >
    > Also, consider that C *does* have something corresponding to an
    > indirect subroutine call.


    Which the OP mentioned in his original article.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Oct 10, 2005
    #12
  13. wrote:
    > Hi,
    >
    > What C statement(s) would translate to indirect jmp in assembly? I know
    > that function pointer invocation would translate to indirect 'call'
    > instruction, but I am not sure what will lead to indirect jmp (eg. jmp
    > <register>).
    >
    > Ganesh
    >

    Here is an example where an indirect call is produced, although there is
    no requirement or justified expectation that anything in C translate to
    anything in assembly.

    We have a program to calculate the thermodynamic properties of 45
    substances. One routine, which calculates enthalpy (h) from internal
    energy (u), pressure (p) and specific volume (v), performs a
    substance-independent calculation, but has to call one of the 45
    substance-specific routines to compute some terms in the calculation.

    Rather than using a long chain of "if" .. "else if" ... or "switch"
    statements, we store pointers to the functions in an array, and call the
    proper member of the array, the selection being made at run time based
    on the value of the integer "subst".

    On an X86 machine, gcc compiles the call to the indirect call instruction

    call *_pvtptr-4(,%eax,4)

    If you are willing to admit a "call" instruction as equivalent to a jump
    with some additional bookkeeping for the return link and stack
    adjustment, this is one example.

    N. Shamsundar
    University of Houston
    ________________________________________
    typedef void (*pvtpointer)(double, double *,double, double *,double *);
    pvtpointer pvtptr[]={
    pvtnh3,pvtco2,pvtc7h16,pvtc6h14,pvc5h12i,
    <-- dozens more such function names cut out -->
    pvtisb87,pvtbut87,pvtiaps};

    void pvt(double T,double *p,double v,double *u,double *h,double *s,int
    subst)
    {pvtptr[subst-1](T,p,v,u,s); *h=(*u)+(*p)*v;
    }
     
    N. Shamsundar, Oct 14, 2005
    #13
  14. On Mon, 10 Oct 2005 18:35:45 +0000 (UTC), -cnrc.gc.ca
    (Walter Roberson) wrote:

    > In article <>,
    > <> wrote:
    > >I will re-state my problem. Name a C statement(s) that would certainly
    > >make any compiler to generate indirect jmp instruction?

    >
    > There is no such statement. C may be implimented on machines whose
    > processor lacks indirect branches.
    >

    That's certainly true.

    > On some architectures, with some compilers, with some code patterns,
    > C compilers have been known to generate indirect branches for some switch
    > statements.
    >

    (Also) On some architectures, possibly in all possibly in only some
    cases, function return can be implemented using indirect jump.


    - David.Thompson1 at worldnet.att.net
     
    Dave Thompson, Oct 17, 2005
    #14
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. George Ter-Saakov

    Indirect use of COM

    George Ter-Saakov, Aug 26, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    363
    Natty Gur
    Aug 27, 2003
  2. plaztik via DotNetMonster.com

    Enterprise Library - Indirect/Inherited Configuration??

    plaztik via DotNetMonster.com, May 6, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    527
    Scott Allen
    May 6, 2005
  3. xarax
    Replies:
    7
    Views:
    7,045
    Robert Olofsson
    Aug 13, 2003
  4. Yu Lianqing
    Replies:
    1
    Views:
    393
    John Harrison
    Jul 31, 2003
  5. Steven T. Hatton

    Indirect recursion and templates?

    Steven T. Hatton, Apr 22, 2004, in forum: C++
    Replies:
    2
    Views:
    451
    Steven T. Hatton
    Apr 22, 2004
Loading...

Share This Page