Problems with 'bit set' operation on the MCF52233

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problems with 'bit set' operation on the MCF52233

798 Views
Eqqman
Contributor I

Hello-

 

I'm trying to replace some of the macros that get created by the MCF52233 compiler with atomic operations.  For example, I'm using things like

 

MCF_PIT0_PCSR |= 1

 

But this compiles into numerous instructions.  I need to be able to set this bit in a single instruction.  Looking through the instruction set, I see that subq, addq, and bset all have the same allowable format of '#<data>,<ea>x'

 

So if I try to compile

subq #1, 40000000

addq #1, 40000000

 

everything is fine, but if I compile

bset #1, 40000000 or

bclr #1, 40000000

 

I get a compile error 'illegal addressing mode'.  So it is not clear to me why this same mode works for some commands and not others when they all allegedly accept it.

Labels (1)
0 Kudos
1 Reply

226 Views
bkatt
Contributor IV

Eqqman wrote:

 

...if I compile

bset #1, 40000000 or

bclr #1, 40000000

 

I get a compile error 'illegal addressing mode'.

 


The tables provided with the full documentation of BSET and BCLR show that combination of addressing modes is NOT permitted. A register must be involved, either the bit number in a source register, or the destination in a data register or through an address register.

 

To atomically set/clear a bit at a byte address, you can put the bit number in a register, e.g.:

 

moveq #1,r0

bset.b r0,40000000

 

Or the address in an address register:

 

lea 40000000,a0

bset.b #1,(a0) 

 

If the target location is 32 bits, you can use "and" and "or" instructions to make atomic changes with the mask/value in a source register. For a 16-bit I/O port, I don't think atomic is possible with coldfire.

 

0 Kudos