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

"using" attribute

Hi,

Anyone can tell me how I can know whether I need to use "using" attribute or not? Attribute "using" ranges 0-3, So which number I have to select? I read Cx51 user guide, it states that:

The using attribute may not be used in functions that return a value in registers. 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. Even when you use the same register bank, functions declared with the using attribute cannot return a bit value.

Unfortunately, I cannot get point.

Thanks,
pak

Parents
  • Anyone can tell me how I can know whether I need to use "using" attribute or not?

    I thought the manual page was pretty clear.

    http://www.keil.com/support/man/docs/c51/c51_le_regbankspec.htm

    Apart from that, there is no requirement that you use register banks ever! If you don't use register banks that memory is available for use by program variables and the stack (assuming you use no bit memory).

    In general, I only use register banks for interrupts. So, my main C function and all the routines it calls use register bank 0. If I keep my interrupt service routines very small, they don't need to save lots of registers on the stack--and I don't need to use a different register bank. If your interrupt routine uses 4 registers and RB0, it must push and pop those registers each time it gets triggered. In some cases, this may take up too much time. Switching to a different register bank is very fast. But, you basically "reserve" those 8 bytes for that interrupt.

    For interrupt routines that must be fast, I try to make them small so they don't use lots of registers in the first place. But, if I just can make that work, then I use a register bank.

    I guess it boils down to how many interrupts you get in a second and how fast the service routine has to run and how short of memory you are. You must balance all of these things to figure out the answer.

    Jon

Reply
  • Anyone can tell me how I can know whether I need to use "using" attribute or not?

    I thought the manual page was pretty clear.

    http://www.keil.com/support/man/docs/c51/c51_le_regbankspec.htm

    Apart from that, there is no requirement that you use register banks ever! If you don't use register banks that memory is available for use by program variables and the stack (assuming you use no bit memory).

    In general, I only use register banks for interrupts. So, my main C function and all the routines it calls use register bank 0. If I keep my interrupt service routines very small, they don't need to save lots of registers on the stack--and I don't need to use a different register bank. If your interrupt routine uses 4 registers and RB0, it must push and pop those registers each time it gets triggered. In some cases, this may take up too much time. Switching to a different register bank is very fast. But, you basically "reserve" those 8 bytes for that interrupt.

    For interrupt routines that must be fast, I try to make them small so they don't use lots of registers in the first place. But, if I just can make that work, then I use a register bank.

    I guess it boils down to how many interrupts you get in a second and how fast the service routine has to run and how short of memory you are. You must balance all of these things to figure out the answer.

    Jon

Children