MPMC 2
MPMC 2
Second Year
Electrical Engineering Department
College of Engineering
Basrah University
2024-2025
3
• Most 8086 instructions can operate on the 8086’s general purpose register set.
The content of a register can be accessed by specifying the name of the register
as an operand to the instruction. For example, the following MOV instruction of
8086 copies the data from the source operand to the destination operand.
• MOV AX, BX
• MOV DL, AL
• MOV SI, DX
• The 8- and l6-bit registers are the valid operands for this instruction. The only
restriction is that both operands must be of the same size.
• The registers are the best place to keep often used variables. Instructions using
the registers are shorter and faster than those that access memory.
• Segment registers can never be used as data registers to hold arbitrary values.
They should only contain segment addresses.
4
• The l6-bit memory address is always written inside the square brackets. For example, the
instruction MOV BL, [2000H], transfers the content of the memory location 2000H in the BL
register. Similarly, the instruction MOV [l2S4H], DL transfers the content of the DL register in the
memory location specified by l2S4H. Figure 4.l shows the direct addressing mode.
5
Data Transfer Instructions
• The Data Transfer Instructions are used for transferring data from source location to destination
location. The Arithmetic Instructions are used to perform arithmetic operations like addition,
subtraction, multiplication and division. Logical Instructions perform the logical operations like
AND, OR, XOR operations. Shift and Rotate Instructions are used to perform the logical and
arithmetic shift operations and left and right shifting. String Instructions performs the string related
operations.
• MOV destination, source
• The MOV Instruction copies the second operand (source) to the first operand (destination)
without modifying the contents of the source. In true sense these are not the data transfer
instructions but data copy instruction because the source is not modified.
• The source operand can be an immediate value, general-purpose register or memory location.
The destination register can be a general-purpose register, or memory location. Both operands
must be the same size, which can be a byte or a word.
6
• The following types of operands are supported:
MOV REG, memory
MOV memory, REG
MOV REG, REG
MOV memory, immediate
MOV REG, immediate
• Here the register may be any of the general purposes registers, i.e. AX, BX, CX, DX, AH, AL,
BL, BH, CH, CL, DH, DL, DI, SI, BP, and SP. The memory may be specified by any of the
memory-related addressing modes. Immediate data can only be specified at the source location.
• A data cannot be transferred from a memory to another memory, from memory to an IO, from
an IO to another IO and from IO to memory. IO can communicate with Accumulator only.
• The MOV instruction cannot set the value of the CS and IP registers. Also, it cannot copy value
of one segment register to another segment register. For example, if we want to initialize the Data
Segment by a memory location 02500H, then first we have to load the value 2500H into AX
register and then transferring the contents of AX to DS register with the help of the following
instructions.
• Example MOV AX, 2500H,
MOV DS, AX
7
Arithmetic Instructions
• The 8086 provides many arithmetic operations: addition, subtraction, negation, multiplication,
division/modulo (remainder), and comparing two values.
• ADD operation: This instruction add a data from source operand to a data from destination and
save the result in the destination operand. The source and destination must be of the same type,
means they must be a byte type or a word type.
• Example: The following example demonstrates how the ADD instruction can be used to perform
the operation (1 + 5 + 7):
MOV AX, 1
ADD AX, 5
ADD AX, 7
• SUB operation: 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 the data which are
of large in size, i.e. double word type.
8
• Example: The following example demonstrates how the SUB instruction can be used to
perform the operation (5678H – 3421H + 10H):
MOV AX, 5678H
SUB AX, 3421H
ADD AX, 10H
• INC operation: This instruction increment the destination operand by l.
MOV AX, 5678H
INC AX
• DEC operation: This instruction decrement the destination operand by l.
MOV AX, 5678H
DEC AX
9
• DIV operation: This instruction divides the contents of the AX by a specified source operand. The
AX is the implied destination operands.
• After the division, the quotient will be stored into AX and the remainder into DX. When the
divisor is of 8 bits, the dividend is AX. And in this case the quotient will be stored in AL and the
remainder in AH.
Example
MOV AX, 0007H
MOV CL, 02H
DIV CL
After this program, the result is available in AL (= 3H) and
the remainder is present in AH (= 01H).
Example
MOV AX, 0007H
MOV CX, 02H
DIV CX
After this program, the result is available in AX (= 3H) and
the remainder is present in DX (= 01H).
10
• MUL operation: This instruction multiplies the contents of the AL or the AX by a specified
source operand. The AL and the AX are the implied destination operands for 8-bit and l6-bit
multiplication.
Example
MOV AL, 0FDH
MOV CL, 02H
MUL CL
The result will be in AX = 01FAH
11
Assembly - Conditions
• Conditional execution in assembly language is accomplished by several looping and branching
instructions. These instructions can change the flow of control in a program.
• The CMP instruction compares two operands. It is generally used in conditional execution. This
instruction basically subtracts one operand from the other for comparing whether the operands are
equal or not.
Example
MOV DX, 10H
CMP DX, 00 ; Compare the DX value with zero
JE L7 ; If yes, then jump to label L7
.
.
L7: ...
Example
MOV DX, 05H
INC DX
CMP DX, 10 ; Compares whether the counter has reached 10
JLE LP1 ; If it is less than or equal to 10, then jump to LP1
12
Example: Example: The following program displays the largest of two
CMP AL, BL variables
JE EQUAL MOV AX, 10
CMP AL, BH CMP AX, 20
JE EQUAL JG End
CMP AL, CL MOV AX, 20
JE EQUAL End: ret
NON_EQUAL: ...
EQUAL: ...
13
Example: Write a program to find the summation of the sequence 1, 2, 3, …. 10
MOV CX, 1
MOV AX, 0
p1: CMP CX, 0AH
JG stop
ADD AX, CX
INC CX
JMP p1
stop: ret
15
ORG 100h is a compiler directive (it tells compiler how to
ORG 100h
handle the source code). This directive is very important
MOV AH, var1
when you work with variables. It tells compiler that the
MOV AL, var2
executable file will be loaded at the offset of 100h (256
MOV sum_0, AH
bytes), so compiler should calculate the correct address for
ADD sum_0, AL
all variables when it replaces the variable names with their
MOV BH, sum_0
offsets.
RET ; stops the program.
Why executable file is loaded at offset of 100h?
var1 DB 2h
Operating system keeps some data about the program in
var2 DB 3h
the first 256 bytes of the CS (code segment), such as
sum_0 DB ?
command line parameters and etc.
16
STRING INSTRUCTIONS
17