From: korpela AT albert DOT ssl DOT berkeley DOT edu (Eric J. Korpela) Newsgroups: comp.os.msdos.djgpp Subject: Re: Q: Asm: self-modifying code Date: 10 Dec 1996 07:06:37 GMT Organization: Cal Berkeley-- Space Sciences Lab Lines: 43 Message-ID: <58j25t$hde@agate.berkeley.edu> References: <32A97083 DOT 68A7 AT stud DOT warande DOT ruu DOT nl> NNTP-Posting-Host: albert.ssl.berkeley.edu To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp In article <32A97083 DOT 68A7 AT stud DOT warande DOT ruu DOT nl>, Elliott Oti wrote: > >how does one change (for instance) > > mov [DWORD PTR @@label + 2], 6h > @@label: > add %eax, 5h > >to ATT syntax? ( Above code fragment changes the 5h to a 6h ). First thing I always like to say is don't write self modifying code if you can help it. Second, if you have to, the first thing to do is to make sure that your data segment is a writable alias for your code segment. Third, make sure your code cache and prefetch get dumped when you modify code. (The above probably won't work as written.) That said, if you really need to do it I would define symbols for the code location that is being modified. It has the added bonus of letting you see what locations are being modified in the symbol table. The above would translate as.... .def _add_imm /* create a symbol called _add_imm */ movl $6,_add_imm /* change the value stored there */ _add_imm=.+2 /* define _add_imm as the current location+2 */ addl $5,%eax /* the modified instruction */ Now after all that work we ask why we did that when the following isn't self modifying and runs faster. .data _add_imm: .long 5 .text movl $6,_add_imm addl _add_imm,%eax Eric -- Eric Korpela | An object at rest can never be korpela AT ssl DOT berkeley DOT edu | stopped. Click here for more info.