Module 2 - Addressing Modes V5.0
Module 2 - Addressing Modes V5.0
School of Engineering
IV Semester 2018-19
Module - 2
Machine Language
Machine language consists of strings of binary numbers (i.e. 0s and 1s) and it is
the only one language, the processor directly understands. Machine language has
Merits of very fast execution speed and efficient use of primary memory.
Merits:
• It is directly understood by the processor so has faster execution time since the
programs written in this language need not to be translated.
• It doesn’t need larger memory.
Demerits:
• It is very difficult to program using 1GL since all the instructions are to be
represented by 0s and 1s.
• Use of this language makes programming time consuming.
• It is difficult to find error and to debug.
• It can be used by experts only.
Low Level Languages
Assembly Language
This language uses mnemonics code (symbolic operation code like ‘ADD’ for
addition) in place of 0s and 1s. The program is converted into machine code by
assembler. The resulting program is referred to as an object code.
Merits:
• It is makes programming easier than 1GL since it uses mnemonics code for
programming. Eg: ADD for addition, SUB for subtraction, DIV for division, etc.
• It makes programming process faster.
• It is easier to debug than machine language.
Demerits:
• Programs written in this language is not directly understandable by computer so
translators should be used.
• It is hardware dependent language.
High Level Language
• High level languages are machine independent languages. Programs written for
a particular machine can run on other machines also.
ADD AX, Y
ADD AX, Z
Arithmetic Instructions
ADC − ADD with carry
Operands: REG, memory; memory, REG; REG, REG;
memory, immediate; REG, immediate;
This instruction adds the source operand to the destination operand along
with the carry flag. The result is stored in the destination operand. This
instruction is used to add the data which are of large in size, i.e., double
word type. Both ADD and ADC instructions affect the flags identically.
Example: addition of the two numbers 12345678H with FEDB4321H with the
help of ADC Instruction.
MOV AX, 5678H
ADD AX, 4321H
MOV BX, 1234H
ADC BX, FEDBH
Arithmetic Instructions
INC − Increment
Used to increment the provided byte/word by 1.
Operand: REG; memory;
Increment the operand by 1. This instruction increments the destination
operand by 1.
This instruction differs with the ADD by 1 instruction in the way that the INC
instruction does not affect the carry flag whereas the ADD instruction
modifies the carry flag.
The INC instruction is more compact and often faster than the comparable
ADD instruction because it is one byte instruction
In INC all flags, except the carry flag, changes.
Arithmetic Instructions
AAA − no operands ASCII Adjust after Addition
Used to adjust ASCII after addition.
AAA converts the result of the addition of two valid unpacked BCD digits to a
valid packed BCD number. AL register is the implied operand.
The decimal numbers in ASCII have a code from 30H (“0”) to 39H (“9”).
When we add two ASCII numbers, the result will not be in ASCII. The AAA
instruction will adjust the result of addition to a BCD digit. The instruction
assumes that the odd operands are proper ASCII values.
If the addition produces carry (AF=1), the AH register is incremented and
the carry CF and auxiliary carry flags are set to 1. If the addition did not
produce a decimal carry, CF and AF are cleared to 0 and AH is not altered.
In both cases the higher 4-bits of AL are cleared to 0.
Arithmetic Instructions
DAA − no operands, Decimal adjust after accumulation
Used to adjust the decimal after the addition/subtraction operation.
The DAA instruction adjusts the result of an addition to a packed BCD
number. DAA converts the binary sum to packed BCD format. If the sum is
greater than 99H after adjustment, then the carry and auxiliary carry flag
are set. Otherwise, the carry and auxiliary carry flags are cleared.
For example, two BCD values are added as if they were binary numbers and
the result will be in binary and then to convert this binary sum the DAA
instruction is executed to correct the result in BCD. The DAA instruction is
executed to correct the result in BCD. The DAA functions like AAA except it
handles packed BCD values rather than unpacked. All flag bits are modified
as per the result.
Arithmetic Instructions
Instructions to perform subtraction
SUB − Used to subtract the byte from byte/word from word.
SBB − Used to perform subtraction with borrow.
DEC − Used to decrement the provided byte/word by 1.
NPG − Used to negate each bit of the provided byte/word and add 1/2’s
complement.
CMP − Used to compare 2 provided byte/word.
AAS − Used to adjust ASCII codes after subtraction.
DAS − Used to adjust decimal after subtraction.
Arithmetic Instructions
Instructions to perform subtraction
SUB − subtraction
Used to subtract the byte from byte/word from word.
Operands: REG, memory; memory, REG; REG, REG;
memory, immediate; REG,
immediate;
This instruction subtracts the source operand from the destination operand
and stores in the result in the destination operand. Segment registers
cannot be used as an operand in ADD instruction. Memory to memory and
IO to memory addition is not permitted. Flag bits are modified as per the
result of the operation.
Example: MOV AL, 05H; SUB AL, 02H;
After the execution of the SUB instruction AL with 03H.
Arithmetic Instructions
SBB − Subtract with borrow.
Used to perform subtraction with borrow.
Operands: REG, memory; memory, REG; REG, REG;
memory, immediate; REG, immediate;
This instruction subtracts the source from the destination along with the
value of the carry flag. The result is stored in the destination. This
instruction is used to subtract data which are of large in size, i.e. double
word type.
DEST operand = DEST operand – SRC operand – Carry flag.
The carry flag will set if an unsigned overflow occurs during the SUB and
SBB instructions.
Arithmetic Instructions
DEC − Decrement
Used to decrement the provided byte/word by 1.
Operand: REG
memory
This instruction decrements the destination operand by 1. This instruction
differs with the SUB by 1 instruction in the way that the DEC instruction
does not affect the carry flag whereas the SUB instruction affects the carry
flag. The DEC instruction is more compact and often faster than the
comparable ADD instruction because it is a one-byte instruction. In DEC
except the carry flag all other flag changes as that of in SUB and SBB
instructions.
Arithmetic Instructions
NEG − Negate
Used to negate each bit of the provided byte/word and add 1/2’s
complement.
Operand: REG
memory
This instruction produces the two’s complement of the specified operand
and stored the result in the same operand. Microprocessor performs the
negate (NEG) operation by subtracting the operand from 0. This is done to
represent a negative number. All the flags are modified as per the result.
Example: MOV AL, 15H
NEG AL;
AL = 0EBH (2’s complement of 15H)
Arithmetic Instructions
CMP −
Used to compare 2 provided byte/word.
Operands: REG, memory; memory, REG; REG, REG;
memory, immediate; REG,
immediate;
This instruction compares the source operand with the destination operand.
Microprocessor executes this CMP instruction by subtracting the source from
destination, but none of the operand is modified. The result is reflected by
flag bits. Generally the result of this instruction is used for conditional
control transfer instructions. The comparison may be signed or unsigned
operation. Unsigned comparison reflects carry and zero flag whereas signed
comparison reflects zero, sign and overflow flag.
Arithmetic Instructions
AAS − no operands, ASCII adjustment after subtraction
Used to adjust ASCII codes after subtraction.
AAS converts the result of the subtraction of two valid unpacked BCD digits
to a single valid BCD number. AL register is an implicit operand.
The two operands of the subtraction must have its lower 4-bit contain
number in the range of 0-9. The AAS instruction then adjust AL so that it
contains a correct BCD digit.
The AAS instruction operates on strings of ASCII numbers with one decimal
digit per byte. This instruction used after a SUB or SBB on the ASCII value.
Except carry and auxiliary carry flag bite, all other flag bits are undefined.
Arithmetic Instructions
DAS − no operands,
Used to adjust decimal after subtraction.
The DAS instruction adjusts the result of a subtraction to a BCD packed
number (less than 100 decimal).
DAS converts the binary result of subtraction into packed BCD.
If the sum is greater than 99H after adjustment, then the carry and auxiliary
carry flags are set. Otherwise, carry and auxiliary carry flags are cleared.
All flag bits are modified as per the result.
Arithmetic Instructions
Instruction to perform multiplication
MUL − Used to multiply unsigned byte by byte/word by word.
IMUL − Used to multiply signed byte by byte/word by word.
AAM − Used to adjust ASCII codes after multiplication.
Arithmetic Instructions
Instruction to perform multiplication
MUL − Multiplication
Used to multiply unsigned byte by byte/word by word.
Operands: REG; memory;
The instruction multiplies the content of AL or AX by a specified source
operand. The AL and the AX are the implied destination operands for 8-bit or
16-bit multiplication. This is an unsigned operation, hence both the
operands are treated as unsinged operands. Both the operands should of
same size.
For a 16-bit multiplication, the implied operand will be AX register, the
product which is of 32-bit will be stored in DX:AX register pair. For an 8-boit
multiplication, the implied operand will be AL register, the product which is
of 16-bit will be stored in AX register.
Arithmetic Instructions
MUL − Multiplication
After multiplication, if DX is not 0 for 16-bit operands or AH is not 0 for 8-bit
operands, then the carry and overflow flags will set. The A, P, S and Z flags
are undefined, i.e. the value of these flag bits may be 0 or 1.
Example: MOV AL, 0FDH
MOV CL, 05H
MUL CL;
Ans: AX = 04F1H
CF = OF = 0,
when high section of the result is zero.
Arithmetic Instructions
IMUL − signed multiplication
Used to multiply signed byte by byte/word by word.
Operands: REG; memory;
This instruction is exactly same as that of MUL except that here both
operands are signed numbers. The source operand cannot be immediate
data or a segment register. If the product sign is extended into DX for 16-bit
operand and AH for 8-bit operand, then the carry and overflow flags are set
and remaining flags remain undefined.
Example: MOV AL, -03H
MOV CL, -05H
IMUL CL ; AX = 000FH
CF = OF = 0 when result fits into operand of IMUL
Arithmetic Instructions
AAM − no operands, ASCII adjustment after multiplication
Used to adjust ASCII codes after multiplication.
AAM converts the result of the multiplication of two valid unpacked BCD
digits into a valid unpacked BCD number. AX is the implicit operand in AAM.
AAM unpacks the result by dividing AX by 10, placing the quotient (Most
Significant Digit) in AH and the reminder (Least Significant Digit) in AL.
In AAM, except carry and auxiliary carry flag bits, all other flag bits are
undefined.
Arithmetic Instructions
Instructions to perform division
DIV − Used to divide the unsigned word by byte or unsigned double word by
word.
IDIV − Used to divide the signed word by byte or signed double word by word.
AAD − Used to adjust ASCII codes after division.
CBW − Used to fill the upper byte of the word with the copies of sign bit of the
lower byte.
CWD − Used to fill the upper word of the double word with the sign bit of the
lower word.
Arithmetic Instructions
Instructions to perform division
DIV − unsigned division
Used to divide the unsigned word by byte or unsigned double word by word.
Operands: REG; memory;
The instruction divides the content of AX or DX:AX by a specified source
operand. The AX and DX:AX are the implied destination operands for 8-bit or
16-bit division. This is an unsigned operation, hence both the operands are
treated as unsinged operands. Both the operands should of same size.
If the divisor is 16-bit wide, then the dividend is the DX:AX register pair.
After the division the quotient will be stored into AX and the reminder into
DX. When the divisor is of 8-bits, the dividend is AX, in this case quotient will
be stored in AL and the reminder in AH.
Arithmetic Instructions
DIV − unsigned division
Example: MOV AX, 00C8H
MOV CL, 06H
DIV CL
The result is available in AL = 21H and the reminder in AH = 02H
Arithmetic Instructions
IDIV − Signed Division
Used to divide the signed word by byte or signed double word by word.
Operands: REG; memory;
This instruction is exactly same as that of DIV except that here both
operands are signed numbers. In bot DIV and IDIV instructions, the source
operand cannot be immediate data or a segment register. All the flag bits
are undefined.
Example: MOV AX, -200 ; AX = 0FF38H
MOV CL, 6
IDIV CL
The result is available in AL (= DFH = -33) and the reminder in AH (= FEH =
02).
Arithmetic Instructions
AAD − no operands, ASCII adjustment before Division
Used to adjust ASCII codes before division.
AAD converts unpacked BCD digits in the AH and AL register into a single
binary number in the AX register in preparation for a division operation.
The most significant BCD digit is stored in the Ah register and the last
significant BCD digit is stored in AL register before the execution of AAD.
The two unpacked BCD digits are combined into a single binary number by
the AAD instruction by setting AL = (AH*10) + AL and clearing AH to 0.
The carry and overflow flag bits are modified as per the result and all other
flag bits remain undefined.
Arithmetic Instructions
CBW − no operand, Convert Byte to Word
Used to fill the upper byte of the word with the copies of sign bit of the lower
byte.
CBW converts the signed value in the AL register into an equivalent 16-bit
signed value in the AX register by extending the sign bit to the left.
This instruction copies the sign of a byte in AL to all the bits in AH. AH is
then said to be sign extension of AL. The flags are not modified and remains
unchanged.
Example: MOV AX, 0 ; AH = 0, AL = 0
MOV AL, F5H
CBW ; AX = 0FFF5H
In this example, F5H is equivalent to 11110101B, this means the sign bit is 1.
After the CBW, the sign bit will be extended into AX register
Arithmetic Instructions
CWD − no operand, Convert Word to Double word
Used to fill the upper word of the double word with the sign bit of the lower
word.
CWD converts the 16-bit signed value in the AX register into an equivalent
32-bit signed value in DX:AX register pair by duplicating the sign bit to the
left.
CWD instruction sets all the bits in the DX register to the same sign bit of
the AX register. The effect is to create a 32-bit signed result that has the
same integer value as the original 16-bit operand. The flags are not
modified and remain unchanged.
Example: MOV DX, 0
MOV AX, 0
MOV AX, -14H ; DX:AX =
0000H:0FFECH
CWD ; DX:AX
= 0FFFFH:0FFECH
Bit Manipulation Instructions
Instructions to perform logical operation
NOT − Used to invert each bit of a byte or word.
AND − Used for adding each bit in a byte/word with the corresponding bit in
another byte/word.
OR − Used to multiply each bit in a byte/word with the corresponding bit in
another byte/word.
XOR − Used to perform Exclusive-OR operation over each bit in a byte/word
with the corresponding bit in another byte/word.
TEST − Used to and operands to update flags, without affecting operands.
Bit Manipulation Instructions
Instructions to perform logical operation
NOT − Logically NOT
Used to invert each bit of a byte or word.
Operands: REG; memory;
This instruction complements the individual bits of the operand and save the
result in the same operand. In other words, we can say it generated the 1’s
compliment or the NOT operation of the operand. After this instruction the
flag register remains unchanged.
Example: MOV AL, 39H
NOT AL ; AL = C6H
Bit Manipulation Instructions
AND − logically AND
Used to multiply each bit in a byte/word with the corresponding bit in
another byte/word.
Operands: REG, memory; memory, REG; REG, REG;
memory, immediate; REG,
immediate;
This instruction performs a bitwise logical AND of destination operand and
the source operand. The result is stored in destination operand. The Z, S and
P flag bits are modified as per the result. The carry and overflow flag bits
are 0 and auxiliary carry is undefined.
Example: MOV AL, 61H ; AL = 01100001
AND AL, CFH ; AL = 01000001
Bit Manipulation Instructions
OR − Logically OR
Used to add each bit in a byte/word with the corresponding bit in another
byte/word.
Operands: REG, memory; memory, REG; REG, REG;
memory, immediate; REG,
immediate;
This instruction performs a bitwise logical OR operation between the source
and destination operand. The result is stored in destination operand.
The Z, S and P flag bits are modified as per the result. The carry and
overflow flag bits are 0 and auxiliary carry is undefined.
Bit Manipulation Instructions
XOR − logically EX-OR
Used to perform Exclusive-OR operation over each bit in a byte/word with
the corresponding bit in another byte/word.
Operands: REG, memory; memory, REG; REG, REG;
memory, immediate; REG,
immediate;
This instruction performs a bitwise exclusive OR operation between the
source and destination operand. The result is stored in destination operand.
The Z, S and P flag bits are modified as per the result. The carry and
overflow flag bits are 0 and auxiliary carry is undefined.
Bit Manipulation Instructions
TEST − Test
Used to add operands to update flags, without affecting operands.
Operands: REG, memory; memory, REG; REG, REG;
memory, immediate; REG,
immediate;
This instruction perform logical AND operation between all bits of the source
and destination operands, but none of the operand is modified. Only Z, S
and P flags are modified. The carry and overflow flags are cleared.
This instruction is used to test specified bits of an operand set the flags for a
subsequent conditional jump or set instruction.
Example: MOV AL, 25H
TEST AL, 05H ; ZF = 0
TEST AL, 20H ; ZF = 0
Bit Manipulation Instructions
Instructions to perform shift operations
SHL/SAL − Used to shift bits of a byte/word towards left and put zero(S) in
LSBs.
SHR − Used to shift bits of a byte/word towards the right and put zero(S) in
MSBs.
SAR − Used to shift bits of a byte/word towards the right and copy the old MSB
into the new MSB.
Bit Manipulation Instructions
Instructions to perform shift operations
SHL/SAL − Arithmetic / Logical Shift Left
Used to shift bits of a byte/word towards left and put zero(S) in LSBs.
Operands: memory, immediate; REG, immediate;
memory, CL; REG, CL;
The SHL (shift logically left) and SAL (shift arithmetically left) are used to
shift the content of the first operand towards left. The second operand may
be an immediate data or the counter register CL and represents the number
of times the shifting takes place. While each bit of the operand shifts to left,
the zeros fill vacated positions at the lower order bits.
SHL example
mov ax, 0A ; set AX to 0A (1010 in binary)
shl ax, 2 ; shifts 2 bits left in AX, now equal to 028 (101000 in binary)
shl ax, 1 ;Equivalent to AX*2
shl ax, 2 ;Equivalent to AX*4
shl ax, 3 ;Equivalent to AX*8
shl ax, 4 ;Equivalent to AX*16
shl ax, 5 ;Equivalent to AX*32
shl ax, 6 ;Equivalent to AX*64
shl ax, 7 ;Equivalent to AX*128
shl ax, 8 ;Equivalent to AX*256
Bit Manipulation Instructions
SHR − logically shift right
Used to shift bits of a byte/word towards the right and put zero(S) in MSBs.
Operands: memory, immediate; REG, immediate;
memory, CL; REG,
CL;
Shift, logically, the content of the first operand right by the number of times
specified by the second operand. The second operand may be an immediate
data or the counter register CL. In SHR while each bit is shifted right and
goes to the carry flag, a zero bit is inserted from the MSB side.
SHR Example
mov ax, 0xA ; set AX to 0xA (1010 in binary)
shr ax, 2 ; shifts 2 bits to the right in AX, now equal to 0x2 (0010 in binary)
shr ax, 1 ;Signed division by 2
shr ax, 2 ;Signed division by 4
shr ax, 3 ;Signed division by 8
shr ax, 4 ;Signed division by 16
shr ax, 5 ;Signed division by 32
shr ax, 6 ;Signed division by 64
shr ax, 7 ;Signed division by 128
shr ax, 8 ;Signed division by 256
Bit Manipulation Instructions
SAR − Arithmetically shift right
Used to shift bits of a byte/word towards the right and copy the old MSB into
the new MSB.
Operands: memory, immediate; REG, immediate;
memory, CL; REG,
CL;
Shift, arithmetically, the content of the first operand right by the number of
times specified by the second operand. The second operand may be an
immediate data or the counter register CL. In SAR while each bit is shifted
right and goes to the carry flag, the sign bit is inserted from the MSB side.
SAR Example
Example:
If we execute
SAR AX,2
If Ax=1010 (10)
1st shift: 1101 (13)
2nd shift: 1110 (14)
Bit Manipulation Instructions
Instructions to perform rotate operations
ROL − Used to rotate bits of byte/word towards the left, i.e. MSB to LSB and to
Carry Flag [CF].
ROR − Used to rotate bits of byte/word towards the right, i.e. LSB to MSB and
to Carry Flag [CF].
RCR − Used to rotate bits of byte/word towards the right, i.e. LSB to CF and CF
to MSB.
RCL − Used to rotate bits of byte/word towards the left, i.e. MSB to CF and CF
to LSB.
Bit Manipulation Instructions
Instructions to perform rotate operations
ROL − Rotate Left
Used to rotate bits of byte/word towards the left, i.e. MSB to LSB and to
Carry Flag [CF].
Operands: memory, immediate; REG, immediate;
memory, CL; REG, CL;
The ROL instruction is used to rotate the operand 1 left. In this instruction
the second operand may be an immediate value or the counter register CL.
This second operand decides the number of times the rotation will take
place.
Bit Manipulation Instructions
ROR − Rotate Right
Used to rotate bits of byte/word towards the right, i.e. LSB to MSB and to
Carry Flag [CF].
Operands: memory, immediate; REG, immediate;
memory, CL; REG, CL;
The ROR instruction is used to rotate the operand 1 right. In this instruction
the second operand may be an immediate value or the counter register CL.
This second operand decides the number of times the rotation will take
place.
Bit Manipulation Instructions
RCR − Rotate right through carry
Used to rotate bits of byte/word towards the right, i.e. LSB to CF and CF to
MSB.
Operands: memory, immediate; REG, immediate;
memory, CL; REG,
CL;
This instruction performs the rotation of the contents of operand 1 right
through carry flag. The second operand may be an immediate value or the
counter register CL. This second operand decides the number of times the
rotation will takes place.
RCR (Rotate Right through Carry Byte or Word):
Syntax: RCR Destination, Count
This inst rotates the data bits right within the destination operand through carry.
The bit that gets rotated out of the LSB goes into the carry flag and the bit that was in
carry flag gets rotated into the MSB.
Example: . RCR AL, 1; if AL = CDH and Carry = 1
RCL AL, 1; if AL = 9EH and Carry = 1
Bit Manipulation Instructions
RCL − Rotate Left Through Carry
Used to rotate bits of byte/word towards the left, i.e. MSB to CF and CF to
LSB.
Operands: memory, immediate; REG, immediate;
memory, CL; REG,
CL;
This instruction performs the rotation of the contents of operand 1 right
through carry flag. The second operand may be an immediate value or the
counter register CL. This second operand decides the number of times the
rotation will takes place.
RCL (Rotate Left through Carry Byte or Word):
Syntax: RCL Destination, Count The operation of RCL is similar to ROL except that RCL
rotates bits through carry flag.
The bit that gets rotated out of the MSB goes into the carry flag and the bit that was in
carry flag gets rotated into the LSB.
CALL − Used to call a procedure and save their return address to the stack.
JMP − Used to jump to the provided address to proceed to the next instruction.
Control Transfer Instructions without any condition
CALL − Call subroutine / procedure
This instruction is used to transfer the control of execution to a subroutine or
procedure. There are two basic types of CALL instruction, the Near CALL and Far Call.
A CALL instruction is called Near CALL if the procedure is in the same code segment
as the main program. When the procedure is stored in a code segment different from
where the main program is stored, the CALL instruction is called Far CALL.
When microprocessor executes the CALL instruction, the control is transferred to the
procedure, but before it goes to the subroutine it saves the returning address on the
top of the stack. The stack pointer is decremented by two and copies the offset of
the next instruction after CALL on the stack.
The control is again transferred to main program when microprocessor comes across
RET instruction at end of the procedure. This is done by popping up the offset saved
on the stack back to IP
Control Transfer Instructions without any condition
RET − no operand, Return
A near return is specified by RETN and far return is specified by RETF. A near
return works by popping a word into IP. A far return works by popping a word
into IP and then popping a word into CS.
Control Transfer Instructions without any condition
JMP − Jump Unconditionally
Operands: label; 4-byte address;
Used to jump to the provided address to proceed to the next instruction.
This is an unconditional jump instruction. By this instruction, the control is
transferred from one memory location to another location within the
program. The 4-byte address specified as 234h:5678H. Here the first value
denotes the segment and the second value shows the offset.
The jump instruction may be conditional also. The control will be transferred
to the label or 4-byte address only when the condition is true. Condition may
be logical or arithmetic and it may be signed or unsigned.
Control Transfer Instructions with some condition
Instructions to transfer the instruction during an execution with some conditions −
JA/JNBE − Used to jump if above/not below/equal instruction satisfies.
JAE/JNB − Used to jump if above/not below instruction satisfies.
JBE/JNA − Used to jump if below/equal/ not above instruction satisfies.
JC − Used to jump if carry flag CF = 1
JE/JZ − Used to jump if equal/zero flag ZF = 1
JG/JNLE − Used to jump if greater/not less than/equal instruction satisfies.
JGE/JNL − Used to jump if greater than/equal/not less than instruction satisfies.
JL/JNGE − Used to jump if less than/not greater than/equal instruction satisfies.
JLE/JNG − Used to jump if less than/equal/if not greater than instruction satisfies.
Control Transfer Instructions with some condition
JA/JNBE − Jump if above/ Jump if not below or equal
Description: Jumps to the destination label mentioned in the instruction if the result of
previous instruction (generally compare) causes both CF and ZF to have value equal to
0, else no action is taken.
Usage: JA dest, JNBE dest
[dest: address in the range of -128 bytes to +127 bytes from the address of instruction
after JA/JNBE]
Flags: the instruction has no effect on any flags.
Example:
CMP AX, 0030H; compares by subtracting 0030H from the value in AX register
JA LABEL1; jumps to the address specified by LABEL1 if value in register AX is above
the value 0030H
Control Transfer Instructions with some condition
JAE/JNB − Jump if above or equal/ Jump if not below
Description: Jumps to the destination label mentioned in the instruction if the result of
previous instruction (generally compare) causes CF to have value equal to 0, else no
action is taken.
Usage: JAE dest, JNB dest
[dest: address in the range of -128 bytes to +127 bytes from the address of instruction
after JAE/JNB]
Flags: the instruction has no effect on any flags.
Example:
CMP AX, 0030H; compares by subtracting 0030H from the value in AX regsiter
JAE LABEL1; jumps to the address specified by LABEL1 if value in register AX is
above or equal to the value 0030H
Control Transfer Instructions with some condition
JBE/JNA − Jump if below or equal/ Jump if not above
Description: Jumps to the destination label mentioned in the instruction if the result of
previous instruction (generally compare) causes either the CF or ZF to have value equal
to 1, else no action is taken.
Usage: JBE dest, JNA dest
[dest: address in the range of -128 bytes to +127 bytes from the address of instruction
after JBE/JNA]
Flags: the instruction has no effect on any flags.
Example:
CMP AX, 0030H; compares by subtracting 0030H from the value in AX regsiter
JBE LABEL1; jumps to the address specified by LABEL1 if value in register AX is
below or equal to the value 0030H
Control Transfer Instructions with some condition
JC −Jump if carry
Description: Jumps to the destination label mentioned in the instruction if the value of
CF is 1, else no action is taken.
Usage: JC dest
[dest: address in the range of -128 bytes to +127 bytes from the address of instruction
after JC]
Flags: the instruction has no effect on any flags.
Example:
JC LABEL1; jumps to the address specified by LABEL1 if CF is set
Control Transfer Instructions with some condition
JE/JZ − Jump if equal/ Jump if zero
Description: Jumps to the destination label mentioned in the instruction if the ZF is set,
else no action is taken.
Usage: JE dest, JZ dest
[dest: address in the range of -128 bytes to +127 bytes from the address of instruction
after JE/JZ]
Flags: the instruction has no effect on any flags.
Example:
JZ LABEL1; jumps to the address specified by LABEL1 if ZF=1
Control Transfer Instructions with some condition
JG/JNLE − Jump if greater/ Jump if not less than or equal
Description: Jumps to the destination label mentioned in the instruction if the result of
previous instruction (generally compare) causes ZF to have value equal to 0 and CF and
OF to have same values, else no action is taken.
Usage: JG dest, JNLE dest
[dest: addressin the range of -128 bytes to +127 bytes from the address of instruction
after JG/JNLE]
Flags: the instruction has no effect on any flags.
Example:
CMP AX, 0030H; compares by subtracting 0030H from the value in AX regsiter
JG LABEL1; jumps to the address specified by LABEL1 if value in register AX is
more positive than the value 0030H
Control Transfer Instructions with some condition
JGE/JNL − Jump if greater than or equal/ Jump if not less than
Description: Jumps to the destination label mentioned in the instruction if the result of
previous instruction (generally compare) causes CF to have value equal to OF, else no
action is taken.
Usage: JGE dest, JNL dest
[dest: address in the range of -128 bytes to +127 bytes from the address of instruction
after JGE/JNL]
Flags: the instruction has no effect on any flags.
Example:
CMP AX, 0030H; compares by subtracting 0030H from the value in AX regsiter
JGE LABEL1; jumps to the address specified by LABEL1 if value in register AX is
more positive or equal to the value 0030H
Control Transfer Instructions with some condition
JL/JNGE −Jump if less than/ Jump if not greater than or equal
Description: Jumps to the destination label mentioned in the instruction if the result of
previous instruction (generally compare) causes CF to have value not equal to OF, else
no action is taken.
Usage: JL dest, JNGE dest
[dest: address in the range of -128 bytes to +127 bytes from the address of instruction
after JL/JNGE]
Flags: the instruction has no effect on any flags.
Example:
CMP AX, 0030H; compares by subtracting 0030H from the value in AX regsiter
JL LABEL1; jumps to the address specified by LABEL1 if value in register AX is
more negative than the value 0030H
Control Transfer Instructions with some condition
JLE/JNG − Jump if less than or equal/ Jump if not greater than
Description: Jumps to the destination label mentioned in the instruction if the result of
previous instruction (generally compare) causes either the ZF to have value equal to 1
or OF to have value unequal to SF, else no action is taken.
Usage: JLE dest, JNG dest
[dest: address in the range of -128 bytes to +127 bytes from the address of instruction
after JLE/JNG]
Flags: the instruction has no effect on any flags.
Example:
CMP AX, 0030H; compares by subtracting 0030H from the value in AX regsiter
JLE LABEL1; jumps to the address specified by LABEL1 if value in register AX is
more negative than or equal to the value 0030H
Control Transfer Instructions with some condition
JNE/JNZ − Jump if not equal/ Jump if not zero
Description: Jumps to the destination label mentioned in the instruction if the ZF is 0,
else no action is taken.
Usage: JNZ dest, JNE dest
[dest: address in the range of -128 bytes to +127 bytes from the address of instruction
after JNZ/JNE]
Flags: the instruction has no effect on any flags.
Example:
JNZ LABEL1; jumps to the address specified by LABEL1 if ZF=0
Control Transfer Instructions with some condition
JNO − Jump if no overflow
Description: Jumps to the destination label mentioned in the instruction if the OF is 0,
else no action is taken. The overflow flag is set when a signed arithmetic operation
produces a result too large for the destination register or memory location to store.
Usage: JNO dest
[dest: address in the range of -128 bytes to +127 bytes from the address of instruction
after JNO]
Flags: the instruction has no effect on any flags.
Example:
ADD AL,BL; add signed bytes in AL and BL
JNZ LABEL1; jumps to the address specified by LABEL1 if OF=0 after to the add
instruction above
Control Transfer Instructions with some condition
JNP/JPO − Jump if no parity/ Jump if parity odd
Description: Jumps to the destination label mentioned in the instruction if the result of
previous instruction (generally compare) causes PF to have value equal to 0, else no
action is taken.
Usage: JNP dest, JPO dest
[dest: address in the range of -128 bytes to +127 bytes from the address of instruction
after JNP/JPO]
Flags: the instruction has no effect on any flags.
Example:
OR AX, AX; Set flags
JNP LABEL1; even parity is expected, jumps to the address specified by LABEL1
if parity is found to be odd
Control Transfer Instructions with some condition
JNS − Jump if not signed (Jump if positive)
Description: Jumps to the destination label mentioned in the instruction if the SF is set,
else no action is taken. If the sign flag is 0 it indicates a positive signed number. Hence
the instruction causes a jump if the result of previous instruction is positive.
Usage: JNS dest
[dest: address in the range of -128 bytes to +127 bytes from the address of instruction
after JNS]
Flags: the instruction has no effect on any flags.
Example:
ADD AL,BL; add signed bytes in AL and BL
JNS LABEL1; jumps to the address specified by LABEL1 if SF=0 due to the add
instruction above
Control Transfer Instructions with some condition
JO − Jump if overflow
Description: Jumps to the destination label mentioned in the instruction if the OF is set,
else no action is taken. The overflow flag is set when a signed arithmetic operation
produces a result too large for the destination register or memory location to store.
Usage: JO dest
[dest: address in the range of -128 bytes to +127 bytes from the address of instruction
after JO]
Flags: the instruction has no effect on any flags.
Example:
ADD AL,BL; add signed bytes in AL and BL
JZ LABEL1; jumps to the address specified by LABEL1 if OF=1 due to the add
instruction above
Control Transfer Instructions with some condition
JP/JPE − Jump if parity/ Jump if parity even
Description: Jumps to the destination label mentioned in the instruction if the result of
previous instruction (generally compare) causes PF to have value equal to 1, else no
action is taken.
Usage: JP dest, JPE dest
[dest: address in the range of -128 bytes to +127 bytes from the address of instruction
after JP/JPE]
Flags: the instruction has no effect on any flags.
Example:
OR AX, AX; Set flags
JNP LABEL1; odd parity is expected, jumps to the address specified by LABEL1 if
parity is found to be even
Control Transfer Instructions with some condition
JS − Jump if signed (Jump if negative)
Description: Jumps to the destination label mentioned in the instruction if the SF is 0,
else no action is taken. If the sign flag is 0 it indicates a positive signed number. Hence
the instruction causes a jump if the result of previous instruction is negative.
Usage: JS dest
[dest: address in the range of -128 bytes to +127 bytes from the address of instruction
after JS]
Flags: the instruction has no effect on any flags.
Example:
ADD AL,BL; add signed bytes in AL and BL
JS LABEL1; jumps to the address specified by LABEL1 if SF=1 due to the add
instruction above
Process Control Instructions
These instructions are used to control the processor action by setting/resetting
the flag values.
STC − Used to set carry flag CF to 1
CLC − Used to clear/reset carry flag CF to 0
CMC − Used to put complement at the state of carry flag CF.
STD − Used to set the direction flag DF to 1
CLD − Used to clear/reset the direction flag DF to 0
STI − Used to set the interrupt enable flag to 1, i.e., enable INTR input.
CLI − Used to clear the interrupt enable flag to 0, i.e., disable INTR input.
Process Control Instructions
These instructions are used to control the processor action by setting/resetting
the flag values.
NOP − No Operation
ESC − Escape
WAIT − Wait
LOCK − Lock
Process Control Instructions
These instructions are used to control the processor action by setting/resetting
the flag values.
NOP − No Operation
DESCRIPTION: This is a do nothing instruction. It results in occupation of both
space and time and is most useful for patching code segments.
USAGE: NOP
FLAGS: NONE
EXAMPLE:
;To do nothing 2 times:
DELAY:NOP ; does nothing
NOP ; does nothing
RET ; returns to point of function call
Process Control Instructions
ESC − Escape
DESCRIPTION: The ESC instruction passes instructions to floating point coprocessor from the
microprocessor. Whenever an ESC instruction executes, the microprocessor provides the memory
address, if required, but otherwise performs a NOP.
USAGE: ESC immediate, src
FLAGS: NONE
WAIT − Wait
DESCRIPTION: The WAIT instruction monitors the hardware BUSY pin on 80286 and 80386, and
the TEST pin on the 8086/8088. If WAIT instruction executes while the pin=1, nothing happens and
the next instruction executes normally. If pin=0, when the WAIT instruction executes, the
microprocessor waits for the pin to return to logic 1. This instruction is used to prevent the CPU from
accessing memory that may be temporarily in use by the coprocessor.
USAGE: WAIT
FLAGS: NONE
Process Control Instructions
LOCK − Lock
DESCRIPTION: The LOCK prefix appends to an instruction and causes the x86 LOCK Pin
to be asserted(become logic 0) and thereby causing external bus masters and other
peripherals to be disabled. The LOCK instruction causes the LOCK pin to be activated for
only the duration of the locked instruction.
USAGE : LOCK : [Instruction]
FLAGS : NONE
EXAMPLES:
LOCK: MOV AL,BL ; Causes the LOCK Pin to be activated for the particular mov
instruction
Iteration Control Instructions
These instructions are used to execute the given instructions for number of times.
LOOP − Used to loop a group of instructions until the condition satisfies,
i.e., CX = 0
LOOPE/LOOPZ − Used to loop a group of instructions till it satisfies
ZF = 1 & CX = 0
LOOPNE/LOOPNZ − Used to loop a group of instructions till it satisfies
ZF = 0 & CX = 0
JCXZ − Used to jump to the provided address if CX = 0
Iteration Control Instructions
These instructions are used to execute the given instructions for number of times.
LOOP − Used to loop a group of instructions until the condition satisfies, i.e., CX = 0
JCXZ does not look at ZF when deciding to jump. Destination label must be in the
range of -128 to 127 bytes from the address of the instruction after the JCXZ instruction.
Usage JCXZ Label
JECXZ Label (386+)
Flags None
Interrupt Instructions
These instructions are used to call the interrupt during program execution.
INT − Used to interrupt the program during execution and calling service
specified.