Download File - M. Imad Aal

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Laws of Form wikipedia , lookup

Transcript
LEC 7
Assist. Lecturer Mohammed Imad
LOGIC INSTURCTIONS:
The 8086 has instructions for performing the logic operation like AND, OR,
XOR, NOT. These instructions perform their respective logic operations bit by
bit on the source and destination operands.
Mnemonic
Mean
Format
Operand
AND
OR
Logical AND
Logical OR
Logical
exclusive OR
Logical NOT
AND D,S
OR D,S
(S).(D)(D)
(S)+(D)(D)
(S) + (D)(D)
XOR
NOT
XOR D,S
NOT D
Flags
affected
CF, AF, ZF,
SF, PF, OF
D’  D
The source/destination operand can be:
Reg  reg
Reg  memory
Reg immediate
Memory  immediate
- AND instruction can be used to masking off specific bits in the operand by
ANDing with 0’s. for example AND AL,01H will mask off all bits except the lest
significant bit.
Example:
AND AL, BH
OR CX,[DI]
NOT [SI]
AL=AL.BH
CX=CX+[DS(0)+DI]
INVERTOR OF [DS(0)+SI]
Example:
write a program to performs the following Boolean operation
DI= (AX.BX)+(AX.CX’+DX)
1
SOL:
NOT CX
AND CX,AX
OR DX,CX
AND BX,AX
OR DX,BX
MOV DI,DX
;CX’
;AX.CX’
;AX.CX’+DX
;AX.BX
EXAMPLE
Write a program to clear bits 0 and 1 of CX, sets bits 9 and 10 of CX and
INVERT bit 12 of CX
SOL:
AND CX,FFFCH
OR CX,0600H
XOR CX,1000H
NOTE: AND with 0 used to clear, OR with 1 used to SET and XOR with 1 used
to invert.
Shifting instructions:
Shift instruction moves a data stored in register to the right or left. There are
two type of shifting
1- Logical shift (SHR, SHL)
2- Arithmetic shifting (SAR,SAL)
Logical shift instruction works with unsigned numbers while the arithmetic
shift instruction works with signed number.
SHR and SHL these two instructions works as follows
2
SHL
CF
SHR
0
0
CF
The basic format of the shift instruction is
SHL D,count
;
SHR D,count
The destination operand can be register or memory location, while the count
source can be either immediate value like 1,4,12 or counter register like CL
SAR and SAL instructions works with signed numbers, works as follow
SAL
CF
S
SAR
0
S
CF
Its format is similar to the logic shift as follow
SAL D,count
;
SAR D,count
Example: what is the result after executing the following:
MOV AX, 091AH
MOV CL,02
SAR AX,CL
SOL:
AX= 0000 1001 0001 1010
Shifting to right CL times
AX= 0000 0010 0100 0110 and the CF=1
AX= 0246H
Note that shifting number to the right 1-bit cause division by 2, while shifting
to the lift 1-bit cause a multiplication by 2.
Therefore shifting to the right/left n-times cause division/multiplication 2n
QUESTION: : write an assembly language program to perform the following
using shift instruction.
DX=12*AX
3
Rotate instructions:
Rotate instructions position binary data by rotating the information through a
register or memory content either from one end to another (ROL,ROR) or
through the carry flag (RCL, RCR)
The rotate instruction similar to the shift instruction, also have two operands,
the destination operand which can be any register. And the source operand
could be immediate or counter register CL
ROL
ROR
CF
CF
RCL
RCR
CF
CF
Example:
Write an assembly language program to shift 32-bit data stored in BX-AX
register one position to the left
Sol:
SHL AX,1
RCL BX,1
BX
CF
AX
0
HW:
Write an assembly language program to fill the content of the BL with value of
bit 3 of the AL register.
4
Compare instruction:
The compare instruction can be used to compare two 8-bits or 16-bits
numbers, the comparison process can be done by subtracting source operand
from the destination operand (D-S), the result that done from that subtraction
not saved in destination operand, instead, based on the result the appropriate
flag’s are set or reset (0 or 1).
Mnemonic
CMP
Mean
Compare
Format
CMP D,S
Operand
(D)- (S)
Flags affected
CF, AF, ZF, SF, PF, OF
The source and destination operand can be:
Reg, reg
Reg, memory
Memory, reg
Reg, immediate
Memory, immediate
Example:
If the value of AL=93 BL=2C. What is the new value of the flags after execute
the instruction ?
CMP AL,BL
Sol:
AL= 93H
= 1001 0011
= -109
BL=2CH
= 0010 1100
= + 44
2nd complement of BL is 1101 0100
1001 0011
+ 1101 0100
1 0110 0111
(-109)10
(-44)10
(103)10 +
5
67H which is 103 and carry flag=1
The flags will be:
There is no carry from bit 3 to bit 4 so
There is a carry out from bit 7
The result is overflowed
The number of 1’s is odd
The result is not zero
The bit7 (sign bit) is 0
AF=0
CF=1
OF=1
PF=0
ZF=0
SF=0
HW: describe what happen to the flags for each instruction in the program
below:
MOV AX,1234H
MOV BX,ABCDH
CMP AX,BX
6