assembly

Synopsis

Assembly language is a low-level programming language for a computer, or other programmable device, in which there is a very strong (but often not one-to-one) correspondence between the language and the architecture’s machine code instructions. Each assembly language is specific to a particular computer architecture in use. In contrast, most high-level programming languages are generally portable across multiple architectures but require interpreting or compiling.

Assembly Language Instructions

InstructionDescription
ADDAdds two operands
ADCAdds two operands with carry
ANDPerforms bitwise AND on two operands
CALLCalls a subroutine
CBWConverts byte to word
CLCClears carry flag
CMCComplements carry flag
CMPCompares two operands
CWDConverts word to double word
DAAAdjusts after addition
DASAdjusts after subtraction
DECDecrements operand by 1
DIVDivides two operands
HLTHalts the processor
IDIVDivides two signed operands
IMULMultiplies two signed operands
INInputs a byte from a port into accumulator
INCIncrements operand by 1
INTPerforms interrupt
IRETReturns from interrupt
JAJumps if above (CF=0 and ZF=0)
JAEJumps if above or equal (CF=0)
JBJumps if below (CF=1)
JBEJumps if below or equal (CF=1 or ZF=1)
JCJumps if carry (CF=1)
JCXZJumps if CX register is 0
JEJumps if equal (ZF=1)

Assembly Language Registers

RegisterDescription
AXAccumulator
BXBase
CXCount
DXData
SISource Index
DIDestination Index
BPBase Pointer
SPStack Pointer
CSCode Segment
DSData Segment
SSStack Segment
ESExtra Segment
IPInstruction Pointer
FLAGSFlags

Assembly Language Directives

DirectiveDescription
DBDefines a byte
DWDefines a word
DDDefines a double word
DQDefines a quad word
DTDefines a ten byte
DODefines a double quad word
DDQDefines a double double quad word
DDTDefines a double ten byte
EQUDefines a constant
ENDEnds a program
EXTERNDeclares an external variable
GLOBALDeclares a global variable
INCLUDEIncludes a file
INCBINIncludes a binary file
LABELDefines a label
ORGDefines an origin
PROCDefines a procedure
REPTRepeats a block of code
SEGMENTDefines a segment
STRUCDefines a structure
SUBSTRUCDefines a substructure
ENDSEnds a structure

Assembly Language Macros

MacroDescription
%defineDefines a macro
%macroDefines a macro
%endmacroEnds a macro
%reptRepeats a block of code
%endreptEnds a repeat block
%ifDefines an if statement
%elseDefines an else statement
%endifEnds an if statement
%includeIncludes a file
%errorDisplays an error message
%warningDisplays a warning message
%lineDefines a line number
%localDefines a local variable
%exitmacroExits a macro
%exitrepExits a repeat block
%exitExits a macro or repeat block
%assignAssigns a value to a variable
%evalEvaluates an expression
%strlenReturns the length of a string
%substrReturns a substring
%substrcountReturns the number of substrings
%substrindexReturns the index of a substring
%substrreplaceReplaces a substring
%substrsplitSplits a string into substrings
%substrtrimTrims a string
%substrtrimleftTrims the left side of a string
%substrtrimrightTrims the right side of a string

Assembly Language Data Types

Data TypeDescription
BYTE8-bit unsigned integer
WORD16-bit unsigned integer
DWORD32-bit unsigned integer
QWORD64-bit unsigned integer
TBYTE80-bit unsigned integer
OWORD128-bit unsigned integer
YWORD256-bit unsigned integer
ZWORD512-bit unsigned integer

Assembly Language Operators

OperatorDescription
+Addition
-Subtraction
*Multiplication
/Division
&Bitwise AND
|Bitwise OR
^Bitwise XOR
~Bitwise NOT
<<Bitwise left shift
>>Bitwise right shift
==Equality
!=Inequality
<Less than
<=Less than or equal
>Greater than
>=Greater than or equal
&&Logical AND
||Logical OR
!Logical NOT
?Ternary operator

Assembly Language Comments

CommentDescription
;Comment
//Comment
/*Comment
*/Comment

Assembly Language Examples

ExampleDescription
MOV AX, 0x1234Moves 0x1234 into AX
MOV [0x1234], 0x5678Moves 0x5678 into memory location 0x1234
ADD AX, BXAdds the contents of BX to AX
SUB AX, BXSubtracts the contents of BX from AX
INC AXIncrements AX by 1
DEC AXDecrements AX by 1
MUL BXMultiplies AX by BX
DIV BXDivides AX by BX
AND AX, BXPerforms a bitwise AND on AX and BX
OR AX, BXPerforms a bitwise OR on AX and BX
XOR AX, BXPerforms a bitwise XOR on AX and BX
NOT AXPerforms a bitwise NOT on AX
SHL AX, 1Shifts AX left by 1 bit
SHR AX, 1Shifts AX right by 1 bit
CMP AX, BXCompares AX and BX
JZ 0x1234Jumps to 0x1234 if the zero flag is set
JNZ 0x1234Jumps to 0x1234 if the zero flag is not set
JA 0x1234Jumps to 0x1234 if the carry flag is set