DEV Community

Erik
Erik

Posted on

All you need to know about Assembly language

GUYS I AM NOT SO GREAT AT ASSEMBLY,so feel free to correct my errors

Let's start with the basics

Assembly is, for any given hardware platform ISA , the unstructured, lowest levels programming language -- it maps (mostly) 1:1 to machine code (the actual binary CPU instructions) and basically only differs from the actual machine code by utilizing a more human readable form. Assembly is compiled by assembler into the the machine code. Assembly is not a single language, it differs for every architecture, and is therefore not portable!

Typical Assembly Language

The language is unstructured, i.e. there are no control structures such as if or for statements: these have to be manually implemented using labels and jump instructions. The typical look of an assembly program is therefore a single column of instructions with arguments, one per line.

The working of the language reflects the actual hardware architecture -- usually there is a small number of registers (e.g. 16) which may be called something like R0 to R15. These registers are the fastest available memory (faster than the main RAM memory) and are used to perform calculations. Some registers are general purpose and some are special: typically there will be e.g. the FLAGS register which holds various 1bit results of performed operations (e.g. overflow, zero result etc.). Values can be moved between registers and the main memory.

Instructions are typically written as three-letter abbreviations and follow some unwritten naming conventions so that different assembly languages at least look similar. Common instructions found in most assembly languages are for example:

  • MOV (move): move a number between registers and/or memory.
  • JMP (jump): unconditional jump to far away instruction.
  • BEQ (branch if equal): jump if result of previous comparison was equality.
  • ADD (add): add two numbers.
  • NOP (no operation): do nothing (used e.g. for delays).
  • CMP (compare): compare two numbers and set relevant flags (typically for a subsequent conditional jump).

Assembly languages may offer simple helpers such as macros.

Top comments (0)