indirect jmp

G

ganeshb

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
 
W

Walter Roberson

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".
 
K

Keith Thompson

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?
 
S

SM Ryan

(e-mail address removed) 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.
 
G

ganeshb

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

Flash Gordon

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

ganeshb

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
 
F

Flash Gordon

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

Walter Roberson

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

Kenneth Brody

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:[email protected]>
 
R

Richard Tobin

Kenneth Brody said:
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
 
N

N. Shamsundar

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;
}
 
D

Dave Thompson

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top