4.3 Bit Manipulation Notes by EMK
4.3 Bit Manipulation Notes by EMK
3 Bit Manipulation
Objective:
Show understanding of & perform binary shifts Logical, arithmetic & cyclic Left shift, right
shift.
.
Note: ACC denotes Accumulator, IX denotes Index Register, # denotes a denary number, e.g.
#123, B denotes a binary number, e.g. B01001010 & denotes a hexadecimal number, e.g. &4
Mask: A number that is used with the logical operators AND, OR, XOR & NOT to identify,
remove or set a single bit or group of bits in an address or register.
Binary Shifts
Binary shift involves moving bits stored in a register a given number of places within
register. Each bit within register may be used for a different purpose.
Types of Shift.
Logical Shift – bits shifted out of register are replaced with zeros.
➢ Left Logical Shift of one position moves each bit to left by one. Vacant least
significant bit (LSB) is filled with zero and most significant bit (MSB) is discarded.
➢ Right Logical Shift of one position moves each bit to the right by one. Least
significant bit is discarded and vacant MSB is filled with zero.
➢ Right Arithmetic Shift of one position moves each bit to right by one. Least
significant bit is discarded and vacant MSB is filled with value of previous (now
shifted one position to right) MSB.
Cyclic Shift – no bits are lost during a shift. Bits shifted out of one end of register are
introduced at other end of register.
Example, an 8-bit register containing binary value 10101111 shifted left cyclically three
places would become 01111101.
Left Shift – bits are shifted to left; gives direction of shift for logical, arithmetic and
cyclic shifts.
Right Shift – bits are shifted to right; gives direction of shift for logical, arithmetic and
cyclic shifts. Logical Shifts in Assembly Language Programming
In monitoring and control, each bit in a register can be used as a flag and would need to be
tested, set or cleared separately.
Example, control system with eight different sensors would need to record when data
from each sensor had been processed.
• AND is used to check if bit has been set.
• OR is used to set the bit.
• XOR is used to clear a bit that has been set.
Setting of All Bits To Zero:
LDD 0034 Loads byte into accumulator from an address 0034.
AND #B00000000 Uses bitwise AND operation of contents of ACC
With operand to convert each bit to 0.
STO 0034 Stores altered byte in original address.
*************************