This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Keil Named Register Variable not working

Somebody ever used named register variables successfully and can tell me what i am doing wrong?

example code:

#pragma O0        // optimization off
#pragma thumb     // thumb mode
__global_reg(8) int myR8;
void DAbt_Handler(void) __irq
{
  register unsigned int programCounter __asm ("lr");
  unsigned int          value = programCounter - (unsigned int)0x04;
  register int myR7 __asm("r7");

  myR7 = 0x07;
  myR7++;

  myR8 = 0x08;
  myR8++;

  printf("R2 : %x",programCounter);
  printf("R7: %x",myR7);
  printf("R8 : %x",myR8);
  printf("** Data Abort @%X **\n",value);

  while(1);
}

So in theory myR7 should be translated to Register R7, myR8 (global register definition) should be R8 etc. but if i look into lst file the compiler makes something different of it:

;;;17     void DAbt_Handler(void) __irq
00000c  e2446004          SUB      r6,r4,#4
;;;18     {
;;;19
;;;20       register unsigned int programCounter __asm ("lr");
;;;21       unsigned int          value = programCounter - (unsigned int)0x04;
;;;22       register int myR7 __asm("r7");
;;;23
;;;24       myR7 = 0x07;
000010  e3a05007          MOV      r5,#7
;;;25           myR7++;
000014  e2855001          ADD      r5,r5,#1
;;;26           myR8 = 0x08;
000018  e3a0b008          MOV      r11,#8
;;;27           myR8++;
00001c  e28bb001          ADD      r11,r11,#1
;;;28
;;;29
;;;30           printf("LR : %x",programCounter);
000020  e1a01004          MOV      r1,r4
000024  e28f007c          ADR      r0,|L1.168|
000028  ebfffffe          BL       __2printf
;;;31           printf("R7: %x",myR7);
00002c  e1a01005          MOV      r1,r5
000030  e28f0078          ADR      r0,|L1.176|
000034  ebfffffe          BL       __2printf
;;;32           printf("R8 : %x",myR8);
000038  e1a0100b          MOV      r1,r11
00003c  e28f0074          ADR      r0,|L1.184|
000040  ebfffffe          BL       __2printf

Any hints are welcome.

Parents Reply Children
  • Independed of the "sense" in this example - in my opinion if i define a "named register variable" i think the compiler has _always_ to generate it as specified and shall not use a different register instead even if it might result in an unexpected runtime behaviour.

    Keil says "You can declare named register variables as global variables. You can declare some, but not all, named register variables as local variables. In general, do not declare Vector Floating-Point (VFP) registers and core registers as local variables. Do not declare caller-save registers, such as R0, as local variables."
    [http://www.keil.com/support/man/docs/armcc/armcc_CHDHCIEE.htm]