4.3 Bit Manipulation

Specification

  • Show understanding of and perform binary shifts

    • logical, arithmetic and cyclic

    • left shift, right shift

  • Show understanding of how bit manipulation can be used to monitor/control a device

    • Carry out bit manipulation operations

    • Test and set a bit (using bit masking)

Instruction Set

Bitwise Manipulation

NOTE: The logic Instructions (especially AND, XOR, OR) are NOT given in the exam, unlike the instruction set in Paper 2 and Paper 4, so be familiar with them. It is likely that if LSL, LSR are used, these would be given, but there is no guarantee.

In summary, bitwise manipulation can be used in the following way:

Binary shifts

New to the 9618 specification is the requirement to perform logical, arithmetic and cyclic left and right shifts. In a given register, the value stored could represent a number, address or be used as a flag register (e.g. the interrupt register). With flag registers, each bit can denote a different thing, such as different types of triggered interrupt. The textbook (page 130) covers this topic in more detail.

Logical shift: As you shift left and right, the places are replaced with zeros. In any given register size, when shifting left or right, bits are lost when they move outside the boundary. E.g. in an eight bit register, 10110000 shifted left two places would become 1100000000, loosing the 10 at the start.

Arithmetic shift: The sign is preserved and each shift left or right will either multiply or divide by powers of 2 accordingly. Unlike logical shifting, arithmetic shifts can trigger underflow or overflow errors should the value grow larger than can be held by the register.

Cyclic shift: A simple shift whereby the bits are rotated either left or right by a number of places. Bits lost at either end are wrapped around to the other side. E.g. 11110000 shifted left 2 places becomes 1100000011.