How to access processor registers

D

dspfun

In general, how do you read contents of the CPU's registers and how do
you get hold of the addresses of the CPU's registers?
 
I

Ian Collins

dspfun said:
In general, how do you read contents of the CPU's registers and how do
you get hold of the addresses of the CPU's registers?
There isn't a general answer. Not many processors have registers that
can be memory mapped.

Most compilers provide a means to embed assembly language, but you will
have to ask on a compiler and platform specific group.
 
B

Ben Pfaff

dspfun said:
In general, how do you read contents of the CPU's registers and how do
you get hold of the addresses of the CPU's registers?

C doesn't provide any portable means to do either one. I'd
advise you to seek help in a forum dedicated to your particular C
implementation.

Also: on most CPUs, the registers do not have addresses.
 
F

Flash Gordon

dspfun wrote, On 31/03/07 22:57:
In general, how do you read contents of the CPU's registers

Last time I did it I used an In-Circuit Emulator
> and how do
you get hold of the addresses of the CPU's registers?

What makes you think they have addresses?

Also, what makes you think this is a C question?
 
T

Thad Smith

Either with target-specific compiler extensions or assembly language.
Also: on most CPUs, the registers do not have addresses.

<OT>
I would say that that the register addresses are in a different memory
space on many processors. In some cases, you need to go through
multiple levels of selection or addressing to access the register. With
memory protection, I/O register access is typically denied to processes
running in user space.
</OT>
 
C

CBFalconer

dspfun said:
In general, how do you read contents of the CPU's registers and
how do you get hold of the addresses of the CPU's registers?

What registers? C runs quite well on register free machines.
 
D

dspfun

In general, how do you read contents of the CPU's registers and how do
C doesn't provide any portable means to do either one. I'd
advise you to seek help in a forum dedicated to your particular C
implementation.

Also: on most CPUs, theregistersdo not have addresses.

Thanks, that's why I haven't found a way to do this using C.
 
S

santosh

dspfun said:
Thanks, that's why I haven't found a way to do this using C.

C specifically disallows taking the address of objects qualified with
register, even if they may not actually be stored in machine
registers. There're also some more limitations for objects qualified
with register. Under modern compilers, register is of little, if any,
usefulness.
 
F

Francine.Neary

C specifically disallows taking the address of objects qualified with
register, even if they may not actually be stored in machine
registers. There're also some more limitations for objects qualified
with register. Under modern compilers, register is of little, if any,
usefulness.

Well as I read somewhere recently, the main audience for your code
isn't so much the compiler as a hypothetical future maintainer of your
code. And the register keyword surely transmits useful information
about the variable to him or her - ie that it's a key variable that
will be heavily used throughout the function.
 
I

Ian Collins

Well as I read somewhere recently, the main audience for your code
isn't so much the compiler as a hypothetical future maintainer of your
code. And the register keyword surely transmits useful information
about the variable to him or her - ie that it's a key variable that
will be heavily used throughout the function.
That should be obvious from inspection. Like any superfluous
documentation, it also has to be maintained. So when the function is
refactored and the variable is no longer important, you have to remember
to remove the unnecessary keyword.
 
S

santosh

Well as I read somewhere recently, the main audience for your code
isn't so much the compiler as a hypothetical future maintainer of your
code. And the register keyword surely transmits useful information
about the variable to him or her - ie that it's a key variable that
will be heavily used throughout the function.

IMHO, the register keyword is a poor way to do this. If you keep your
functions short in length and purpose, it ought to be easy enough to
determine the relative use of it's objects.
 
D

Daniel Rudy

At about the time of 3/31/2007 2:57 PM, dspfun stated the following:
In general, how do you read contents of the CPU's registers and how do
you get hold of the addresses of the CPU's registers?

The short answer? You don't. The compiler takes care of it for you.

CPU registers are, by definition, in the CPU, not memory. So they don't
have addresses per say.


--
Daniel Rudy

Email address has been base64 encoded to reduce spam
Decode email address using b64decode or uudecode -m

Why geeks like computers: look chat date touch grep make unzip
strip view finger mount fcsk more fcsk yes spray umount sleep
 
I

Ian Collins

Daniel said:
At about the time of 3/31/2007 2:57 PM, dspfun stated the following:



The short answer? You don't. The compiler takes care of it for you.

CPU registers are, by definition, in the CPU, not memory. So they don't
have addresses per say.
Have you ever used an 8051?
 
M

Martin Golding

Have you ever used an 8051?

Some modesl of the IBM 1130 stored the index register in memory. Some
microprocessor (TI9900, IIRC) used a single hardware register to point
to a block of memory locations containing the "registers". The Microdata
Reality series had a memory resident "accumulator", which was occasionally
loaded with a two character subroutine "op<number>; return;" to make up
for a handful of opcodes that had a constant where they should have had
an index. Way Back Then, registers weren't that much faster than memory.


Your token olde farte,

Martin
 
D

Daniel Rudy

At about the time of 4/5/2007 3:32 PM, Ian Collins stated the following:
Have you ever used an 8051?

Actually, I have. In fact, I have a few of Atmel versions laying
around. Microcontrollers like the 8051 use memory mapped I/O...and I
think that one does have the fabled memory mapped registers (It's been
awhile).

But, once again, this is not exactly portable C code. That is specific
to that platform.

--
Daniel Rudy

Email address has been base64 encoded to reduce spam
Decode email address using b64decode or uudecode -m

Why geeks like computers: look chat date touch grep make unzip
strip view finger mount fcsk more fcsk yes spray umount sleep
 
D

Daniel Rudy

At about the time of 4/5/2007 6:51 PM, Martin Golding stated the following:
Some modesl of the IBM 1130 stored the index register in memory. Some
microprocessor (TI9900, IIRC) used a single hardware register to point
to a block of memory locations containing the "registers". The Microdata
Reality series had a memory resident "accumulator", which was occasionally
loaded with a two character subroutine "op<number>; return;" to make up
for a handful of opcodes that had a constant where they should have had
an index. Way Back Then, registers weren't that much faster than memory.


Your token olde farte,

Martin

And I thought that the 8051, 8042, and their clones were the only ones
who did memory mapped registers....


--
Daniel Rudy

Email address has been base64 encoded to reduce spam
Decode email address using b64decode or uudecode -m

Why geeks like computers: look chat date touch grep make unzip
strip view finger mount fcsk more fcsk yes spray umount sleep
 
A

Al Balmer

Some modesl of the IBM 1130 stored the index register in memory. Some
microprocessor (TI9900, IIRC) used a single hardware register to point
to a block of memory locations containing the "registers".

IIRC, the TI99xx was a wide spectrum of computers based on the same
instruction set. The big thing about the register block was very fast
(for the time) context switching, each context having its own register
block.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top