x64 assembly instructions
An instruction in x64 is a binary-encoded command that the CPU decodes and executes. These instructions manipulate data in registers, memory, or both. The x64 instruction set extends the 32-bit x86 architecture, introducing 64-bit registers and enhanced capabilities while retaining backward compatibility.
Some features of x64 instructions are :
- 64-bit Registers
- Extended Addressing Modes
- SIMD (Single Instruction, Multiple Data)
Classification of x64 Instructions
Arithmetic and Logical Instructions
- Arithmetic Instructions :
- ADD : Adds two values and stores the result in the destination operand. example: Code x86asm
;ADD source in destination and set the result value in destinataion ;ADD destination source ADD RAX, RBX; RAX = RAX + RBX
- SUB : Subtracts the source operand from the destination operand. Similer like ADD. example : Code x86asm
;SUB destination source SUB RAX, RBX ; RAX = RAX - RBX
- MUL : Multiplies the value (Unsigned) in the RAX register with the source operand. example : Assume if you want to multiply B in A then you have to first MOVE the value of A into RAX and use MUL B operation. It will store the multiplication result into 2 registers (RAX,RDX) if result is greater than 64 bits. Lower 64 bits are stored in RAX and upper 64 bits are stored in RDX registers.Code x86asm
; MUL source MUL RBX; RAX RDX = RAX * RBX
- IMUL : Multiplies signed integers. Variants exist for different operand counts. Example : Code x86asm
; If 1 operand IMUL RBX; Similer like MUL (RAX RDX) = RAX * RBX ; If 2 operands IMUL RCX, RBX ; RCX = RCX * RBX
- DIV : Divides RDX:RAX (128 bits) by the source operand. (RAX for lower 64 bits and RDX for higher) Code x86asm
DIV RBX ; Unsigned division of RDX:RAX by RBX ;Result quotient in RAX, remainder in RDX.
- IDIV : Divides RDX:RAX (128 bits) by the source operand (signed). It works same as DIV . Code x86asm
IDIV RBX ; Signed division of RDX:RAX by RBX
Logical operations :
- AND : Performs a bitwise AND between two operands and stores the result in the destination operand. Code x86asm
AND RAX, RBX ; RAX = RAX AND RBX
- OR : Performs a bitwise OR between two operands and stores the result in the destination operand. Also works same as AND operation but use OR. Code x86asm
OR RAX, RBX ; RAX = RAX OR RBX
- XOR : Performs a bitwise XOR (exclusive OR) between two operands and stores the result in the destination operand. Code x86asm
XOR RAX, RBX ; RAX = RAX XOR RBX
- NOT : Performs a bitwise NOT on the operand, flipping all bits (1 becomes 0, and 0 becomes 1) Code x86asm
NOT RAX ; RAX = NOT RAX
Data Transfer Instructions
- MOV : Transfers data from the source operand to the destination operand. Code x86asm
MOV RAX, RBX ; Copy the value of RBX into RAX MOV RCX, 42 ; Load the immediate value 42 into RCX
- PUSH / POP : PUSH decreases the stack pointer (RSP) and stores the value of the operand on the stack. POP retrieves the value at the top of the stack and increments the stack pointer (RSP). Code x86asm
PUSH RAX ; Push the value of RAX onto the stack POP RAX ; Pop the value from the top of the stack into RAX
- LEA : Loads the effective address of a memory operand into a register. This is often used to compute addresses or perform arithmetic without actually accessing memory Code x86asm
LEA RAX, [RBX + 4*RCX] ; Load the address of RBX + 4*RCX into RAX
- XCHG : Exchanges (swaps) the values of the two operands. Code x86asm
XCHG RAX, RBX ; Exchange the values of RAX and RBX
Control Flow Instructions
- Unconditional Jumps :
- JMP : Jump/start the execution of instructions from a Specified Address. Code x86asm
;JMP target ; use address/labels for jumping JMP _start;
- JMP : Jump/start the execution of instructions from a Specified Address.
- Conditional Jumps :
- JE / JZ :
- JNE / JNZ :
- JG / JNLE :
- JL / JNGE :
- Function Calls :
- CALL :
- RET :