Mail Archives: djgpp/1996/12/13/02:52:29
In article <32A97083 DOT 68A7 AT stud DOT warande DOT ruu DOT nl>,
Elliott Oti <e DOT oti AT stud DOT warande DOT ruu DOT nl> 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.
<a href="http://www.cs.indiana.edu/finger/mofo.ssl.berkeley.edu/korpela/w">
Click here for more info.</a>
- Raw text -