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

How can I exchange two bits?

The following does not work (ACC is always 0, despite out[0] is 255):

ACC0 = out[0] & 1 == 1 ? 1 : 0;
ACC1 = out[0] & 2 == 2 ? 1 : 0;
out[0] &= 0xFC;
send_string(" acc1");
send_byte(ACC);
if (ACC0)
out[0] |= 2;
if (ACC1)
out[0] |= 1;

Parents
  • I can't help but think you are assuming that you can utilize the ACCumulator from C, which of course you can, but it is extremely ill-advised to do so. "ACC" is an SFR defined in regxx.h for the microcontroller's accumulator register -- the single most frequently used register! To assume that ACC contains anything predictable after a call to send_string() is sheer lunacy. In this case, it may happen to always be zero if only because (and this is a pure guess on my part) send_string() may return after encountering the NUL-terminator of the string you are passing it and having checked for zero using the accumulator before returning.

Reply
  • I can't help but think you are assuming that you can utilize the ACCumulator from C, which of course you can, but it is extremely ill-advised to do so. "ACC" is an SFR defined in regxx.h for the microcontroller's accumulator register -- the single most frequently used register! To assume that ACC contains anything predictable after a call to send_string() is sheer lunacy. In this case, it may happen to always be zero if only because (and this is a pure guess on my part) send_string() may return after encountering the NUL-terminator of the string you are passing it and having checked for zero using the accumulator before returning.

Children
No data