Ex: Write An ALP To Find The Sum of The Following Series: Sum 1 + 2 + 3 + 4 + 5 + 6 Ans
Ex: Write An ALP To Find The Sum of The Following Series: Sum 1 + 2 + 3 + 4 + 5 + 6 Ans
ALDOURI
MOV BX , 0000H
MOV SI , 0001H
XOR DI , DI
NEXT: CALL SUBR
ADD BX , AX
ADC DI , 0000H
INC SI
CMP SI , 0007H
JNZ NEXT
HLT
49
8086/8088MP INSTRUCTOR: ABDULMUTTALIB A. H. ALDOURI
Note : The variable-port in IN / OUT instructions has advantage that the port
address can be computed or dynamically determined in the program. Suppose,
for example, that an 8086-based computer needs to input data from 10 terminals
(ports), each having its own port address. Instead of having a separate procedure
to input data from each port, you can write one generalized input procedure and
simply pass the address of the desired port to the procedure in DX.
58
8086/8088MP INSTRUCTOR: ABDULMUTTALIB A. H. ALDOURI
Ex: Write a piece of code to send 55H to output port device which its
address is F300H.
MOV AL , 55H
MOV DX , F300H
OUT DX , AL
Ex: Write a piece of code to input the contents of the byte-wide input port
at A000H of the I/O address space into BL.
MOV DX, 0A000H
IN AL, DX
MOV BL, AL
Ex: Write a piece of code to read data from two byte-wide input ports at
addresses AAH and A9H and output the data as a word to the word-wide
output port at address B000H.
IN AL, 0AAH
MOV AH, AL
IN AL, 0A9H
MOV DX, 0B000H
OUT DX, AX
51
8086/8088MP INSTRUCTOR: ABDULMUTTALIB A. H. ALDOURI
Miscellaneous Instructions
HLT (HALT PROCESSING)
The HLT instruction causes the 8086 to stop fetching and executing
instructions. The 8086 will enter a halt state. The different ways to get the
processor out of the halt state are with an interrupt signal on the INTR
pin, an interrupt signal on the NMI pin, or a reset signal on the RESET
input.
ESC (ESCAPE)
This instruction is used to pass instructions to a coprocessor, such as the
8087 Math coprocessor, which shares the address and data bus with 8086.
Instructions for the coprocessor are represented by a 6-bit code embedded
in the ESC instruction. As the 8086 fetches instruction bytes, the
coprocessor also fetches these bytes from the data bus and puts them in its
queue. However, the coprocessor treats all the normal 8086 instructions as
NOPs. When 8086 fetches an ESC instruction, the coprocessor decodes
the instruction and carries out the action specified by the 6-bit code
specified in the instruction. In most cases, the 8086 treats the ESC
instruction as a NOP.
52
8086/8088MP INSTRUCTOR: ABDULMUTTALIB A. H. ALDOURI
4. Get a new value for IP from an absolute memory address of 4 times the
type specified in the instruction. For an INT 8 instruction, for example,
the new IP will be read from address 00020H.
5. Get a new for value for CS from an absolute memory address of 4 times
the type specified in the instruction plus 2, for an INT 8 instruction, for
example, the new value of CS will be read from address 00022H.
6. Reset both IF and TF. Other flags are not affected.
53
8086/8088MP INSTRUCTOR: ABDULMUTTALIB A. H. ALDOURI
BYTE 1 Specification
OPCODE field (6-bits) : Specifies the operation to be performed such as
MOV , ADD , SUB …..etc.
Register direction bit (D-bit):
D = 1 : the register operand specified by REG in byte 2 is a destination
operand.
D = 0 : the register operand specified by REG in byte 2 is a source
operand
Data size bit (W-bit): Specifies whether the operation will be performed
on 8-bit or 16-bit data.
W = 1 : 16-bit data size
W = 0 : 8-bit data size
MOD Explanation
00 Memory Mode no displacement
01 Memory Mode 8-bit displacement
10 Memory Mode 16-bit displacement
11 Register Mode (no displacement)
Register (REG) field (3-bit) : Identifies the register for the first operand
Register/Memory (R/M) field (3-bit): Together with MOD field to
specify the second operand.
54
8086/8088MP INSTRUCTOR: ABDULMUTTALIB A. H. ALDOURI
Ex: Encode the following instruction in machine code. Assume that the
OPCODE for XOR instruction is 0011002.
XOR CL , [1234H]
Ans.
OPCODE = 001100 (for XOR), D = 1 (destination), W = 0 (8-bit) this leads to:
BYTE 1 = 001100102 = 3216
In byte 2 the destination operand, specified by REG is CL , then:
REG = 001 , MOD = 00, R/M = 110
Therefore:
BYTE 2 = 000011102 = 0E16
BYTE 3 = 3416 and BYTE 4 = 1216
The machine code for the instruction is:
XOR CL , [1234H] = 320E341216
Ex: Encode the following instruction in machine code. Assume that the
OPCODE for ADD instruction is 0000002.
ADD [BX+DI+1234H] , AX
Ans.
OPCODE = 000000 (for ADD) , D = 0 (source), W = 1 (16-bit) This leads to :
BYTE 1 = 000000012 = 0116
In byte 2 the destination operand, specified by REG is AX, then :
REG = 000 , MOD = 10 , R/M = 001
Therefore :
BYTE 2 = 100000012 = 8116
BYTE 3 = 3416 and BYTE 4 = 1216
The machine code for the instruction is:
ADD [BX+DI+1234H] , AX = 0181341216
56