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
  • I am looking at the assembler output. That's why I stated the question the way I did. I don't understand why the manual states "don't do it" when the assy code appears to indicate it should work fine: A function "using" a register bank first pushes the PSW containing the caller's register bank bits, then loads the PSW with the same register bank bits, place the function result in the expected absolute-addressed registers, then pops the PSW which returns the same bank bit settings to the caller, which pulls the result from the same registers. Ergo, the result appears to be returned just fine.

    In this particular case, the calling function is an interrupt handler. If the called function isn't declared using the same register bank, things obviously get bolluxed up. The called function will (probably) use bank zero, fouling up whatever was happening when the interrupt occurred. The called function could pass the result in memory rather than returning it in registers, incurring extra store and load operations. The interrupt trap could push all registers on the way in and pop them back on the way out. All this is not necessary if my analysis of the assy code is correct.

    My current project is the first in which I've used the 8051 architecture and I was hoping to hear from someone with more experience using the parts.

Reply
  • I am looking at the assembler output. That's why I stated the question the way I did. I don't understand why the manual states "don't do it" when the assy code appears to indicate it should work fine: A function "using" a register bank first pushes the PSW containing the caller's register bank bits, then loads the PSW with the same register bank bits, place the function result in the expected absolute-addressed registers, then pops the PSW which returns the same bank bit settings to the caller, which pulls the result from the same registers. Ergo, the result appears to be returned just fine.

    In this particular case, the calling function is an interrupt handler. If the called function isn't declared using the same register bank, things obviously get bolluxed up. The called function will (probably) use bank zero, fouling up whatever was happening when the interrupt occurred. The called function could pass the result in memory rather than returning it in registers, incurring extra store and load operations. The interrupt trap could push all registers on the way in and pop them back on the way out. All this is not necessary if my analysis of the assy code is correct.

    My current project is the first in which I've used the 8051 architecture and I was hoping to hear from someone with more experience using the parts.

Children