CS Basics: Assembly Code Pt. 2
Logical instructions and bitwise operations - the building blocks of decision-making in computing, from NOT and AND to OR and XOR.
Originally written by Carl Mills · December 14, 2017
Understanding Logical Instructions
Logical instructions change bits to 0 or 1 based on specific rules. These simple binary manipulations power conditional logic in all modern programming languages.
NOT Instruction
The simplest logical operation. NOT inverts each bit - 0 becomes 1, and 1 becomes 0.
In: 0 0 0 1 1 1 0
Out: 1 1 1 0 0 0 1
NOT works on single binary inputs.
AND Instruction
The AND operation outputs 1 only if both input bits are 1. Otherwise, it outputs 0.
In1: 0 0 0 1 1 1 0
In2: 1 1 1 1 0 1 1
Out: 0 0 0 1 0 1 0
OR Instruction
The OR operation outputs 1 if either of the two input bits is 1. If both are 0, the result is 0.
In1: 0 0 0 1 1 1 0
In2: 1 0 1 1 0 1 0
Out: 1 0 1 1 1 1 0
XOR Instruction
The XOR (exclusive OR) operation outputs 1 only if the two input bits are different. If both are the same, it outputs 0.
In1: 0 0 0 1 1 1 0
In2: 1 0 1 1 0 1 0
Out: 0 0 1 0 1 0 0
Why Logical Instructions Matter
These basic operations are used across all levels of computing - from controlling data at the hardware level
to implementing if and else logic in high-level languages like C, C++, Python, and
JavaScript.
Every condition, loop, or comparison in software ultimately relies on these binary relationships between bits.
Next in the Series
In the next article, we'll explore how these logical operations evolve into conditional logic and control flow in higher-level languages.
Continue to CPU Architecture →