Register storage class is used to quicky access the variable and its memory is allocated in CPU. But the registers in the cpu are limited. I use an intel Core i5-4260U Processor. I've visited intel website for the details of the register. But I couldn't find any of such specification of how many registers does the cpu contain (to visit website click <a href="http://ark.intel.com/products/75030/Intel-Core-i5-4260U-Processor-3M-Cache-up-to-2_70-GHz" rel="nofollow">here</a>). Even if i could find that the number of registers((from <a href="https://stackoverflow.com/questions/9130349/how-many-registers-are-there-in-8086-8088" rel="nofollow">How many registers are there in 8086/8088?</a>)) but I couldn't figure out how many of these are used by c storage classes.Answer1:
But I couldn't find any of such specification of how many registers does the cpu contain</blockquote>
Just look for "ia32 programming model" or "amd64 programming model".<blockquote>
I couldn't figure out how many of these are used by c storage classes.</blockquote>
That is implementation dependent. A compiler can even ignore that. Some of them use automatic register mapping if invoked with a high level of optimization, regardless of the way the variable has been declared.
For example: the programming model for user-mode applications on IA32 is composed of the registers
EDX are used as accumulators, they are implicit operands for some instructions (
DIV) and they hold the return value of a function.
ESP are reserved for stack and frame management.
EIP is the instruction pointer. So this leaves us with
ESI for register mapping. Depending upon the code generated, one or more of these registers may be needed, so reducing even more the number of available registers for mapping variables.
The <em>register</em> keyword in C was included because when C was created, compilers did not always do a good job of <em>register allocation</em>. Register allocation is the the part of the compiler which maps program variables to CPU registers.
Nowadays, the algorithms compilers use for register allocation are on the whole excellent. So much so that compilers often ignore the <em>register</em> keyword, reasoning that the compiler knows better then the programmer on how to map registers to maximize performance.
I'm not sure what compiler 'mcleod_ideafix' is referring to when he writes that
EDX are not available for register allocation. The <em>gcc</em> compiler uses 6 integer registers in 32 bit x86 code (
EDI). It will even use
EBP if the function does not make any function calls and you give the proper compiler option. 64 bit mode adds 8 more registers
R15. If you are using <em>gcc</em> just compile your file with the
-S option then look at the generated code to see what registers are used.
Another thing to consider is that Intel processors use a feature called <a href="http://en.wikipedia.org/wiki/Register_renaming" rel="nofollow">register renaming</a> to reduce the performance penalty of having not enough registers.