Date: Thu, 9 Oct 1997 17:04:22 -0700 (PDT) Message-Id: <199710100004.RAA14936@adit.ap.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" To: Peter Berdeklis , djgpp AT delorie DOT com From: Nate Eldredge Subject: Re: Assembler question Precedence: bulk At 01:55 10/8/1997 GMT, Peter Berdeklis wrote: >On Tue, 7 Oct 1997, Nate Eldredge wrote: > >> At 03:03 10/6/1997 GMT, Marsel wrote: >> >Hi, >> > Can I get the address of the program counter in a C program ? >> I don't think there's a good way to do it directly from C, but you can do it >> with external assembler, I.E. NASM. > >Easy to do with inline assembler: > > int pc; > > asm( "movl %%eip, %0"; "=q" (pc) ); > >(Untested, but I don't think that it violates any protection.) The problem is deeper than any protection. You cannot use the eip register explicitly with any 386 instruction such as MOV. The only way to modify it is with JMP or CALL, and the only way to look at it is to issue a CALL and see what value was pushed on the stack (my approach). Nate Eldredge eldredge AT ap DOT net