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

Use of "using"

The C51 manual states, "The using attribute may not be used in functions that return a value in registers" and goes on to state, "Even when you use the same register bank, functions declared with the using attribute cannot return a bit value." It's clear that a bit value set in the carry flag isn't passed back to the calling function. It's not clear why a function "using" a register bank can't call another function "using" the same register bank: The same bank select bits are being pushed, loaded, and popped. Am I missing something, or is this an OK thing to do?

Parents
  • The using attribute may not be used in functions that return a value in registers

    This warning appears on the manual page: http://www.keil.com/support/man/docs/c51/c51_le_regbankspec.htm

    The reason for this warning should be clear...

    1. Enter function
    2. Save the register bank
    3. Switch to new register bank
    4. Execute function code
    5. Store return values in registers
    6. Restore prior register bank...oops, just killed return values
    7. Return to caller

    So, as you can see, the reason for this warning has to do with the register bank getting restored to that of the caller.

    The remainder of the warning states that: "You must exercise extreme care to ensure that register bank switches are performed only in carefully controlled areas. Failure to do so may yield incorrect function results."

    So, as long as you do that (and make sure you are in the same register bank) you should be OK.

    The final sentence of the warning, "Even when you use the same register bank, functions declared with the using attribute cannot return a bit value." should also be clear.

    Saving and restoring the register banks involves pushing and popping the PSW which contains the carry flag (which contains the bit return value). Restoring the register banks also restores the carry flag. Therefore, you lose the intended return bit value.

    You may want to take a look at the Registerbank directive (http://www.keil.com/support/man/docs/c51/c51_registerbank.htm).

    My personal advice is to make sure this is what you REALLY want to do. It's not difficult to make things work but this was usually a sign to me when I was at Keil that there was a potential design problem.

    Jon

Reply
  • The using attribute may not be used in functions that return a value in registers

    This warning appears on the manual page: http://www.keil.com/support/man/docs/c51/c51_le_regbankspec.htm

    The reason for this warning should be clear...

    1. Enter function
    2. Save the register bank
    3. Switch to new register bank
    4. Execute function code
    5. Store return values in registers
    6. Restore prior register bank...oops, just killed return values
    7. Return to caller

    So, as you can see, the reason for this warning has to do with the register bank getting restored to that of the caller.

    The remainder of the warning states that: "You must exercise extreme care to ensure that register bank switches are performed only in carefully controlled areas. Failure to do so may yield incorrect function results."

    So, as long as you do that (and make sure you are in the same register bank) you should be OK.

    The final sentence of the warning, "Even when you use the same register bank, functions declared with the using attribute cannot return a bit value." should also be clear.

    Saving and restoring the register banks involves pushing and popping the PSW which contains the carry flag (which contains the bit return value). Restoring the register banks also restores the carry flag. Therefore, you lose the intended return bit value.

    You may want to take a look at the Registerbank directive (http://www.keil.com/support/man/docs/c51/c51_registerbank.htm).

    My personal advice is to make sure this is what you REALLY want to do. It's not difficult to make things work but this was usually a sign to me when I was at Keil that there was a potential design problem.

    Jon

Children
No data