💻

Assembly Language Overview

Aug 19, 2025

Overview

This lecture introduces Assembly language, explaining its role as a bridge between high-level code and machine hardware, key components, and practical uses.

What is Assembly Language?

  • Assembly language is a low-level programming language close to machine code and hardware.
  • It lets programmers directly control the CPU and memory for optimized performance.
  • Each Assembly instruction performs a specific, simple operation.
  • Used in performance-critical areas like embedded systems, device drivers, and operating systems.

Basic Components of Assembly

  • Assembly programs consist of instructions and operands that specify actions and data.
  • Mnemonics are human-readable abbreviations (e.g., MOV, ADD, JMP) for instructions.
  • Registers are small, fast CPU storage areas where data is held during operations.
  • Assembly syntax is architecture-specific; code for one CPU (e.g., x86) won’t run on another (e.g., ARM).

CPU Registers and Flags

  • Registers are high-speed memory spots in the CPU for data and instructions during processing.
  • Types include general-purpose (for various data), special-purpose (instruction register, program counter), and status registers (hold CPU state flags).
  • Flags are status bits set by operations; examples include Zero, Carry, Overflow, and Sign flags.
  • Flags guide program flow, especially in conditional instructions and jumps.

Memory and Addressing Modes

  • Memory stores data while addressing modes define how instructions access this data.
  • Immediate addressing uses values directly in instructions.
  • Direct addressing accesses a specific memory address.
  • Indirect addressing uses a register to point to a memory address.

Basic Assembly Instructions

  • Arithmetic: ADD, SUB, MUL, DIV for math operations.
  • Logic: AND, OR, XOR, NOT for bitwise calculations.
  • Control: JMP, CMP, JE, JNE for flow control and comparisons.
  • Data movement: MOV (data transfer), PUSH (save to stack), POP (retrieve from stack).
  • Bit manipulation: SHL, SHR (bit shifts), ROL, ROR (bit rotations).

Fetch-Decode-Execute Cycle

  • Fetch: CPU retrieves next instruction from memory using the program counter.
  • Decode: CPU interprets the instruction and identifies needed operands.
  • Execute: CPU performs the operation, and the cycle continues for each instruction.

Practical Example

  • Load values into registers, perform ADD, use AND to check if the sum is even/odd, use conditional jumps to update result strings.

Real-World Applications

  • Assembly is vital in embedded systems, game consoles, device drivers, and some operating system components for efficiency and control.

Limitations of Assembly

  • Assembly is complex, verbose, and architecture-specific (not portable).
  • Development takes longer and requires detailed hardware knowledge.
  • Lacks libraries and built-in features found in high-level languages.

Key Terms & Definitions

  • Assembly Language — Low-level code providing direct hardware control.
  • Register — Fast CPU storage for temporary data.
  • Flag — Status bit showing results or conditions during execution.
  • Mnemonic — Short, human-readable instruction code.
  • Addressing Mode — Method for specifying where data is accessed in memory.

Action Items / Next Steps

  • Review basic Assembly instructions and their categories.
  • Practice writing simple Assembly code to reinforce concepts.
  • Explore real-world uses of Assembly in embedded systems or device drivers.