Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Acessing registers with C

Reply
Thread Tools

Acessing registers with C

 
 
jeff
Guest
Posts: n/a
 
      02-13-2004
Hiya,

I would like to be able to read the values in the registers of the x86
type processor, using C.

I could do this in ASM but I really want to use C for my project, I
havent done anything like this in C before and would be interested to
learn how to.

Although the operating system doesnt really relate to pure C, and I
doubt there will be any difference between *nix and windows products,
I think i should make it clear that I would like to find out the space
that is being used by a certain program, in both *nix and windows. I
no that this is the CX register just not sure how to apply it to a
certain program.

Thanks

Greg
 
Reply With Quote
 
 
 
 
Richard Bos
Guest
Posts: n/a
 
      02-13-2004
http://www.velocityreviews.com/forums/(E-Mail Removed) (jeff) wrote:

> I would like to be able to read the values in the registers of the x86
> type processor, using C.


Not possible in a language that was designed to be portable to other
processors than a single one which didn't even exist when the language
was born.
It may be possible to do this using an extension to the language
provided by your compiler, but this would be off-topic in comp.lang.c,
which deals with the language itself and not with the various mutually
incompatible add-ons. Then again, it may not be possible at all using
your compiler.
You should ask this question in a specialised newsgroup, one that deals
with your implementation.

> Although the operating system doesnt really relate to pure C, and I
> doubt there will be any difference between *nix and windows products,


I wouldn't be so sure.

Richard
 
Reply With Quote
 
 
 
 
Tom St Denis
Guest
Posts: n/a
 
      02-13-2004

"jeff" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> Hiya,
>
> I would like to be able to read the values in the registers of the x86
> type processor, using C.
>
> I could do this in ASM but I really want to use C for my project, I
> havent done anything like this in C before and would be interested to
> learn how to.


A good optimizing compiler won't tell you meaningful things at the source
level about what's in the registers at all times. So you're best bet is to
actually code an assembler routine.

> Although the operating system doesnt really relate to pure C, and I


How so? Most operating systems are written in C nowadays.

> doubt there will be any difference between *nix and windows products,
> I think i should make it clear that I would like to find out the space
> that is being used by a certain program, in both *nix and windows. I
> no that this is the CX register just not sure how to apply it to a
> certain program.


How to apply the CX register to your program? That doesn't make any sense
whatsoever.

Tom


 
Reply With Quote
 
Kenneth Brody
Guest
Posts: n/a
 
      02-13-2004
Tom St Denis wrote:
> "jeff" <(E-Mail Removed)> wrote in message

[...]
> > I doubt there will be any difference between *nix and windows products,


No difference between *nix and Windows???

Well, this is true as far as "pure ANSI C" is concerned, but I doubt
that "how do I access the CX register" counts as "pure ANSI C".

> > I think i should make it clear that I would like to find out the space
> > that is being used by a certain program, in both *nix and windows. I
> > no that this is the CX register just not sure how to apply it to a
> > certain program.

>
> How to apply the CX register to your program? That doesn't make any sense
> whatsoever.


