Beruflich Dokumente
Kultur Dokumente
ا
Royal Commission at Yanbu 678) (0345.( ا90:.ا
Yanbu University College (Boys' and Girls Campus) ( ?087.م ا2A) 678)-(0,;<=.( ا043.ا
Department of CS / MIS 116ext 3932961 :Tel
Yanbu Al-Sinaiyah (0D<8E. ا678)
Objective:
The objective of this lab is to make students practice
Outline:
Using AND, OR, XOR, NOT, SHL, SHR, ROL, and ROR instructions in
8086
1
___________________________________________________________________________________________________
Prepared by: Khurram Tanvir CS Department YUC
Introduction:
In this experiment you will be introduced to logical operations and logical shift and rotate instructions.
Logical Instructions:
Logic shift and rotate instructions are called bit manipulation operations. These operations are
designed for low-level operations, and are commonly used for low-level control of input/output
devices. The list of the logic operations of the 8086 is given in the table, along with examples, and the
effect of these operations on the flags. The “*” in the table means that the corresponding flag may
change as a result of executing the instruction. The “-” means that the corresponding flag is not
affected by the instruction, whereas the “?” means that the flag is undefined after executing the
instruction.
Flags
Instruction Example Meaning
OF SF ZF AF PF
The logic operations are the software analogy of logic gates. They are commonly used to separate a bit
or a group of bits in a register or in a memory location, for the purpose of testing, resetting or
complementing. For example, if b is the value of a certain bit in a number. The related effects of the
basic operations on a single bit are indicated in Table 5.3:
Operation Effect
b AND 0 = 0 Reset the bit
b OR 1 = 1 Set the bit
b XOR 1 = b’ Complement the bit
b XOR 0 = b -
The shift operations are used to multiply or divide a number by another number that is a power of 2
(i.e. 2n or 2 –n). Multiplication by 2 is achieved by a one-bit left shift, while division by 2 is achieved
by a one-bit right shift.
2
___________________________________________________________________________________________________
Prepared by: Khurram Tanvir CS Department YUC
• 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
The rotate operations are very similar to the shift operations, but the bits are shifted out from one end
of a number and fed back into the other end to fill the vacated bits. They are provided to facilitate the
shift of long numbers (i.e. numbers of more than 16 bits). They are also used to reposition a certain bit
of a number into a desired bit-location.
Right shifting
Left shifting
Rotate left
Rotate right
6. Flags
Type
3
___________________________________________________________________________________________________
Prepared by: Khurram Tanvir CS Department YUC
Practice Program 1
.MODEL SMALL
.STACK 200
.DATA
NUM1 DW 0FA62H
NUM2 DB 94H
.CODE
.STARTUP
4
___________________________________________________________________________________________________
Prepared by: Khurram Tanvir CS Department YUC
Practice Program 2
.MODEL SMALL
.STACK 200
.CODE
.STARTUP
.EXIT
END
Exercise
Write a program to store a value shown in the following table in AH register.
Write further instructions to change the value in AH register so that
a) b7 and b6 are inverted.
b) b1 and b0 are set to 1.
c) B2 is cleared to 0.
b7 b6 b5 b4 b3 b2 b1 b0
d) Right Shift the result in AH by 3
e) Rotate left the result in AH by 1 0 1 1 0 1 1 0 0
5
___________________________________________________________________________________________________
Prepared by: Khurram Tanvir CS Department YUC