Logical Operators and Bit Shifting

From NES Hacker Wiki
Jump to: navigation, search

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


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

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 thrown away, and a the empty space is filled with a 0.

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 thrown away, and a the empty space is filled with a 0.

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