less_retarded_wiki/assembly.md

22 lines
2.1 KiB
Markdown
Raw Normal View History

# Assembly
2023-01-01 14:58:49 +01:00
*GUYS I AM NOT SO GREAT AT ASSEMBLY, correct my errors*
2023-01-01 14:58:49 +01:00
Assembly is, for any given hardware platform ([ISA](isa.md)), the unstructured, lowest levels [programming language](programming_language.md) -- it maps (mostly) 1:1 to [machine code](machine_code.md) (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](assembler.md) into the the machine code. Assembly is **not** a single language, it differs for every architecture, and is therefore not [portable](portability.md)!
## 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.