This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

instruction-space modification


Greeting,
I was wondering if you could help me with a problem. I can't seem to find an
answer anywhere.
When I try to alter data in instruction space in a c-programme, like:
call 0
pop bx
mov byte ptr [bx+7], 3
shl ax, 2

I get a "segmentation fault" because of the third instruction.
Could you tell me how to avoid this, or where I could find literature that
explains these kinds of questions.
I'm trying to do this, because "shl ax, cl" is not pairable and much slower
than a shift with an immediate constant second operand.

My test-programme looked like this:
int main() {
   int a = 1;

   asm(".byte 0xE8, 0x00, 0x00, 0x00, 0x00, 0x5B, 0xC6, 0x43;"
	".byte 0x07, 0x03, 0xC1, 0xE0, 0x02;"
	: "=a"(a)
	: "a"(a)
	: "%ebx", "%ecx", "%edx", "%esi", "%edi");

printf("%d\n",a); // Should produce "8"

   return 0;
} // int main() endp

Kind regards,
Gerard Visser


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]