Hello! Everybody!
Please help me. I would like to use named register. R6 for example. After a subroutine, which modify this register, the compiler doesnt recognize it, and place a nop where I want to rewrite this register. Here is my simple example:
register unsigned int akku __asm("r6");
unsigned char test1() { akku=1; return 12; }
unsigned char test(void) { unsigned char x,y; akku=10; //it is ok x=test1(); //this subroutine modify the akku(R6) register to 1 akku=10; //here is the problem if (x==12) { y=akku; } return y; } After the subroutine y=1. But the correct value is 10.
Here you can see the dissasembly window. The problem is the 0x8000CE6. Why it is NOP???
41: { 42: unsigned char x,y; 0x08000CDC B500 PUSH {lr} 43: akku=10; 0x08000CDE 260A MOVS r6,#0x0A 44: x=test1(); 0x08000CE0 F000F807 BL.W test1 (0x08000CF2) 0x08000CE4 4602 MOV r2,r0 45: akku=10; 0x08000CE6 BF00 NOP 46: if (x==12) 47: { 0x08000CE8 2A0C CMP r2,#0x0C 0x08000CEA D100 BNE 0x08000CEE 48: y=akku; 49: } 0x08000CEC B2F1 UXTB r1,r6 50: return y; 0x08000CEE 4608 MOV r0,r1 51: }
Thank you.
"For example in my program if I turn off the named registers, and I use normal variables, I lose 10kbyte."
If having a single register-mapped global variable changes the code size of 10kB for a 150kB program, then you have gremlins in the program. And since you claim your smaller program isn't even working the size of it is irrelevant.
If your functions are arranged according to how your algorithms works, then the compiler would already have noticed the value of keeping this akku variable in a register for the majority of the code lines. Because the compiler will count each access to different variables and try to figure out how probable it is that a loop will happen or a jump will be taken. And then select the most important variables for use in registers.
A great way to fail that is if the variable in question is used in such a way that it needs the volatile keyword - then the compiler isn't allowed to keep RAM copies and the number of memory accesses will escalate. If your code has huge numbers of accesses to volatile variables, then it's time to take one step back and see if the code can be redesigned.
An important thing to remember is aliasing. Global variables means the compiler will have to be very wary of aliasing, which affects the ability to produce good code. Having a value sent in as a value and then returned back on function exit indicates to the compiler that the function is given ownership of the variable - so the compiler can produce much better code.
Thank you for your help. I will test these suggestions. And I try to get help from technical support.