----- Ursprüngliche Nachricht -----
Von: Ian Tait
Gesendet am: 01 Sep 2010 06:19:47

> My understanding is that the difference between the two instructions is 
> simply the way in which you specify the bit mask.  'bic' will invert it 
> for you then AND it, where with 'and' the source bitmask needs to be 
> inverted.  Both instructions take the same number of cycles to execute 
> and both of your examples are using immediate addressing of the literal, 
> and absolute addressing of P1OUT. (overflow bit behaviour differs)

There's a difference, and that's why the compiler is using BIC sometimes: if 
the compiler detects that the bit to clear is one of the lower four bits (and 
only one), teh dat asource for the BIC instruction can be the constant 
generator, avoiding the need to pass the argument as separate 16 bit value to 
the instruction. This executes faster and is 2 bytes shorter.
AND instructions (if used for clearing a bit rather then for isolating one) 
usually have a multi-bit argument and therefore cannot use the constant 
generator.

> Given that you are coding in C and the statement actually says to AND an 
> inverted literal value with P1OUT, it seems quite reasonable for the 
> preprocessor to invert the literal then present the compiler with a 
> straight forward AND, which it obviously uses the 'and.b' instruction for.

Yes, using the & operator is obviously an AND instruction and so the compiler 
uses it as it is written. Unless it detects a way for optimization.
If the same argument is required more than once in a function, the compiler 
might decide to put it into a register and use it from there. Then there is no 
difference between AND and BIC (except for the inverted argument).

> I can see that the output is inconsistent between upper and lower 
> nibbles, but the end result is the same.

There are no 0x10...0x80 constants available through the constant generator. It 
has nothing to do with 'nibble' but rather with the fact that bit 0..3 are the 
most often bits in the status register (carry, overflow etc.), so the 
constant generator was optimized to provide them.

JMGross


Reply via email to