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

Newsgroups: comp.os.msdos.djgpp
From: Peter Berdeklis <peter AT atmosp DOT physics DOT utoronto DOT ca>
Subject: Re: Assembler question
Message-ID: <Pine.SGI.3.91.971008094703.9747C-100000@atmosp.physics.utoronto.ca>
NNTP-Posting-Host: chinook.physics.utoronto.ca
Sender: news AT info DOT physics DOT utoronto DOT ca (System Administrator)
Mime-Version: 1.0
Organization: University of Toronto - Dept. of Physics
In-Reply-To: <199710070150.SAA24301@adit.ap.net>
Date: Wed, 8 Oct 1997 13:55:17 GMT
References: <199710070150 DOT SAA24301 AT adit DOT ap DOT net>
Lines: 20
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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.)

---------------
Peter Berdeklis
Dept. of Physics, Univ. of Toronto

- Raw text -


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