Вы находитесь на странице: 1из 6

Bangabandhu Sheikh Mujibur Rahman Science & Technology University

Department of Electrical & Electronic Engineering


Laboratory Experiment Sheet
Course No: EEE 391
Course Title: Microprocessor Interfacing and System Design LAB

Experiment No: 04
Experiment Name: Introduction of Logical, Rotate and Shift instructions in assembly
language.

Objective:

To get familiar with Logical, Rotate and Shift Instructions in assembly language.

Introduction:

Logic instructions:
Logic operations are used to manipulate individual bits in the computer. When a logic
operation is applied to 8 or 16 bit operands, the result is obtained by logic operation at
each bit position. Truth table for logic operators AND, OR, XOR and NOT are shown
below:

a aa a Bbb b a Aa a AND b a OR b a a XOR bN NOT a


0 0 0 0 0 0 0 1
00 0 00 1 0 1 1 1
1 1 1 0 0 1 1 0
1 1 1 1 1 1 0 0

Effect on flags:
SF, ZF, PF reflect the result.
CF, OF=0

Test Instructions:
The TEST instruction performs an AND operation of the destination with the source but
does not change the destination contents. The purpose of the TEST instructions is to
set the status flags. The format is: TEST destination, source

Effect on flags:
SF, ZF, PF reflect the result.
CF, OF=0
Shift and Rotate command:

The shift and rotate instructions shift the bits in the destination operand by one or more
positions either to the left or right. For a shift instructions, the bits shifted out are lost;
for a rotate instructions, bits shifted out from one end of the operand are put back into
the other end. The instructions have two possible formats. For a signle shift or rotate,
the form is
Opcode destination,1
For a shift or rotate of N positions, the form is
Opcode destination, CL where CL contains N. In both cases, destination is an 8-bit or
16-bit register or memory location.

SHL and SAL instructions:


BIT VALUE X A B C D E F G H

BIT NO CF 7 6 5 4 3 2 1 0

AFTER SHL/ SAL

BIT VALUE A B C D E F G H 0

BIT NO CF 7 6 5 4 3 2 1 0

SHR instructions:
BIT VALUE X A B C D E F G H

BIT NO CF 7 6 5 4 3 2 1 0

AFTER SHR
BIT VALUE H 0 A B C D E F G

BIT NO CF 7 6 5 4 3 2 1 0

SAR instructions:
BIT VALUE X A B C D E F G H

BIT NO CF 7 6 5 4 3 2 1 0

AFTER SAR
BIT VALUE H A A B C D E F G

BIT NO CF 7 6 5 4 3 2 1 0
ROL instructions:
BIT VALUE X A B C D E F G H

BIT NO CF 7 6 5 4 3 2 1 0

AFTER ROL
BIT VALUE A B C D E F G H A

BIT NO CF 7 6 5 4 3 2 1 0

ROR instructions:
BIT VALUE X A B C D E F G H

BIT NO CF 7 6 5 4 3 2 1 0

AFTER ROR

BIT VALUE H H A B C D E F G

BIT NO CF 7 6 5 4 3 2 1 0

RCL instructions:
BIT VALUE C A B C D E F G H

BIT NO CF 7 6 5 4 3 2 1 0

AFTER RCL

BIT VALUE A B C D E F G H C

BIT NO CF 7 6 5 4 3 2 1 0

RCR instructions:
BIT VALUE C A B C D E F G H

BIT NO CF 7 6 5 4 3 2 1 0

AFTER RCR
BIT VALUE H C A B C D E F G

BIT NO CF 7 6 5 4 3 2 1 0
Class Assignment:

(a) Program 1:

CODE SEGMENT

MOV AL, 45h

AND AL, 7Fh; clear the sign bit of AL while leaving other bits unchanged

OR AL, 81h; set the msb and lsb while preserving the other bits.

XOR AL, 80h; toggle the sign bit


XOR AL, AL; clear the register AL

HLT

CODE ENDS

END

Obtain AX register value in write the previous value and present value in binary form.
What type of operation is this?

(b) Program 2:

CODE SEGMENT

ASSUME CS: CODE

MOV CL, 04H

MOV AX, 564AH

SAL AX, CL

HLT

CODE ENDS

END

Obtain AX register value in write the previous value and present value in binary form.
What type of operation is this?
(c) Program 3:
CODE SEGMENT

ASSUME CS: CODE

MOV CL, 04H

MOV AX, 564AH

ROL AX, CL

HLT

CODE ENDS

END

Obtain AX register value in write the previous value and present value in binary form.
What type of operation is this?

(d) Program 4:

CODE SEGMENT

ASSUME CS: CODE

MOV CL, 04H

MOV AX, 564AH

RCL AX, CL

HLT

CODE ENDS

END

Obtain AX register value in write the previous value and present value in binary form.
What type of operation is this?

(e) Perform for similar values of AX and CL with SHR, SAR. RCR,
ROR command.
Homework:

1. Write some code to count the number of 1 bit in BX, without changing BX. Put the
answer in AX.

2. Write some code to reverse the bit pattern of the number stored in AX.

Вам также может понравиться