Basic Arithmetic
ADD
SUB
INC
DEC
MUL
Multiplies eax
by a value and stores the result 64-bit value across edx:eax
:
mul value
mul 0x10
DIV
Divides one number by another
DIV arg
Some forms:
- arg of size 8 bits:
al <- ax / arg; quotient
ah <- ax % arg; remainder
- arg of size 16 bits:
ax <- dx:ax / arg
dx <- dx:ax % arg
- arg of size 32 bits:
eax <- edx:eax / arg
edx <- edx:eax % arg
Examples:
div ch
: dividesch
and stores the division result insideal
. The remainder is stored insideah
.div esi
: dividesedx:eax
byesi
. Stores the quotient insideeax
. Stores the remainder insideedx
.div di
: dividesdx:ax
bydi
. Stores the quotient insideeax
. Stores the remainder insideedx
.
edx:eax
is the extension of edx:eax
so:
mv edx, '20' ; edx:eax is now 0000002000000000
mv ebx, '3A'
div ebx ; divide edx:eax by ebx ==> eax= 8D3DCB0, edx=30 (remainder)
div bx
; divide ax:dx by bx ==>
bx == 3A
dx:ax== 30CB08
ax == D75C (quotient)
dx == 0 (remainder)