Subtopic Notes

4.3 Bit manipulation

4. Processor Fundamentals

4.3 Bit manipulation

Bitwise Instructions

OpcodeOperandExplanation
AND#n /Bn/&nBitwise AND operation of the contents of ACC with the operand
AND<address>Bitwise AND operation of the contents of ACC with the contents of <address>
XOR#n/Bn/&nBitwise XOR operation of the contents of ACC with the operand
XOR<address>Bitwise XOR operation of the contents of ACC with the contents of <address>
OR#n/Bn/&nBitwise OR operation of the contents of ACC with the operand
OR<address>Bitwise OR operation of the contents of ACC with the contents of <address>
LSL#nBits in ACC are shifted logically n places to the left. Zeros are introduced on the right hand end
LSR#nBits in ACC are shifted logically n places to the right. Zeros are introduced on the left hand end

All questions will assume there is only one general purpose register available
(Accumulator)
ACC denotes Accumulator
IX denotes Index Register
<address> can be an absolute or symbolic address
# denotes a denary number, e.g. #123
B denotes a binary number, e.g. B0101010
& denotes a hexadecimal number, e.g. &4A

Shifts

Logical Shifts

  • Moving a binary value to the left or the right
  • Most significant bits (MSB) or the least significant bits (LSB) are lost
  • Shifting 1100 1010 two places to the left = 0010 1000
  • Each left shift multiplies the original number by 2 (Data may be lost)
  • Shifting 1100 1010 two places to the right = 0011 0010
  • Each right shift divides the original number by 2 (Data may be lost)

Arithmetic Shift: Shifts the bits of a binary number, while preserving the sign bit (usually the MSB)

Cyclic Shift: Bits which are removed from one end is added to the other

Bit Masking

  • Definition: Process of getting CPU to ignore the bits we don't want to work on and only to process digits we want to process
  • Used to check/change/remove individual bits within a binary value
  • Advantage: Less processing needed to perform a task
  • Application: Used in simple control systems where each bits represent a flag
  • Operations:
    • AND: Setting chosen bits to 0
      • AND 0: Sets value to 0
      • AND 1: Retains value
    • OR: Setting chosen bits to 1
      • OR 0: Retains value
      • OR 1: Sets value to 1
    • XOR: Inverting chosen bits or finding differences between
      • XOR 0: Retains the Value
      • XOR 1: Inverts the value