Moonlit
Moonlit

Reputation: 5419

bit manipulation avr assembly

I am currently reading a tutorial about avr assembler programming. There is said:

Bit Manipulation cbr and sbr clear or set one multiple bit(s) in a register. These instructions only work on registers r16 to r31. They do not use single bits as an argument, but masks which can contain multiple bits:

sbr r16, (1<<5)+(1<<3) ;set bits 5 and 3 in register 16 
cbr r16,0x03    ;clear bits 1 and 0 in register 16

can anybody explain me the parameters of the two instructions? why do i have to write (1<<5)+(1<<3) in order to set bit 5 and 3? i guess << is something like a bitshifting operation.

Upvotes: 0

Views: 6840

Answers (2)

Bob McLoud
Bob McLoud

Reputation: 1

Isn't it easier to just write

ldi r16, 0x28

Upvotes: 0

Ian McMahon
Ian McMahon

Reputation: 1700

yes, << is bitshifting. What you're doing is constructing a bitmask which will be 00101000, and that will set bits 3 and 5, zero indexed. In your cbr instruction, you're passing the mask 0x03, which is 00000011, which clears bit 0 and 1.

Upvotes: 6

Related Questions