Assembly Playground - Help
Reference page for the simulator. Covers everything implemented in this small version of x86 assembly.
Registers
Registers are small storage slots inside the CPU, almost like pre-made variables! There are 4 general purpose ones (a, b, c, d) and each one has 4 names that all point to different parts of the same 32-bit value.
eax is the full 32-bit register. ax is the lower 16 bits of it, and ah/al are the two halves of ax. They all point to the same value, so changing one affects the others.
ebx, ecx and edx work exactly the same way with their own sub-registers (bx/bh/bl, etc).
Special registers
These dont have sub-registers, they each just do one specific thing.
*note: currently only eip and esp have functionality attached to them.
Floating Point Registers
The registers st0 - st7 are all specifically designed to handle floating point values. Attempting to store a float like 3.14 in eax would end up clamping the value and reducing it simply to 3.
Unlike the general purpose registers, the float registers work as a stack. This means you don't write to them directly. Instead you push and pop values using fld and fstp. st0 is always the top of the stack, and pushing a new value shifts everything down.
For example, if you load two values with fld, the first one ends up in st1 and the second in st0, since st0 is always the most recently pushed value.
*note: these registers are based on the x87 FPU registers from real x86, but simplified. Real x87 uses 80-bit extended precision internally, while this emulator uses 64-bit double precision.
Flags
Flags are set automatically after arithmetic and cmp instructions. the jump instructions then read them to decide whether to jump or not.
Memory
The simulator has 1MB of memory. (Indexing starts at 0x100) You access it by wrapping an address in square brackets.
mov ebx, [0x1000] ; read from 0x1000 into ebx
mov [eax], 42 ; use eax as the address
*note: reads and writes are (almost) always 32-bit (4 bytes at once). writing to address 0x100 also changes 0x101, 0x102 and 0x103.
Sections
Sections split your program into named regions. section .text holds your instructions and section .data holds values that exist before your program runs.
*note: the .text section is where execution starts. any instructions placed outside a section are assumed to be in .text.
Data Declarations
Variables are declared in the section .data block using a name, size keyword, and initial value.
When you reference a data variable by name in the text section, you get its memory address. Use square brackets to read the actual value.
x dd 42
section .text
mov eax, [x] ; eax = 42 (read value)
mov ebx, x ; ebx = address of x
Strings are stored in a db, they must be null-terminated to work correctly. (see example)
msg db "string", 0 ; null-terminated string, add ', 0'
section .text
mov eax, msg ; move the address of 'msg' into eax
println [eax] ; loops over the string until it hits the null-terminator
println eax ; prints the address of the first character in the string
Macros
Macros are text replacements. Use %define to create a macro that gets replaced everywhere it appears.
%define BUFFER_SIZE 1024
mov ecx, MAX_COUNT ; becomes mov ecx, 100
add edi, BUFFER_SIZE ; becomes add edi, 1024
*note: macros are case-insensitive and get replaced before any other processing happens. they are purely replacing text with their value.
Data movement
mov ebx, eax
mov [0x200], eax
Arithmetic
fld [pi]
je .done
Bitwise Operations
These work on individual bits instead of whole numbers.
Jumps
These move execution to a label. the conditional ones check flags set by the last compare.
je .equal
jne .loop
jg .big
jl .small
.start:
loop .start ; repeats 5 times
*note: always put cmp right before a jump or the flags might be wrong from a previous instruction.
Stack and calls
The stack is a region of memory that grows downward. esp points to the top of it.
push eax
call .func
.func:
mov eax, 99
ret
Misc
print "hello"
println "hello"
printi 42
printfl 3.14
*note: some of the 'Misc' instructions are not real x86 instructions.
Syntax
Comments
Labels
A label is just a name followed by a colon. The dot at the start is optional but often used to make labels easier to distinguish from variables and other identifiers.
dec ecx
jne .loop
Numbers
mov eax, 0xFF ; same value in hex
Memory references
mov ebx, [eax] ; treat eax as a memory address and read from it
; to get the address of a variable, remove the brackets
mov eax, myVar
*note: everything is case-insensitive so MOV, mov and mOv all work fine.