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

what's the function of "AREGS"and "NOAREGS"

what's the function of "AREGS"and "NOAREGS", can you provide me some sample, so that I could understand them clear. Are them still useful in current updated versions.
In the manual it is said that with "NOAREGS" the function could be called by another functions using different register bank.

#pragma NOAREGS
char add(char i)
{
    return i+10;
}

void main(void) using 1
{
    ch = add(3);
}

whether I enable or disable #pragma NOAREGS
I always get the right result. If with "NOAREGS" the function could be called by another functions using different register bank, then does it also mean that with "AREGS" the function could not be called by another functions using different register bank. I am very confused with "AREGS"and "NOAREGS".

Parents
  • The point about NOAREGS is that all registers also have an absolute address in memory. So, if the compiler knows that you are using register bank 0, it can access access registers R0, R1, ... R7 not only by name, but also accessing data memory addresses 0, 1, ... 7. Each register of each register bank has a unique address.

    Being able to access registers either way has advantages for speed and compactness of code. The compiler will use a mixture of addressing modes to get at the registers.

    The problems only start when a function is called and the currently selected register bank is unknown. In this case, the compiler cannot know the direct address of a register - in fact you have to tell it not to make any assumptions about the selected register bank by using NOAREGS.

    I find it very strange that the compiler should allow a function that has parameters passed in registers to set the register bank with using. The reason add() does not work with using 2 is parameter i is put into a register by main() and although add() will be looking at the right register, it will have changed the register bank. I cannot think of any good reason for the compiler not to generate a warning here.

Reply
  • The point about NOAREGS is that all registers also have an absolute address in memory. So, if the compiler knows that you are using register bank 0, it can access access registers R0, R1, ... R7 not only by name, but also accessing data memory addresses 0, 1, ... 7. Each register of each register bank has a unique address.

    Being able to access registers either way has advantages for speed and compactness of code. The compiler will use a mixture of addressing modes to get at the registers.

    The problems only start when a function is called and the currently selected register bank is unknown. In this case, the compiler cannot know the direct address of a register - in fact you have to tell it not to make any assumptions about the selected register bank by using NOAREGS.

    I find it very strange that the compiler should allow a function that has parameters passed in registers to set the register bank with using. The reason add() does not work with using 2 is parameter i is put into a register by main() and although add() will be looking at the right register, it will have changed the register bank. I cannot think of any good reason for the compiler not to generate a warning here.

Children
No data