delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/03/03/16:35:36

Sender: nate AT cartsys DOT com
Message-ID: <36DDAAA8.C46888A4@cartsys.com>
Date: Wed, 03 Mar 1999 13:33:28 -0800
From: Nate Eldredge <nate AT cartsys DOT com>
X-Mailer: Mozilla 4.08 [en] (X11; I; Linux 2.2.1 i586)
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: Re: Generating Machine Code on the fly
References: <7b6qpv$39t$1 AT news8 DOT svr DOT pol DOT co DOT uk>
<199902261912 DOT OAA24117 AT envy DOT delorie DOT com>
<7b7gra$5nh$1 AT news4 DOT svr DOT pol DOT co DOT uk>
<199902270142 DOT UAA26915 AT envy DOT delorie DOT com>
<7b80qg$qm3$1 AT news8 DOT svr DOT pol DOT co DOT uk>
<36d80527 DOT 13423287 AT 158 DOT 152 DOT 254 DOT 68>
<7b9el1$mi9$1 AT news7 DOT svr DOT pol DOT co DOT uk>
<7b9vu9$1fp$1 AT news6 DOT svr DOT pol DOT co DOT uk> <3 DOT 0 DOT 6 DOT 32 DOT 19990303121608 DOT 0092fc00 AT pop DOT globalserve DOT net> <36DD7DAD DOT 3FDDFA96 AT unb DOT ca>
Reply-To: djgpp AT delorie DOT com

Endlisnis wrote:
> 
> Paul Derbyshire wrote:
> 
> > >char *codehere;     /*void*, char* or what*/
> > >codehere=(char *)malloc(100);    /* 100 bytes of code memory */
> > >codehere[0]=0xc3;    /*just perform a ret operation for now*/
> > >asm(
> > >    "call %%ebx"    /* no comma after this */
> > >    : /*no ouputs*/
> > >    : b (codehere)   );
> >
> > Why %ebx? Why not let the compiler choose?
> 
>     No real reason, actually I can't remember how to do that, and I didn't feel
> like looking it up.

asm("call %0" : : "r" (codehere));

And if it follows C calling conventions, which might not be a bad idea,
you can just do:

((void (*)(void))codehere)();

replacing types as appropriate.
-- 

Nate Eldredge
nate AT cartsys DOT com

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019