Assembly Language (ASM)

This garden is a work in progress. Some notes may be incomplete.

Table of Contents


Introduction

1. Historical Context

Before modern programming, computers were programmed using raw machine code. The bridge between human logic and machine execution was built in the early 1950s by Kathleen Booth, who invented the world's first Assembly Language and its accompanying Assembler while working on the APEC computer system.

2. The Purpose of Assembly

While rarely used to write full applications today, ASM is essential for:

3. How It Works (The Mechanics)

Assembly is not a universal language; it is strictly tied to a specific CPU Architecture (Instruction Set Architecture or ISA). Assembly code written for an Intel x86_64 chip will not run on an Apple ARM chip.

Core Components

  1. Opcode (Operation): What the CPU should do.
    • MOV: Move data.
    • ADD: Add numbers.
    • PUSH/POP: Interact with the stack.
    • JMP: Jump to a different line (Logic/Loop).
  2. Operands: What the CPU should perform the action on.
    • Registers: Tiny, ultra-fast storage slots physically located inside the CPU (e.g., EAX, RBX, RIP).
    • Memory Addresses: Locations in RAM (e.g., [0x401000]).
    • Immediates: Raw, hardcoded numbers (e.g., 5).

4. x86_64 Example & System Calls

To do anything outside of internal math (like printing “Hello World” to the screen or opening a file), Assembly code must request help from the Operating System kernel using a System Call (SYSCALL).

; A simple x86_64 logic block
MOV RAX, 5      ; Load the number 5 into the RAX register
ADD RAX, 3      ; Add 3 to the value in RAX (RAX is now 8)
CMP RAX, 10     ; Compare RAX (8) with 10
JLE LessThan    ; If 8 is Less or Equal to 10, Jump to the "LessThan" label
Powered by Forestry.md