Kirk Humphries

RAM Test Routine

Discussion created by Kirk Humphries Employee on Jan 26, 2006

This message contains an entire topic ported from a separate forum. The original message and all replies are in this single message. We have seeded this new forum with selected information that we expect will be of value to you as you search for answers to your questions.

 

Posted: Fri Dec 16, 2005  4:58 am

 

Hi,

 

I've to make a RAM test routine at startup.

I've have already the code in C language.

But I don't want to use RAM memory to test it-self.

So I must to use just CPU registers.

Is there any way to declare local variables as registers in C Language ??

I try that :

" register int test; "

But when I look at generated assembly code, it uses the stack.

 

If it's not possible, I will have to code it in assembly code and I don't want to do that .

 

Many thanks in advance for your help.

 


 

Posted: Fri Dec 16, 2005  2:43 pm

 

> I try that :

> " register int test; "

> But when I look at generated assembly code, it uses the stack.

 

Looks right, but usually it doesn't work for me because C uses registers automatically, and since there are extremely few registers in this CPU, there is often not the right type available for your variable.

 

Also I don't know if register allocation is well optimized in my compiler (GCC).

 


 

Posted: Mon Dec 19, 2005  10:20 am

 

> > I try that :

> > " register int test; "

> > But when I look at generated assembly code, it uses the stack.

>

 

> Looks right, but usually it doesn't work for me because C uses

> registers automatically, and since there are extremely few registers

> in this CPU, there is often not the right type available for your

> variable.

>

 

> Also I don't know if register allocation is well optimized in my

> compiler (GCC).

 

As I recall the "register" keyword is a "suggestion" to the compiler. It can be used, or not, according to what the compiler thinks best.

 


 

Posted: Mon Dec 19, 2005  10:06 am

 

> I've to make a RAM test routine at startup.

> I've have already the code in C language.

> But I don't want to use RAM memory to test it-self.

> So I must to use just CPU registers.

> Is there any way to declare local variables as registers in C Language ??

> I try that :

> " register int test; "

> But when I look at generated assembly code, it uses the stack.

>

 

> If it's not possible, I will have to code it in assembly code and I

> don't want to do that .

 

Look to your compiler's optimization options. CodeWarrior has such options and I suspect other compilers do too. If you're doing a "debug" build (rather than a "production" or "release" build), your compiler may suppress optimizing variables.

 

By the way, you don't mention what compiler/platform you're using.

 

Regards,

 


 

Posted: Mon Dec 19, 2005  11:17 am

 

> But I don't want to use RAM memory to test it-self.

> So I must to use just CPU registers.

 

If you must not use any memory to run the test, your best bet will be to code the test in assembly. It's asking a lot of the compiler to generate all-register code, particularly with the small register set of an HC12.

 

> Is there any way to declare local variables as registers in C Language ??

> I try that:

> " register int test; "

> But when I look at generated assembly code, it uses the stack.

 

Most C compilers are coded to assume the availability of a stack when they generate code. It would require a rather different approach to the code generator to emit all-register code instead of register-and-stack code.

 

Declaring a variable "register" does not mean "the compiler must put this in a register". "register" is a promise to the compiler that you will never take the address of the variable and a request that the compiler make access to the variable "as fast as possible". The compiler is free to ignore the keyword if it wants, or if it can do a better job of register allocation using its internal algorithms.

 

The result is that either you have to use scratchpad RAM somewhere or you have to code the RAM test in assembly.

Outcomes