EmbeddedRelated.com
Forums

BIC instruction in Code Composer Studio (CCS4)

Started by cyclanprime December 23, 2011
I am porting to a newer MSP430 and as a consequence evaluating Code Composer Studio 4.1. I have been using the IAR toolchain for MSP430X169 development.

The IAR tool chain is smart enough to use BIS.B and BIC.B instructions when setting and clearing a single bit. For example, this is the assembly it produces for the following C syntax:

P4OUT |= BIT6;
asm( BIS.B #0x40,&P4OUT )
P4OUT &= ~BIT6;
asm( BIC.B #0x40,&P4OUT )

The same syntax using the CCS tool chain for MSP430X6638 produces the following assembly:

P4OUT |= BIT6;
asm( BIS.B #0x0040,&Port_3_4_P4OUT )
P4OUT &= ~BIT6;
asm( AND.B #0x00bf,&Port_3_4_P4OUT )

Now, aside from the differences because the 6638 can address I/O registers as 16-bit, is there another syntax or switch I should use to get CCS to use a BIC.B instruction? Maybe it doesn't matter that much, but I am a little worried about full register writes glitching the I/O, even if it has the same value after the write.

Thanks,
Jeff Geisler

Beginning Microcontrollers with the MSP430

"cyclanprime" :

> P4OUT &= ~BIT6;
> asm( BIC.B #0x40,&P4OUT )
> asm( AND.B #0x00bf,&Port_3_4_P4OUT )

This is just a alias and produce the same code. The MSP430 Assembler is using
several aliases, e.g. a jump is similar to a "ADD.W #value,R0"
The reason to use different instruction names for the same code (=alias) is
to improve the readability of the assembly code, but keep the CPU very
efficient and small. The opposite of this is the 8051 - it has bit
instructions (for some registers) and logical instructions - both do the same
but use different code (and cycles). This blows up the CPU (and ROM space)
with little benefit.

M.

Hi,

> "cyclanprime" :
>
> > P4OUT &= ~BIT6;
> > asm( BIC.B #0x40,&P4OUT )
> > asm( AND.B #0x00bf,&Port_3_4_P4OUT )
>
> This is just a alias and produce the same code.

Actually not. BIC is a separate instruction. For instance:

BIC R4, R5

You can't make that into an AND without first somehow doing a "NOT".

> The MSP430 Assembler is using
> several aliases, e.g. a jump is similar to a "ADD.W #value,R0"
> The reason to use different instruction names for the same code (=alias)
is to
> improve the readability of the assembly code, but keep the CPU very
efficient
> and small. The opposite of this is the 8051 - it has bit instructions (for
> some registers) and logical instructions - both do the same but use
different
> code (and cycles). This blows up the CPU (and ROM space) with little
benefit.

--
Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
SolderCore running Defender... http://www.vimeo.com/25709426

I believe there is also a difference in the flag handling - BIC doesn't
affect the flags, whereas AND and BIS do.

Apart from that, "BIC x, y" means "y &= ~x".

mvh.,

David

On 23/12/2011 10:12, Paul Curtis wrote:
> Hi,
>
> > "cyclanprime" > >:
> >
> > > P4OUT &= ~BIT6;
> > > asm( BIC.B #0x40,&P4OUT )
> > > asm( AND.B #0x00bf,&Port_3_4_P4OUT )
> >
> > This is just a alias and produce the same code.
>
> Actually not. BIC is a separate instruction. For instance:
>
> BIC R4, R5
>
> You can't make that into an AND without first somehow doing a "NOT".
>
> > The MSP430 Assembler is using
> > several aliases, e.g. a jump is similar to a "ADD.W #value,R0"
> > The reason to use different instruction names for the same code (=alias)
> is to
> > improve the readability of the assembly code, but keep the CPU very
> efficient
> > and small. The opposite of this is the 8051 - it has bit instructions
> (for
> > some registers) and logical instructions - both do the same but use
> different
> > code (and cycles). This blows up the CPU (and ROM space) with little
> benefit.
>
> --
> Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
> SolderCore running Defender... http://www.vimeo.com/25709426
"Paul Curtis" :

> Hi,
>
>> "cyclanprime" :
>>
>> > P4OUT &= ~BIT6;
>> > asm( BIC.B #0x40,&P4OUT )
>> > asm( AND.B #0x00bf,&Port_3_4_P4OUT )
>>
>> This is just a alias and produce the same code.
>
> Actually not. BIC is a separate instruction. For instance:
>
> BIC R4, R5
>
> You can't make that into an AND without first somehow doing a "NOT".

Yes true, but in this case negation (for constant operator) is done during
compile time, not run time - so it is not wrong.

M.

Hi Matthias,

> "Paul Curtis" :
>
> > Hi,
> >
> >> "cyclanprime" :
> >>
> >> > P4OUT &= ~BIT6;
> >> > asm( BIC.B #0x40,&P4OUT )
> >> > asm( AND.B #0x00bf,&Port_3_4_P4OUT )
> >>
> >> This is just a alias and produce the same code.
> >
> > Actually not. BIC is a separate instruction. For instance:
> >
> > BIC R4, R5
> >
> > You can't make that into an AND without first somehow doing a "NOT".
>
> Yes true, but in this case negation (for constant operator) is done during
> compile time, not run time - so it is not wrong.

It's not right either as BIC and AND affect the flags slightly differently
(as was mentioned before). I don't think the assembler will have the
latitude to change the instruction.

--
Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
SolderCore running Defender... http://www.vimeo.com/25709426

"Paul Curtis" :

> Hi Matthias,
>
>> "Paul Curtis" :
>>
>> > Hi,
>> >
>> >> "cyclanprime" :
>> >>
>> >> > P4OUT &= ~BIT6;
>> >> > asm( BIC.B #0x40,&P4OUT )
>> >> > asm( AND.B #0x00bf,&Port_3_4_P4OUT )
>> >>
>> >> This is just a alias and produce the same code.
>> >
>> > Actually not. BIC is a separate instruction. For instance:
>> >
>> > BIC R4, R5
>> >
>> > You can't make that into an AND without first somehow doing a "NOT".
>>
>> Yes true, but in this case negation (for constant operator) is done durin
> g
>> compile time, not run time - so it is not wrong.
>
> It's not right either as BIC and AND affect the flags slightly differently
> (as was mentioned before). I don't think the assembler will have the
> latitude to change the instruction.

Yes, BIC and BIS are not influencing the flags; however I have not yet seen
that a MSP430-compiler is using the flags after a BIC/BIS from the result of
a instruction before the BIC/BIS. (?)

M.