Logical Operators and Bit Shifting

From ROM Detectives Wiki
(Redirected from LSR)
Jump to navigation Jump to search

The 6502 Microprocessor supports the logical operators AND, OR, and XOR and bit shifting operators Shift Left and Shift Right, Rotate Left and Rotate Right.


AND

AND performs a logical AND on an entire byte. The result switches all bits to 0 unless both are 1. Below is a truth table for every possible condition at the bit level.

Bits 1 0 0 1 1
Bits 2 0 1 0 1
Result 0 0 0 1

OR

OR performs a logical OR on an entire byte. The result switches all bits to 1 if any bit is 1, and 0 if both bits are 0. Below is a truth table for every possible condition at the bit level.

Bits 1 0 0 1 1
Bits 2 0 1 0 1
Result 0 1 1 1

Exclusive OR (XOR)

XOR performs a logical Exclusive OR on an entire byte. The result switches all bits to 1 if they are different or 0 if they are the same. Below is a truth table for every possible condition at the bit level.

Bits 1 0 0 1 1
Bits 2 0 1 0 1
Result 0 1 1 0

Shift Left

Shift Left moves each bit in a byte one space to the left. The left-most bit is removed, and the empty space is filled with a 0. The removed bit is saved and placed in the carry flag.

Original Byte 1 0 1 0 1 1 1 1
Shifted Byte 0 1 0 1 1 1 1 0

Shift Right

Shift Right moves each bit in a byte one space to the right. The right-most bit is removed, and the empty space is filled with a 0. The removed bit is saved and placed in the carry flag.

Original Byte 1 0 1 0 1 1 1 1
Shifted Byte 0 1 0 1 0 1 1 1

Rotate Left

Rotate Left moves each bit in a byte one space to the left. The left-most bit wraps around to the other side, filling the empty space created by moving each bit.

Original Byte 1 0 1 1 1 0 0 0
Shifted Byte 0 1 1 1 0 0 0 1

Rotate Right

Rotate Right moves each bit in a byte one space to the right. The right-most bit wraps around to the other side, filling the empty space created by moving each bit.

Original Byte 0 0 0 0 0 1 1 1
Shifted Byte 1 0 0 0 0 0 1 1