[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: programming question



On Tue, Nov 14, 2000 at 01:26:05PM -0800, Travis Davies wrote:
> What are the advantages of using CPU registers?
> If I used only registers to store value and arrays in,
> would it crash or cause the processing of the computer
> to slow?

Cpu Registers are very small memory locations (IIRC, 16 bit on i386's) on 
the processor. Their advantage is that they are /very/ fast, since they 
operate at the same clock speed as the processor and don't have to be
accessed through a bus. 

Registers can serve as temperory holding locations for data that will have
to be handled again soon. There is a lot more to them than that, but I can
not go much deeper with my limited knowledge about registers. IIRC, Jason
is an assembler programmer and, thus, would know a great deal about using
registers if you want an authority on the subject.

Your next question is reliant apon which language you are using. I am
assuming that you are not using Assembler as you would probably not be 
asking this question if you were. C has a regester keword which is now
obsolete. Its purpose was (thirty years ago, when it was concieved) 
to allow a programmer to tell the compiler that he would be using a value
a great deal an that the compiler should put it in a register.

Now, however, compilers are usually better judges as to what should go
a register than are programmers, so it is not advantageous to use the 
register keyword.

As to your question about storing data in registers, barring a kernel bug, 
I am not aware of any way to crash your system by storing an improper 
value in a register, but that dosen't mean there isn't a way. You can not
crash your program with the use of the register keyword, in fact, 
I believe that the default behavior of gcc is to simply ignore it and 
let the optomizer allocate registers.

Basically, don't mess with the registers in C, gcc does a pretty good job
with them on its own.

--
Jordan Bettis 
-
To unsubscribe, send email to majordomo@luci.org with
"unsubscribe luci-discuss" in the body.