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