MP Instructions

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

0LFURSURFHVVRU/DE

Instruction Set:

Instructions Operands Description


Copy operand2 to operand1.
REG, memory
MOV memory, REG The MOV instruction cannot:
REG, REG • Set the value of the CS and IP registers.
memory, immediate • Copy value of one segment register to another segment
REG, immediate register (should copy to general register first).
• Copy immediate value to segment register (should
SREG, memory copy to general register first).
memory, SREG
REG, SREG Algorithm: operand1 = operand2
SREG, REG
Ex: Mov AX,BX ;Copy contents of BX to AX
Mov si,00h ;load Si with 00h
Unsigned Multiply.
MUL REG Multiply the contents of REG/Memory with contents of AL
Memory register.
Algorithm:

When operand is a byte:


AX = AL * operand.

When operand is a word:


(DX: AX) = AX * operand.
Compare.
REG, memory
CMP memory, REG Algorithm: operand1 - operand2
REG, REG
memory, immediate Result is not stored anywhere, flags are set (OF, SF, ZF, AF,
REG, immediate PF, CF) according to result.

Unconditional Jump.

JMP Label Transfers control to another part of the program. 4-byte address
may be entered in this form: 1234h: 5678h, first value is a
segment second value is an offset.

Algorithm: always jump


Jump If Above.

JA Label Short Jump if first operand is Above second operand (as set by
CMP instruction). Unsigned.

Algorithm: if (CF = 0) and (ZF = 0) then jump

Jump If Above Or Equal

JAE Label Short Jump if first operand is Above or Equal to second


operand (as set by CMP instruction). Unsigned.
Algorithm:

if CF = 0 then jump

Jump If Below.

JB Label Short Jump if first operand is Below second operand (as set by
0LFURSURFHVVRU/DE

CMP instruction). Unsigned.

Algorithm:

if CF = 1 then jump
Jump If Below Or Equal

JBE Label Short Jump if first operand is Below second operand (as set by
CMP instruction). Unsigned.

Algorithm:

if CF = 1 then jump
Jump If Carry

JC Label Short Jump if Carry flag is set to 1.

Algorithm:

if CF = 1 then jump
Jump If Equal.

JE Label Short Jump if first operand is Equal to second operand (as set
by CMP instruction). Signed/Unsigned.

Algorithm:

if ZF = 1 then jump
Jump If Greater

JG Label Short Jump if first operand is Greater then second operand (as
set by CMP instruction). Signed.

Algorithm:

if (ZF = 0) and (SF = OF) then jump


Jump If Greater Or Equal.

JGE Label Short Jump if first operand is Greater or Equal to second


operand (as set by CMP instruction). Signed.

Algorithm:

if SF = OF then jump
Jump If Less than.

JL Label Short Jump if first operand is Less then second operand (as set
by CMP instruction). Signed.

Algorithm:

if SF <> OF then jump


Jump If Less Or Equal.

JLE Label Short Jump if first operand is Less or Equal to second operand
(as set by CMP instruction). Signed.

Algorithm:
0LFURSURFHVVRU/DE

if SF <> OF or ZF = 1 then jump

Jump If Non Zero.

JNZ Label Short Jump if Not Zero (not equal). Set by CMP, SUB, ADD,
TEST, AND, OR, XOR instructions.

Algorithm:

if ZF = 0 then jump
Jump If Zero.

JZ Label Short Jump if Zero (equal). Set by CMP, SUB, ADD, TEST,
AND, OR, XOR instructions.

Algorithm:

if ZF = 1 then jump
Load Effective Address.

LEA REG, memory Algorithm:

• REG = address of memory (offset)

Decrease CX, jump to label if CX not zero.

Algorithm:
LOOP Label
• CX = CX - 1
• if CX <> 0 then
o jump

else

o no jump, continue
Add.
REG, memory
ADD memory, REG Algorithm:
REG, REG
memory, immediate operand1 = operand1 + operand2
REG, immediate

Logical AND between all bits of two operands. Result is stored


