4.3. Bit Manipulation Flashcards

1
Q

Left shift (LSL #n)

A
  • Bits are shifted to the left to multiply
  • E.g. to multiply by four, all digits shift two places to left
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Right shift (LSR #n)

A
  • Bits are shifted to the right to divide
  • E.g. to divide by four, all digits shift two places to right
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Logical shift

A

Zzeros replace the vacated bit position

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Arithmetic shift

A

Used to carry out multiplication and
division of signed integers represented by bits in the
accumulator by ensuring that the sign-bit (usually the
MSB) is the same after the shift.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Cyclic shift

A

The bit that is removed from one end by the
shift is added to the other end.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Bit Masking

A
  • Each bit can represent an individual flag.
    ∴ by altering the bits, flags could be operated upon.
    Bit manipulation operations:
  • Masking: an operation that defines which bits you
    want to keep and which bits you want to clear.
  • Masking to 1: The OR operation is used with a 1.
  • Masking to 0: The AND operation is used with a 0.
  • Matching: an operation that allows the
    accumulator to compare the value it contains to
    the given value in order to change the state of the
    status register.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Practical applications of Bit Masking

A

Setting an individual bit position:
* Mask the content of the register with a mask
pattern which has 0 in the ‘mask out’ positions and
1 in the ‘retain’ positions.
* Set the result with the match pattern by using the
AND command with a direct address.

Testing one or more bits:
* Mask the content of the register with a mask
pattern which has 0 in the ‘mask out’ positions and
1 in the ‘retain’ positions.
* Compare the result with the match pattern by
using the CMP command or by “Checking the
pattern”.

Checking the pattern
* Use AND operation to mask bits and obtain
resultant.
* Now subtract matching bit pattern from resultant.
* The final ‘non-zero’ result confirms the patterns
are not the same else vice versa.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly