Mail Archives: djgpp/2000/04/13/22:46:22
Hello, I got the following code to work (new to AT&T ASM, somewhat familiar
with Intel):
#include <stdio.h>
#include <conio.h>
int main(void)
{
int x, y = 32;
x = 0;
x++;
printf("%i\n", x);
// Form __asm__ __volatile__ ("Code" : outputs : inputs :
registers-modified);
// Allowed to destroy eax, ecx, edx, fs, gs, and eflags (although
pushing/popping them
// is a whole lot safer
__asm__ __volatile__("
push %%eax
movl %0, %%eax
rol $32, %%eax
movl %%eax, %0
pop %%eax"
:
: "g" (x), "g" (y)
: "ax", "cx", "memory"
);
printf("%i\n", x);
}
Basically, the ASM code does nothing, but I want to be able to self-modify
the code during run-time and replace the number $32 with the value in y.
The assembler complains whenever I try replacing the $32 with a variable
and I think that the only way that I am going to get that number to change
is to self-modify. If someone knows of a better solution, let me know.
Otherwise, how do I self-modify ASM code in 32-bit PM (if such a thing is
even allowed).
Thanks in advance!
Thomas J. Hruska -- shinelight AT crosswinds DOT net
Shining Light Productions -- "Meeting the needs of fellow programmers"
http://www.shininglightpro.com/
- Raw text -