delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/10/09/20:06:08

Date: Thu, 9 Oct 1997 17:04:22 -0700 (PDT)
Message-Id: <199710100004.RAA14936@adit.ap.net>
Mime-Version: 1.0
To: Peter Berdeklis <peter AT atmosp DOT physics DOT utoronto DOT ca>, djgpp AT delorie DOT com
From: Nate Eldredge <eldredge AT ap DOT net>
Subject: Re: Assembler question

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



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019