Instruction Set and Assembler Directives in Assembly Language (MASM)
When you're learning assembly language programming, it's important to understand
the Instruction Set and Assembler Directives. These are the fundamental parts of an
assembly program.
The Instruction Set is a collection of commands (instructions) that a processor can
execute. Each instruction includes an opcode (operation code) and, sometimes, one or
more operands. It's worth noting that the instruction set is specific to a particular
architecture, such as x86 for MASM.
Categories of Instructions
The instruction set can be categorized into several groups based on the function of the
instructions:
1. Data Transfer Instruction
2. Arithmetic Instructions
3. Logical Instructions
4. Control Transfer Instructions
5. Bit Manipulation Instructions
1. Data Transfer Instructions
These instructions move data between registers, memory, and I/O devices.
Instruction
MOV
Syntax
MOV dest, source
PUSH
POP
PUSH reg/mem/imm
POP reg/mem
XCHG
IN
OUT
XCHG reg, reg/mem
IN AX, DX
OUT DX, AX
Description
Moves data from the source to the
destination
Pushes the operand onto the stack
Pops the top of the stack into the
operand
Exchanges the contents of two operands
Reads data from an I/O port
Sends data to an I/O port
Example:
MOV AX, BX
; Moves data from BX to AX
PUSH AX
; Pushes AX onto the stack
POP CX
; Pops the top of the stack into CX
XCHG AX, BX
; Exchanges the values of AX and BX 2. Arithmetic Instructions**
These perform basic arithmetic operations like addition, subtraction, multiplication,
and division.
Instruction
ADD
SUB
MUL
DIV
INC
DEC
Syntax
ADD dest, source
SUB dest, source
MUL reg/mem
DIV reg/mem
INC reg/mem
DEC reg/mem
Description
Adds source to destination
Subtracts source from destination
Multiplies unsigned AX by the operand
Divides AX by the operand
Increments the operand by 1
Decrements the operand by 1
Example
ADD AX, BX
; Adds BX to AX
SUB AX, 1
; Subtracts 1 from AX
MUL BX
; Multiplies AX by BX, result in DX:AX
DIV BX
; Divides AX by BX, quotient in AX, remainder in DX
3. Logical Instructions
These instructions perform bitwise logical operations like AND, OR, XOR, and NOT.
Instruction
AND
Syntax
AND dest, source
OR
OR dest, source
XOR
XOR dest, source
NOT
TEST
NOT reg/mem
TEST dest, source
Description
Performs bitwise AND between dest and
source
Performs bitwise OR between dest and
source
Performs bitwise XOR between dest and
source
Inverts the bits of the operand
Performs AND but doesn't store result
Example:
AND AX, BX
OR AX, 1
XOR AX, BX
NOT AX
TEST AX, BX
; Bitwise AND between AX and BX
; Bitwise OR between AX and 1
; Bitwise XOR between AX and BX
; Bitwise NOT of AX
; Tests if any bit in both AX and BX is set 4. Control Transfer Instructions
These instructions control the flow of the program, like jumping to different parts of the
code or calling procedures.
Instruction
JMP
JE/JZ
JNE/JNZ
CALL
RET
INT
Instruction
JMP
JE/JZ
JNE/JNZ
CALL
RET
INT
Syntax
JMP label
JE/JZ label
JNE/JNZ label
CALL label
RET
INT n
Syntax
JMP label
JE/JZ label
JNE/JNZ label
CALL label
RET
INT n
Description
Unconditional jump to label
Jump if equal/zero flag is set
Jump if not equal/zero flag is clear
Calls a procedure
Returns from a procedure
Software interrupt
Description
Unconditional jump to label
Jump if equal/zero flag is set
Jump if not equal/zero flag is clear
Calls a procedure
Returns from a procedure
Software interrupt
Example:
CMP AX, BX
; Compare AX with BX
JE EQUAL
; Jump to label EQUAL if AX == BX
JMP NEXT
; Unconditionally jump to NEXT
EQUAL:
MOV CX, 0
; If AX == BX, execute this
NEXT:
5. Bit Manipulation Instructions
These instructions shift and rotate bits within a register or memory operand.
Instruction
SHL/SAL
SAL
Syntax
SHL dest, count
SAL destination, count
Description
Shift logical left
Shift Arithmetic Left
Instruction Set and Assembler Directives in Assembly Language
of 3
Report
Tell us what’s wrong with it:
Thanks, got it!
We will moderate it soon!
Free up your schedule!
Our EduBirdie Experts Are Here for You 24/7! Just fill out a form and let us know how we can assist you.
Take 5 seconds to unlock
Enter your email below and get instant access to your document