Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

practical application of the registers in c programming language

Status
Not open for further replies.

demola0001

Newbie level 3
Newbie level 3
Joined
Jun 22, 2011
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,302
please i will like to know the practical application of the registers in c programming language.
 

I think the question you had made is incomplete... If you are trying to refer any microcontroller device please mention it...
 

No the question is not incomplete, there are register values in C. In fact there is a corresponding register keyword.

Register values are automatic variables. If you declare a variable as a register variable, it is stored in the CPU registers instead of RAM, resulting to faster access to those variables. User can instruct the compiler to put a variable in registers. Consider the following example:

Code:
uint16 i;
for (i = 0; i < 50000; i++)
{
  ;
}

This loop has a big execution time, since it counts from 0 to 50000. So someone would want the i variable to be placed in a fast memory region, so that the loop execution time would be reduced. I believe that a decent compiler should decide effectively what variables should be stored inside registers or RAM, but user could do it manually anyway:

Code:
[B]register[/B] uint16 i;
for (i = 0; i < 50000; i++)
{
  ;
}

One important thing is that the compiler is free to ignore that hint, so you must check the i variable position inside your watch window.

Hope that helped.
 
  • Like
Reactions: XT.5155

    XT.5155

    Points: 2
    Helpful Answer Positive Rating
The register storage class specifier indicates to the compiler that the object should be stored in a machine register. The register storage class specifier is typically specified for heavily used variables, such as a loop control variable, in the hopes of enhancing performance by minimizing access time. However, the compiler is not required to honor this request. Because of the limited size and number of registers available on most systems, few variables can actually be put in registers. If the compiler does not allocate a machine register for a register object, the object is treated as having the storage class specifier auto.

An object having the register storage class specifier must be defined within a block or declared as a parameter to a function.

The following restrictions apply to the register storage class specifier:

You cannot use pointers to reference objects that have the register storage class specifier.
You cannot use the register storage class specifier when declaring objects in global scope.
A register does not have an address. Therefore, you cannot apply the address operator (&) to a register variable.
You cannot use the register storage class specifier when declaring objects in namespace scope.

I hope this will help to you.....
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top