By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,812 Members | 875 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,812 IT Pros & Developers. It's quick & easy.

indirect jmp

P: n/a
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

Nov 15 '05 #1
Share this Question
Share on Google+
13 Replies


P: n/a
In article <11**********************@g14g2000cwa.googlegroups .com>,
<ga*****@gmail.com> 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!
Nov 15 '05 #2

P: n/a
ga*****@gmail.com 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) ks***@mib.org <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.
Nov 15 '05 #3

P: n/a
ga*****@gmail.com 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.
Nov 15 '05 #4

P: n/a
I am not trying to solve any problem. I am just wondering why indirect
jmp is kept in an instruction set.

Nov 15 '05 #5

P: n/a
ga*****@gmail.com 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.
Nov 15 '05 #6

P: n/a
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

Nov 15 '05 #7

P: n/a
In article <11**********************@g14g2000cwa.googlegroups .com>,
<ga*****@gmail.com> 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.
Nov 15 '05 #8

P: n/a
ga*****@gmail.com 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.
Nov 15 '05 #9

P: n/a
ga*****@gmail.com 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:Th*************@gmail.com>

Nov 15 '05 #10

P: n/a
In article <43***************@spamcop.net>,
Kenneth Brody <ke******@spamcop.net> 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
Nov 15 '05 #11

P: n/a
ri*****@cogsci.ed.ac.uk (Richard Tobin) writes:
In article <43***************@spamcop.net>,
Kenneth Brody <ke******@spamcop.net> 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) ks***@mib.org <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.
Nov 15 '05 #12

P: n/a
ga*****@gmail.com 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;
}
Nov 15 '05 #13

P: n/a
On Mon, 10 Oct 2005 18:35:45 +0000 (UTC), ro******@ibd.nrc-cnrc.gc.ca
(Walter Roberson) wrote:
In article <11**********************@g14g2000cwa.googlegroups .com>,
<ga*****@gmail.com> 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
Nov 15 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.