REG, memory in operand1.
AND memory, REG
REG, REG These rules apply:
memory, immediate
REG, immediate 1 AND 1 = 1; 1 AND 0 = 0
0 AND 1 = 0; 0 AND 0 = 0
0LFURSURFHVVRU/DE

Logical OR between all bits of two operands. Result is stored in


first operand.
OR REG, memory
memory, REG These rules apply:
REG, REG
memory, immediate 1 OR 1 = 1; 1 OR 0 = 1
REG, immediate 0 OR 1 = 1; 0 OR 0 = 0

Subtract.
REG, memory
memory, REG Algorithm:
SUB REG, REG
memory, immediate operand1 = operand1 - operand2
REG, immediate

Decimal adjust After Addition.


Corrects the result of addition of two packed BCD values.

DAA No Operands Algorithm:


if low nibble of AL > 9 or AF = 1 then:
• AL = AL + 6
• AF = 1

if AL > 9Fh or CF = 1 then:


• AL = AL + 60h

• CF = 1
Decimal adjust After Subtraction.
Corrects the result of subtraction of two packed BCD values.

DAS No Operands Algorithm:


if low nibble of AL > 9 or AF = 1 then:
• AL = AL - 6
• AF = 1

if AL > 9Fh or CF = 1 then:


• AL = AL - 60h

• CF = 1
Increment.

INC REG Algorithm: operand = operand + 1


memory
Decrement.

DEC REG Algorithm: operand = operand – 1


Memory
Unsigned Divide.

REG Algorithm:
DIV Memory
when operand is a byte:
AL = AX / operand
AH = remainder (modulus)
when operand is a word:
AX = (DX AX) / operand
DX = remainder (modulus)
0LFURSURFHVVRU/DE

Shift Left.
memory, immediate
SHL REG, immediate Shift operand1 Left. The number of shifts is set by operand2.

memory, CL Algorithm:
REG, CL
• Shift all bits left, the bit that goes off is set to CF.
• Zero bit is inserted to the right-most position.
Shift Right.
memory, immediate
SHR REG, immediate Shift operand1 Right. The number of shifts is set by operand2.

memory, CL Algorithm:
REG, CL
• Shift all bits right, the bit that goes off is set to CF.
• Zero bit is inserted to the left-most position.
Rotate Left.
memory, immediate
REG, immediate Rotate operand1 left. The number of rotates is set by operand2.
ROL
memory, CL Algorithm:
REG, CL
Shift all bits left, the bit that goes off is set to CF and
the same bit is inserted to the right-most position.
Rotate Right.
memory, immediate
REG, immediate Rotate operand1 right. The number of rotates is set by
ROR operand2.
memory, CL
REG, CL Algorithm:

Shift all bits right, the bit that goes off is set to CF and
the same bit is inserted to the left-most position.
procedure name Transfers control to procedure, return address is (IP) pushed to
CALL label stack.

Return from near procedure.

RET No operands Algorithm:


Or even immediate date
• Pop from stack:
o IP

if immediate operand is present: SP = SP + operand


Input from port Into AL or AX.
AL, im.byte Second operand is a port number. If required to access port
IN AL, DX number over 255 - DX register should be used.
AX, im.byte
AX, DX
Output from AL or AX to port.
AL, im.byte First operand is a port number. If required to access port number
OUT AL, DX over 255 - DX register should be used.
AX, im.byte
AX, DX
0LFURSURFHVVRU/DE

Get 16 bit value from the stack.


REG
POP SREG Algorithm: Operand = SS : [SP](top of stack)
memory
SP = Sp + 2.

Store 16 bit value in the stack.

REG Algorithm:
PUSH SREG
memory • SP = SP - 2

• SS:[SP] (top of the stack) = operand


Logical XOR (Exclusive OR) between all bits of two operands.
REG, memory Result is stored in first operand.
memory, REG
XOR REG, REG These rules apply:
memory, immediate
REG, immediate 1 XOR 1 = 0; 1 XOR 0 = 1
0 XOR 1 = 1; 0 XOR 0 = 0

Exchange values of two operands.


REG, memory
XCHG memory, REG Algorithm: operand1 < - > operand2
REG, REG

Translate byte from table.


