reserve registers
reserve registers
Is there a way to reserve CPU registers as variables, so that, for example, in an ISR, you can operate out of the registers rather than RAM, and yet keep the contents persistent?
If you know what you're doing, you're not learning anything.
- dejan.odabasic
- mikroElektronika team
- Posts: 2649
- Joined: 30 Apr 2012 14:20
Re: reserve registers
Hello,
Please take a look at Memory Type Specifiers section of compiler help file.
You can use rx to specify that variable should be stored in working registers space.
If there is enough space for your variables to be stored in working registers space, compiler will not use the Rxx register which is allocated for your variable.
In statistic window you can find the address which is assigned to variable name and then you can find which Rxx register is on that location.
Then you can confirm that that Rxx register is not used by compiler by searching the *.lst file.
If there is no enough space compiler will report error.
Best regards.
Please take a look at Memory Type Specifiers section of compiler help file.
You can use rx to specify that variable should be stored in working registers space.
If there is enough space for your variables to be stored in working registers space, compiler will not use the Rxx register which is allocated for your variable.
In statistic window you can find the address which is assigned to variable name and then you can find which Rxx register is on that location.
Then you can confirm that that Rxx register is not used by compiler by searching the *.lst file.
If there is no enough space compiler will report error.
Best regards.
Re: reserve registers
The Memory Type Specifiers section in the help file says
What I'm evaluating is the possibility of some very fast (~1 uS) timers in the ISR. When I program them in Pascal, it generates about 50 instructions, which is way too much. I could reduce this to less than 10 (which would be acceptable) with an ASM block, but I need to be sure that the registers are persistent, and that they're accessible from the main Pascal code.
This leaves me with two questions; first, since you only specify rx, does the compiler chose the specific register? Secondly, are these assignments guaranteed to be persistent?Description This memory specifier allows variable to be stored in the working registers space (reserved for compiler purposes only).
Example // puts y in Rx space
var y : char; rx;
What I'm evaluating is the possibility of some very fast (~1 uS) timers in the ISR. When I program them in Pascal, it generates about 50 instructions, which is way too much. I could reduce this to less than 10 (which would be acceptable) with an ASM block, but I need to be sure that the registers are persistent, and that they're accessible from the main Pascal code.
If you know what you're doing, you're not learning anything.
Re: reserve registers
Bump.
This isn't working. I have to use the R reference in the ASM block. So I declare a variable with rx, and then look up the variable's R value (i.e. R12), and then place the reference to R12 in the ASM block. Then I recompile, and in the new compilation, the variable is now R13. So I change the ASM block to R13, and it changes the variable assignment back to R12. There doesn't seem to be a way to access this without changing it.
The compiler won't let me refer to the register by R value in the ASM block, because it changes the rx value. Is there a way to make an absolute reservation, so that I can guarantee that it always gets assigned to (for example) R12?
This isn't working. I have to use the R reference in the ASM block. So I declare a variable with rx, and then look up the variable's R value (i.e. R12), and then place the reference to R12 in the ASM block. Then I recompile, and in the new compilation, the variable is now R13. So I change the ASM block to R13, and it changes the variable assignment back to R12. There doesn't seem to be a way to access this without changing it.
The compiler won't let me refer to the register by R value in the ASM block, because it changes the rx value. Is there a way to make an absolute reservation, so that I can guarantee that it always gets assigned to (for example) R12?
If you know what you're doing, you're not learning anything.
- janko.kaljevic
- Posts: 3565
- Joined: 16 Jun 2011 13:48
Re: reserve registers
Hello,
If there is no free RX space, compiler will through an error, and won't allow you to set your variable in RX space.
But if there is free RX space, then compiler will not use it for it's own purposes.
You can call this variable by its name and you should not use R register where it is stored.
For example:
So you can use it in the code and in assembly (but with its original name).
Best regards.
If there is no free RX space, compiler will through an error, and won't allow you to set your variable in RX space.
But if there is free RX space, then compiler will not use it for it's own purposes.
You can call this variable by its name and you should not use R register where it is stored.
For example:
Code: Select all
var bla : dword; rx;
...
asm LUI bla, 15
end;
LATA := bla;
Best regards.
Re: reserve registers
Ok, making progress. When I use your example of
it works and seems to generate legitimate code. But when I tried my own code:
it said that it was "out of memory", which presumably means out of registers, since it highlighted the variable declaration. Is BLEZ not supported for some reason?
Code: Select all
asm LUI bla, 15 end;
Code: Select all
asm BLEZ bla, 0 end;
If you know what you're doing, you're not learning anything.
- janko.kaljevic
- Posts: 3565
- Joined: 16 Jun 2011 13:48
Re: reserve registers
Hello,
Thanks for reporting this.
I have reproduced it and we will inspect it further and provide solution promptly.
Best regards.
Thanks for reporting this.
I have reproduced it and we will inspect it further and provide solution promptly.
Best regards.
Re: reserve registers
Was this supposed to be fixed in 3.30? I'm still having the same problem with 3.30.
If you know what you're doing, you're not learning anything.