Sie sind auf Seite 1von 5

Kingdom of Saudi Arabia ()‫د‬+,-.‫( ا‬012,.‫( ا‬3455.

‫ا‬
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)

BACHELOR OF SCIENCE IN COMPUTER SCIENCES


Lab Work

Computer Organization and Assembly ( CS203)


Second Semester - Academic Year 2007 – 08
Lab Sheet 4

Practicing Logical and Bit Manipulation Instructions in 8086

Objective:
The objective of this lab is to make students practice

1. Demonstrate AND and OR instructions


2. Practice XOR and NOT instructions
3. Practice shifting instructions, SHL and SHR
4. Practice rotate instructions, ROL and ROR

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

AND AND AX, FFDFH AX ← AX AND FFDFH 0 * * ? *


OR OR AL, 20H AL ← AL OR 20H 0 * * ? *
XOR XOR NUM1, FF00 [NUM1]←[NUM1]XOR FF00 0 * * ? *
NOT NOT NUM2 _______ - - - - -
[NUM2]←[ NUM2]

Summary of the Logic Instructions of the 8086 Microprocessor

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 -

Effects on bits of the basic logic instructions

The Shift Operations:

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

Instruction Example Meaning OF SF ZF AF PF CF

SHL SHL AX,1 Shift AX left by 1 bit. Fill * * * ? * *


vacated bit with 0.
Shift

SHR SHR NUM2,CL Shift NUM2 right by the * 0 * ? * *


number of bits indicated in CL.
Fill vacated bits with 0.
ROL ROL BH,CL Same as SHL, but shifted bits * - - - - *
Rotate

are fed back to fill vacated bits.


ROR ROR NUM1,1 Same as SHR, but shifted bits * - - - - *
are fed back to fill vacated bits.

Summary of the Shift and Rotate Instructions of the 8086 Microprocessor

3
___________________________________________________________________________________________________
Prepared by: Khurram Tanvir CS Department YUC
Practice Program 1

Fill in table while running the above program using CodeView.

TITLE “Logic Instructions”


; This program shows the effect of the logic instructions

.MODEL SMALL
.STACK 200
.DATA
NUM1 DW 0FA62H
NUM2 DB 94H
.CODE
.STARTUP

MOV AX, NUM1 ;load AX with number NUM1


AND AX, 0FFDFH ;Reset 6th bit of AX
OR AL, 20H ;Set 6th bit of AL
XOR NUM1, 0FF00H ;Complement the high order byte of
; NUM1
NOT NUM2 ;Complement NUM2
XOR AX, AX ;Clear AX
MOV AX, NUM1
AND AX, 0008H ; Isolate bit 4 of NUM1
XOR AX, 0080H ;Complement 4th bit of AX
.EXIT
END

Destination Content Status Flags


Statement
Before After O D I S Z A P C
F F F F F F F F
1. MOV AX, NUM1
2. AND AX, 0FFDFH
3. OR AL, 20H
4. XOR NUM1, 0FF00H
5. NOT NUM2
6. XOR AX, AX
7. MOV AX, NUM1
8. AND AX, 0008H
9. XOR AX, 0080H

4
___________________________________________________________________________________________________
Prepared by: Khurram Tanvir CS Department YUC
Practice Program 2

Fill in table while running the above program using CodeView.

TITLE “Logical and Shifting Instructions”


; This program shows the effect of the logic instructions

.MODEL SMALL
.STACK 200
.CODE
.STARTUP

MOV AH, 34H


SHL AH, 1
AND AH, 65H
SHR AH, 3
NOT AH
ROR AH, 1
XOR AH, 88H
ROL AH, 1

.EXIT
END

Destination Content Status Flags


Statement
Before After O D I S Z A P C
F F F F F F F F
1. MOV AH, 34H
2. SHL AH, 1
3. AND AH, 65H
4. SHR AH, 3
5. NOT AH
6. ROR AH, 1
7. XOR AH, 88H
8. ROL AH, 1

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

Use code view to view output of your code line by line.

5
___________________________________________________________________________________________________
Prepared by: Khurram Tanvir CS Department YUC

Das könnte Ihnen auch gefallen