Article by Ayman Alheraki on January 11 2026 10:37 AM
In this section, we provide concrete, detailed examples for the primary instruction classes covered in this chapter. These examples illustrate typical usage patterns, operand encoding considerations, and highlight subtle nuances necessary for accurate assembly programming and assembler design.
MOV (Move Data) Moves data between registers, memory, and immediate values.
; Move immediate 0x10 into 64-bit register RAXmov rax, 0x10
; Move 32-bit register value ECX into EDXmov edx, ecx
; Move data from memory address pointed by RSI into RAXmov rax, [rsi]
; Move 128-bit XMM register to memory (aligned)movaps xmm0, [rbx]Considerations:
MOV supports various operand sizes: 8, 16, 32, and 64 bits in general registers; 128, 256, and 512 bits in SIMD registers with appropriate instructions.
Assembler must handle encoding with proper prefixes (REX for 64-bit, VEX/EVEX for SIMD).
MOV cannot directly move data between two memory locations.
ADD (Addition) and SUB (Subtraction)
; Add immediate value 5 to 64-bit register RAXadd rax, 5
; Subtract RBX from RDXsub rdx, rbx
; Add packed double-precision floats in XMM0 and XMM1, result in XMM2 (SSE)addpd xmm2, xmm1AND (Bitwise AND) and XOR (Exclusive OR)
; Perform bitwise AND between EAX and ECX, result in EAXand eax, ecx
; Exclusive OR to clear register (common idiom)xor rax, raxConsiderations:
Arithmetic instructions update RFLAGS, affecting conditional operations.
SIMD arithmetic requires correct prefixes and register width awareness.
Immediate operands have size and sign restrictions.
JMP (Unconditional Jump)
; Jump to label 'loop_start'jmp loop_startConditional Jumps (JE, JNE, JL, JG, etc.)
; Jump if zero flag is set (equal)je equal_label
; Jump if not equaljne not_equal_labelCALL and RET
; Call procedure at address stored in RAXcall rax
; Return from procedureretConsiderations:
Control flow instructions use relative or register/memory addressing.
Relative jumps support signed 8-bit or 32-bit offsets; assembler calculates displacement.
CALL pushes return address on stack; RET pops return address.
PUSH and POP
; Push RBP onto stackpush rbp
; Pop top of stack into RBPpop rbpENTER and LEAVE (Function Prologue/Epilogue)
; Allocate 32 bytes of stack frame and save previous base pointerenter 32, 0
; Restore base pointer and deallocate stack frameleaveConsiderations:
PUSH and POP update RSP accordingly.
ENTER and LEAVE manage stack frames automatically but are less commonly used in modern optimized code.
Assembler must encode operand size correctly (16/32/64-bit variants).
MOVSB and MOVSW (Move String Byte/Word)
; Move byte from [RSI] to [RDI], increment RSI and RDImovsbLODSB (Load String Byte)
; Load byte from [RSI] into AL, increment RSIlodsbSTOSB (Store String Byte)
xxxxxxxxxxasmCopyEdit; Store AL into [RDI], increment RDIstosb
Considerations:
REP prefixes can repeat instructions for block moves or scans.
Direction Flag (DF) affects increment/decrement of RSI and RDI.
Useful for memory initialization, copying, or searching.
HLT (Halt Processor)
hltCLI and STI (Clear/Set Interrupt Flag)
cli ; Disable interruptssti ; Enable interruptsSYSENTER / SYSEXIT (Fast System Calls)
sysenterConsiderations:
Privileged instructions; usage restricted to ring 0.
Essential for OS kernel and system-level programming.
Assembler must support proper instruction encoding and privilege checks.
Packed Addition with SSE
; Add packed single-precision floats in xmm1 to xmm0addps xmm0, xmm1AVX256 Vector Multiply
; Multiply packed double-precision floats in ymm1 and ymm2, result in ymm0vmulpd ymm0, ymm1, ymm2AVX-512 Masked Blend
; Blend xmm1 and xmm2 based on mask k1, store result in xmm0vblendmps xmm0 {k1}, xmm1, xmm2Considerations:
Proper VEX and EVEX prefix encoding critical for AVX and AVX-512 instructions.
Mask registers control conditional execution in AVX-512.
SIMD instructions have strict operand alignment and size requirements.
These detailed examples provide a foundational understanding of typical instructions from each primary category. For assembler implementation, supporting correct operand encoding, prefix management, and operand size handling are essential. Understanding instruction semantics and side effects on processor state (e.g., flags, registers, memory) enables robust assembler design and accurate machine code generation.