ARM Bitwise Logic
Bitwise Logic Bitwise operations : Work on patterns of bits, not values represented by those bits
Bitwise Logic Bitwise OR:
Binary Immediates #0b starts a binary immediate value – No spaces – Any 1’s must be in 8 consecutive bits 0b b b b
ORR ORR: Bitwise OR ORRrd, rs, #___ ORRrd, rs, rm
AND AND: Bitwise AND ANDrd, rs, #___ ANDrd, rs, rm
EOR EOR: Bitwise exclusive OR EORrd, rs, #___ EORrd, rs, rm
In Place Swap EOR can swap two values in place
NOT No NOT instruction – use MVN
Key Details A or 0 = A – Anything or'd with 0 is that thing A and 1 = A – Anything and'd with 1 is that thing A and 0 = 0 – Anything and'd with 0 is 0 A xor 1 = not(A) – Xoring with 1 flips bit A xor 0 = A – Xoring with 0 does nothing
High Level Code In C/C++
High Level Code
BIC BIC: Binary Clear BICrd, rs, #___ BICrd, rs, rm – Clear bits set in # or rm – AND with invers or bits in # or rm
Bit Isolation Getting particular bits out of pattern Strategy 1: – Shift to wipe out others Want to clear left 8 bits: Shift left 8 bits: Shift back right 8 bits:
Bit Isolation Getting particular bits out of pattern Strategy 1: – Shift to wipe out others Want to isolate green five bits Shift left 8 bits Shift right
Bit Isolation Getting particular bits out of pattern Strategy 2: – Mask : binary pattern showing bits to keep 0x00 : keep no bits 0x01 : keep bit 1 ( ) 0x04 : keep bit 3 ( ) 0x05 : keep bit 1 & 3 ( ) 0xF0 : keep bit 5-8 ( )
Using Masks AND with a mask 0's out unmasked portions: Mask Data AND result
Hex Mask F (1111) mask a whole hex digit 0x fMask0xfff x Data0x x AND result0x
Bit Isolation Getting particular bits out of pattern Strategy 2: – Masking : binary pattern showing bits to keep Want to keep just green bits Create mask… 0x01F AND
Mask Samples