x86, x64 and a little bit of ARM...

Created: 2019-02-10

Acroynms / Terminology

Register types & quanities

Memory Models

Assembly language

InstructionNotes
MOV D, SMove (S)ource into (D)estination
LEAQ D, SLoad effective address (S) into (D)
IMUL D,S
IMULQ S
MULQ S
IDIVQ S
DIVQ S
Signed multiplication of rax by (S), with result placed in dx:ax
Unsiged version of above.
Signed divide of dx:ax by S, with result stored in dx and remainder in ax
Unsigned version of abovce
SAL D, bits
SAR D, bits
(S)hift (A)rthimetic (L)eft/(R)right.
Shift D bits to the (L)eft or (R)ight, preserving the highest order bit (i.e. the sign) and setting lowerest order bit to zero.
SAR D, bits
SHL D, bits
(S)hift (H)? (L)eft/(R)ight
Shift D bits as above, but set highest order bit to zero.
NEG D
NOT D
Arithmetic negation of (D) e.g. 0 - D
Bitwise complement of (D). e.g. 1001 -> 0110
CTWL
CLTQ
CQTO
(C)onvert 8-bit ax (T)o 32-bit (L)ong, maintaining sign (W?) and place result in eax
(C)onvert eax (L) (T)o 64-bit (Q)uardword maintaining sign and place result in rax
(C)onvert rax (Q)uadword (T)o 128-bit (O)ctoword
COM S1, S2
TEST S1, S2
Set flags for S1-S2
Set flags for S1 boolean AND S2 ?? TODO ??
SETE [SETNE]
SETZ [SETNZ]
SETS [SETNS]
SETG / SETNLE
SETGE / SETNL
(SE)t if equal / (Z)ero flag set. [Inverse]
SE)t if not equal / (Z)ero flag not set. [Inverse]
(SE)t if negative / (S)igned flag is set. [Inverse]
(SE)t if (G)reater than / (N)ot (L)ess or (E)qual to.
(SE)t if (G)reater than or (E)qual to / (N)ot (L)ess than.
PUSHFD / POPFDPushes / pops the eFlags register to / from the stack ?? What does the D stand for? ??

x86

Registers

Calling conventions

x64

Registers

name64-bit32-bit16-bit8-bit (bits 7-0)8-bit (bits 15-8)Intel special use notes (p 3-11)
Register A ExtendedraxaxaxalahAccumulator for operands and results data
Register B ExtendedrbxbxbxblbhPointer to data in the DS segment
Register C ExtendedrcxcxcxclchCounter for string and loop operations
Register D ExtendedrdxdxdxdldhI/O pointer
Register Source IndexrsisisisilPointer to data in the segment pointed to by the DS register; source pointer for string operations
Register Destination IndexrdidididilPointer to data (or destination) in the segment pointed to by the ES register; destination pointer for string operations
Stack PointerrspspspsplStack pointer (in the SS segment)
Base PointerrbpbpbpbplPointer to data on the stack (in the SS segment)
Register 8 - 15r8 - r15r8-15dr8-15wr8-15b

Status Flags in EFLAGS register
(Intel notes p. 3-15)
Flags usable with CMPxx (compare), SETxx (set if), Jxx (jump if) etc instructions:
BitShort nameFull nameNotes
0CFCarry FlagSet if borrow or carry outside of the most-significant bit of the number
2PFParity FlagSet if the least significant byte of the result contains an even number of 1 bits
4AFAuxillary carry FlagSet if borrow or carry outside of bit three (used with BCD)
6ZFZero FlagSet is result is zero
7SFSign FlagSet to the most significant bit of the result (1 = negative, 0=positive)
11OFOverflow flagSet if the result is (ignoring the sign bit) too big to fit the datatype

Only the CF flag can be set directly (?? why would we want to? ??)

Other Flags
BitShort nameFull nameNotes
10DFDirection flagControls whether string instruction (MOVS, CMPS, etc) to process downwards (set) or upwards (unset). Flag is set/unset via the STD/CLD instructions.

Calling conventions

Example: call myAdd(1, 15)

movq rdi, $1

movq rsi, $15

call myAdd

# 16 returned in rax

ARM

Common patterns

Segment addressing

Segmentation dates back to the 8086 / 8088 days (1978). The 20-bit address space (1 meg) was managed using a 4-bit segmentation register in addition to a normal 16-bit (64K) address schema. Support for four segment registers mean 256KB could be accessed without switching segments.

286 processors (1982) use the segment registers as pointers into description tables containing 24-bit base addresses (16MB), and added virtual memory management on a segment swapping basis. Segment could be marked read-only or execute-only.

386 processors (1985) introduced 32-bit processors, and a virtual 8086 mode. 32-bit means 4GB of memory support directly, but segmented also supported. Virtual memory management supported on a 4K page basis. First parallel stage support.

486 (1989) improved parallel staging. First on-chip cache (8K). Integrate FPU.

Pentium onwards (1993-...). Nothing interesting from the perspective of this level of programming.

References