From: Endlisnis Newsgroups: comp.os.msdos.djgpp Subject: Re: Generating Machine Code on the fly Date: Sun, 28 Feb 1999 13:29:41 -0400 Organization: BrunNet Lines: 42 Message-ID: <36D97D05.C4440EED@unb.ca> 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> NNTP-Posting-Host: ftnts1c23.brunnet.net Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.04 [en] (Win95; U) To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Andrew Davidson wrote: > Can anyone provide me with the inline assembler code to call the code in a > given address in memory. It should go something like this I think: > > 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 %codehere", /* don't know if this is right */ > : /*no ouputs*/ > : (codehere) > : "%eax", "%ebx", "%ecx","%edx", > "%esi","%edi" /*anything else?*/ > ); > > This seems very,very wrong. I know absolutely nothing about using the gcc > asm function so if you could explain this clearly in words of less than two > sylables that would help ;) You can't access a local variable through "%codehere". You will have to put it as one of your inputs. And you don't destroy the value in any registers, so you don't need to list them. [in this example]. I haven't done this in a while so, there may be something wrong, but this is what I would do: 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) ); -- (\/) Endlisnis (\/) s257m AT unb DOT ca Endlisnis AT GeoCities DOT com Endlisnis AT BrunNet DOT Net Endlisnis AT HotMail DOT com