CS Basics: Assembly Code Pt. 1

Understanding how assembly language translates human logic into raw machine operations - one level above binary, yet still close to the metal.

Originally written by Carl Mills · December 13, 2017

From Machine Code to Assembly

CPUs work through billions of transistors switching between off (0) and on (1) - this is machine code. Assembly language is one step above: a readable set of commands that map directly to those binary instructions.

Copy Instructions

Used to move or duplicate data between locations.

  • MOV - copies data to a new location
  • LD - loads data into a register
  • ST - stores data from a register to memory

Arithmetic Instructions

These operate in the accumulator register and handle basic math operations.

  • ADD - addition
  • SUB - subtraction
  • MUL - multiplication
  • DIV - division

Jump Instructions

Control the order in which instructions execute - similar to if statements in higher-level languages.

  • JP NEXT - jump to the instruction labeled NEXT
  • JE - jump if equal
  • JZ - jump if zero

These allow the program to make decisions or repeat operations based on conditions.

Shift Instructions

Move all bits in a byte left or right.

Logical Shifts

Insert a 0 in the newly empty position:

Shift right logical: 11011101 → 01101110
Shift left logical:  11011101 → 10111010
Arithmetic Shifts

Maintain the arithmetic value of the byte:

  • Shift left fills the Least Significant Bit (LSB) with 0
  • Shift right keeps the Most Significant Bit (MSB) the same
Rotations

Rotate bits around to the opposite end:

Rotate left:  (1)1011101 → 1011101(1)
Rotate right: 1101110(1) → (1)1101110

Why Assembly Still Matters

Although rarely used directly today, every modern language compiles down to assembly. Knowing how it works deepens your understanding of what your code really does - how data moves, how loops branch, and how efficiency is achieved.

Assembly development remains a niche craft, but it's the foundation from which all higher-level programming languages evolved.

Next in the Series

In Part 2, we'll explore logical operators - AND, OR, XOR, and NOT - and how they shape every operation at the binary level.

Continue to Logical Operators →