I think he's referring to the fact that tiny-model MS-DOS programs
(ie: *.COM) start with the CX register containing the size of the
executable image. (At least, that's what I recall from years ago.)

Now, how this applies to *nix and Windows, let alone C in general,
I don't know. (Well, I do. The answer is "it doesn't".)

--

+---------+----------------------------------+-----------------------------+
| Kenneth | kenbrody at spamcop.net | "The opinions expressed |
| J. | http://www.hvcomputer.com | herein are not necessarily |
| Brody | http://www.fptech.com | those of fP Technologies." |
+---------+----------------------------------+-----------------------------+

 
Reply With Quote
 
jeff
Guest
Posts: n/a
 
      02-13-2004
Hiya

> How so? Most operating systems are written in C nowadays.


I was trying to Pre-empt a reponse saying that i was offtopic.

> How to apply the CX register to your program? That doesn't make any sense
> whatsoever.


If you go to command and then run debug and debug something.com (or
exe), then you can use the -r command to get the register values, the
CX value here relates to the program size. Thats what I want to get
at.

Im not sure whether its just related to C in the sense that is
newgroup use it but theres the ASM command, I could use that get the
value of CX but I wouldnt know how to then use it in the rest of the
program,

cheers

greg
 
Reply With Quote
 
Alan Balmer
Guest
Posts: n/a
 
      02-13-2004
On 13 Feb 2004 02:51:32 -0800, (E-Mail Removed) (jeff) wrote:

>Although the operating system doesnt really relate to pure C, and I
>doubt there will be any difference between *nix and windows products,
>I think i should make it clear that I would like to find out the space
>that is being used by a certain program, in both *nix and windows. I
>no that this is the CX register just not sure how to apply it to a
>certain program.


I'm curious as to how you will apply it to any program on a machine
which doesn't have a CX register.

--
Al Balmer
Balmer Consulting
(E-Mail Removed)
 
Reply With Quote
 
Alan Balmer
Guest
Posts: n/a
 
      02-13-2004
On 13 Feb 2004 10:09:18 -0800, (E-Mail Removed) (jeff) wrote:

>Hiya
>
>> How so? Most operating systems are written in C nowadays.

>
>I was trying to Pre-empt a reponse saying that i was offtopic.
>

It didn't help. You're still off-topic.

Find a newsgroup which deals with the implementation you're interested
in, whether that be Windows or *nix. Don't expect the answer to be the
same for both. Don't even expect the answer to be the same for
different *nix implementations.

--
Al Balmer
Balmer Consulting
(E-Mail Removed)
 
Reply With Quote
 
Chris Torek
Guest
Posts: n/a
 
      02-13-2004
In article <news:(E-Mail Removed). com>
jeff <(E-Mail Removed)> writes:
>I would like to be able to read the values in the [ordinary cpu]
>registers of the x86 type processor, using C.


While many or even most "real world" C compilers provide a way to
do this, there is no Standard C method. In practice, each C compiler
uses a different syntax from the next. If I gave you a gcc-specific
answer but you are using a Microsoft compiler, it would do you no
good. Thus, to get a *useful* answer, you need some other newsgroup,
where people who use your particular compiler on your particular
system can answer your question, and correct those who give wrong
answers.

This same sort of reasoning -- i.e., that you will be much more
likely to get a correct and useful answer elsewhere -- applies to
questions about Unix-like systems (including Linux) and Windows
systems. In particular, I believe they have quite different
methods for determining load-image and runtime memory sizes.
(Consider, e.g., ELF-style shared libraries vs Windows-style DLLs.)
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (4039.22'N, 11150.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
 
Reply With Quote
 
Joona I Palaste
Guest
Posts: n/a
 
      02-13-2004
Alan Balmer <(E-Mail Removed)> scribbled the following:
> On 13 Feb 2004 10:09:18 -0800, (E-Mail Removed) (jeff) wrote:
>>Hiya
>>
>>> How so? Most operating systems are written in C nowadays.

>>
>>I was trying to Pre-empt a reponse saying that i was offtopic.
>>

> It didn't help. You're still off-topic.


> Find a newsgroup which deals with the implementation you're interested
> in, whether that be Windows or *nix. Don't expect the answer to be the
> same for both. Don't even expect the answer to be the same for
> different *nix implementations.


....some of which are for architectures that don't have "CX registers"
in the first place. Sun Microsystems, for instance, makes millions
selling those.

--
/-- Joona Palaste ((E-Mail Removed)) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Hasta la Vista, Abie!"
- Bart Simpson
 
Reply With Quote
 
Thomas Matthews
Guest
Posts: n/a
 
      02-13-2004
jeff wrote:

> Hiya
>
>
>>How so? Most operating systems are written in C nowadays.

>
>
> I was trying to Pre-empt a reponse saying that i was offtopic.
>
>
>>How to apply the CX register to your program? That doesn't make any sense
>>whatsoever.

>
>
> If you go to command and then run debug and debug something.com (or
> exe), then you can use the -r command to get the register values, the
> CX value here relates to the program size. Thats what I want to get
> at.

[snip]

1. I've searched and searched the ARM Reference Guide and the
ARM User Guide and I can't find the CX register. Can you help?

2. The embedded operating system I'm using doesn't have the "debug"
command. What can I use?

>
> cheers
>
> greg



--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Acessing gridview data programmatially Fernando Monteiro ASP .Net 0 11-10-2005 01:27 PM
Acessing property Steve Peterson ASP .Net 1 06-17-2004 01:22 PM
Acessing codebehind data from ASPX Fabiano ASP .Net 1 05-26-2004 12:46 AM
Acessing ISA adminstration objects using ASP.Net sandy ASP .Net 2 04-26-2004 04:58 PM
Acessing mdb file from a network share!! Jay ASP .Net 2 11-21-2003 09:12 PM



Advertisments