Copy value of memory byte at DS:[BX + unsigned AL] to AL
XLAT No Operands register.

Algorithm: AL = DS:[BX + unsigned AL]

ASCII Adjust after Addition.


Corrects result in AH and AL after addition when working with
BCD values.

Algorithm:

if low nibble of AL > 9 or AF = 1 then:


• AL = AL + 6
• AH = AH + 1
• AF = 1
• CF = 1

AAA No Operands
else
• AF = 0
• CF = 0

in both cases:
cLear the high nibble of AL.

Example:
MOV AX, 15 ; AH = 00, AL = 0Fh
AAA ; AH = 01, AL = 05
ASCII Adjust after Subtraction.
Corrects result in AH and AL after subtraction when working
with BCD values.
0LFURSURFHVVRU/DE

Algorithm:

if low nibble of AL > 9 or AF = 1 then:


• AL = AL - 6
• AH = AH - 1
AAS No Operands • AF = 1
• CF = 1

else
• AF = 0
• CF = 0

in both cases:
cLear the high nibble of AL.

Example:
MOV AX, 02FFh ; AH = 02, AL = 0FFh
AAS ; AH = 01, AL = 09

ASCII Adjust after Multiplication.


Corrects the result of Multiplication of two BCD values.

Algorithm:

• AH = AL / 10
AAM No Operands • AL = remainder

Example:
MOV AL, 15 ; AL = 0Fh
AAM ; AH = 01, AL = 05
0LFURSURFHVVRU/DE

DOS Interrupt INT 2lH Function Calls

01H READ THE KEYBOARD


Entry AH = 01H
Exit AL = ASCII character
Notes If Al = 00H, the function call must be invoked again to read an
extEnded ASCII character. This function call automatically
echoes whatever is typed to the video screen.

02H WRITE TO STANDARD OUTPUT DEVICE


Entry AH = 02H
DL = ASCII character to be displayed
Notes This function displays character on video display

06H DIRECT CONSOLE READ/WRITE


Entry AH = 06H
DL = 0FFH or DL = ASCII character
Exit AL = ASCII character
Notes If DL = 0FFH on entry, then this function reads the console. If
DL = ASCII character, then this function displays the ASCII
character on the console (CON) video screen.

09H DISPLAY A CHARACTER STRING


Entry AH = 09H
DS:DX = Address of the character string
Exit AL = ASCII character
Notes The character string must End with an ASCII $ (24H). The
character string can be of any length and may contain control
characters such as carriage return (0DH) and line feed (0AH).

2CH READ SYSTEM TIME


Entry AH = 2CH
Exit CH = Hours (0-23)
CL = Minutes
DH = Seconds
DL = Hundredth of seconds
Notes All times are returned in binary form, and hundredths of
seconds may not be available.
3CH CREATE A NEW FILE
Entry AH = 3CH
CX = Attribute word
DS:DX = Address of ASCII-Z string file name
Exit AX = Error code if carry set
AX = File handle if carry cLeared
Notes The attribute word can contain any of the following(adding
together) :
0LFURSURFHVVRU/DE

01H = Read-only access,


02H = Hidden file or directory,
04H = System file,
0BH = Volume label,
10H = Subdirectory, and
20H = Archive bit.
In most cases, a file is created with 0000H.

41H DELETE A FILE


Entry AH = 41H
DS:DX = Address of ASCII-Z string file name
Exit AX = Error code if carry set

4CH TERMINATE A PROCESS


Entry AH = 4CH
AL = Error code
Exit Returns control to DOS
Notes This function codes are
AL = 00H to load and execute a program,
AL = 01H to load a program but not execute it,
AL = 03H to load a program overlay, and
AL = 05H to enter the EXEC state.

BIOS Interrupt INT 10H Function Calls

02H SELECT CURSOR POSITION


Entry AH = 02H
BH = Page number (usually 0)
DH = Row number (beginning with 0)
DL = Column number (beginning with 0)
Exit Changes cursor to new position

03H READ CURSOR POSITION


Entry AH = 03H
BH = Page number
Exit CH = starting line (cursor size)
CL = Ending line (cursor size)
DH = current row
DL = current column

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy