reserve registers

General discussion on mikroPascal PRO for PIC32.
Post Reply
Author
Message
LGR
Posts: 3204
Joined: 23 Sep 2004 20:07

reserve registers

#1 Post by LGR » 22 Feb 2013 01:41

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.

User avatar
dejan.odabasic
mikroElektronika team
Posts: 2649
Joined: 30 Apr 2012 14:20

Re: reserve registers

#2 Post by dejan.odabasic » 01 Mar 2013 16:46

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.

LGR
Posts: 3204
Joined: 23 Sep 2004 20:07

Re: reserve registers

#3 Post by LGR » 01 Mar 2013 19:15

The Memory Type Specifiers section in the help file says
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;
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?

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.

LGR
Posts: 3204
Joined: 23 Sep 2004 20:07

Re: reserve registers

#4 Post by LGR » 06 Mar 2013 22:23

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?
If you know what you're doing, you're not learning anything.

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: reserve registers

#5 Post by janko.kaljevic » 08 Mar 2013 14:37

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:

Code: Select all

var bla : dword; rx;
...
  asm LUI bla, 15
  end;
  LATA := bla;
So you can use it in the code and in assembly (but with its original name).

Best regards.

LGR
Posts: 3204
Joined: 23 Sep 2004 20:07

Re: reserve registers

#6 Post by LGR » 08 Mar 2013 20:14

Ok, making progress. When I use your example of

Code: Select all

asm LUI bla, 15  end;
it works and seems to generate legitimate code. But when I tried my own code:

Code: Select all

asm BLEZ bla, 0  end;
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?
If you know what you're doing, you're not learning anything.

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: reserve registers

#7 Post by janko.kaljevic » 11 Mar 2013 16:12

Hello,

Thanks for reporting this.
I have reproduced it and we will inspect it further and provide solution promptly.

Best regards.

LGR
Posts: 3204
Joined: 23 Sep 2004 20:07

Re: reserve registers

#8 Post by LGR » 19 Mar 2013 19:22

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.

Post Reply

Return to “mikroPascal PRO for PIC32 General”