简体   繁体   中英

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.

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.

写起来难吗?

ldi r16, 0x28

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM