City University
Department of Electrical and Electronic Engineering (EEE)
Course Code: EEE 3216, Course Title: Microprocessor and Interfacing Laboratory
Experiment No. 05
Name of the Experiment: Introduction to Logical, Rotate and Shift instruction in assembly language
program.
Objectives
The objectives of this experiment are to
To understand and implement logical AND, OR, XOR, NOT operations.
To grasp the concept of rotation and shifting operations (left and right shifts).
To apply these instructions to solve simple problems.
A. Theory
Logical instructions:
Logical instructions include NOT, AND, OR, XOR, TEST etc. instructions. There job is to compare
the data values and make results according to logic specified. For example,
MOV BX, 30H ; In binary 110000
NOT BX ; In binary 001111
This code takes BX value and then complements all the bits and stores the new value to BX. So it
stores 0F value in BX after executing NOT operation. For another example,
MOV BX, 70H ; In binary
1110000 MOV CX, 40H ; In
binary 1000000 AND CX, BX ; In
binary 1000000
AND operation performs bit by bit AND operation and then stores the value in first operand. In upper
code CX holds the final result.
MOV BX, 70H ; In binary
1110000 MOV CX, 40H ; In
binary 1000000
OR CX, BX ; In binary 1110000
OR operation performs bit by bit OR operation and then stores the value in first operand. In upper
code CX holds the final result. Similar case happens for XOR and it is given below,
MOV BX, 70H ; In binary
1110000 MOV CX, 40H ; In
binary 1000000 XOR CX, BX ; In
binary 0110000
Test operation is a little different from AND operation. It performs bit by bit AND operation but it
does not change any operands value.
MOV BX, 70H ; In binary
1110000 MOV CX, 40H ; In
binary 1000000
TEST CX, BX ; In binary CX value is 1000000
1
All the logical instructions stated above upgrades all the flag register values except
AF register. NOT command does not effect any flags. How flags are affected is stated below.
MOV BX, 70H ; In binary
1110000 MOV CX, 40H ; In
binary 1000000 AND CX, BX ; In
binary 1110000
After this operation Zero Flag is 0 (ZF = 0; as the value of CX is not 0), Carry Flag is 0 (CF = 0; as
there is no carry), Parity Flag is 0 (PF = 0; as there are odd number of
1’s), Sign Flag is 0 (SF = 1), Overflow Flag is 0 (OF = 0; as there is no overflow). In this all the flags
can be determined.
Program 1:
CODE SEGMENT
ASSUME CS:CODE, DS:CODE
ORG 1000H
MOV AX, 1027H
MOV BX, 5A27H
MOV CX, 54A5H
OR AX, BX
XOR AX, CX
NOT AX
TEST CX, BX
AND CX, AX
HLT
CODE ENDS
END
Shift and Rotate command:
Shift and Rotate commands are used to convert a number to another form where some bits are shifted or
rotated. The basic difference between shift and rotate is that the shift command makes “fall off” bits at
the end of the register. Where rotate command makes “Wrap around” at the end of the register. There
are both arithmetic (SAL and SAR) and logical (SHL and SHR) shift instructions. Graphical operations
for these commands are shown below.
2
3
Some simple codes can be given to clarify the idea.
MOV CL,03H ;
MOV AX,02F3H ; In binary 0000 0010 1111 0011
SHR AX,CL ; In binary 0000 0000 0101 1110
In this procedure, SHR commands inserts 0’s from left side. Each time a 0 is inserted right most bit
is vanished from register content.
MOV CL,03H ;
MOV AX,82F3H ; In binary 1000 0010 1111 0011
SAR AX,CL ; In binary 1111 0000 0101 1110
In this procedure, SAR command inserts MSB content from left side. Each time it is inserted right
most bit is vanished from register content.
MOV CL,03H ;
MOV AX,82F3H ; In binary 1000 0010 1111 0011
ROR AX,CL ; In binary 0111 0000 0101 1110
In this case, ROR instruction picks up the LSB and inserts it as MSB and so on.
Program 2:
CODE SEGMENT
ASSUME CS:CODE,DS:CODE
ORG 1000H
MOV AX,0055H
MOV DX,0505H
MOV CL, 3
SAL AX,CL
SAR DX,CL
MOV CL, 2
ROR AX,CL
ROL DX,CL
STC
RCL AL, CL
RCRDX,CL
HLT
CODE ENDS
END
B. Apparatus Required
1. 8086 microprocessor kit.
2. Assembler “MASM” and loader “LOD186”.
3. WinComm.
C. Procedures
1. Write the program 1 in notepad and save the file as “filename.asm”. Place this file in the
folder where “masm.exe” exists.
4
2. Go to command prompt and execute “masm.exe”. You will see the following
message –
Microsoft (R) Macro Assembler Version 5.10
Copyright (C) Misrosoft Corp 1981, 1988. All right reserved.
Source filename [.ASM]:
3. Follow the procedure given below to prepare machine code for your program:
Source filename [.ASM]: filename Press ENTER
Object filename [C:filename.OBJ]: Press ENTER
Source listing [NUL.LST]: filename Press ENTER
Cross reference [NUL.CRF]: Press ENTER
4. Execute “LOD186.exe”. You will see the following message
Paragon LOD186 Loader-Version 4.0h
Copyright (C) 1983 - 1986 Microtec Research
Inc. ALL RIGHT RESERVED.
Object/Command File [.OBJ]:
5. Follow the procedure given below to prepare HEX (ABS) file for your program:
Object/Command File [.OBJ]: filename Press ENTER
Output Object File [C:filename.ABS]: Press ENTER
Map Filename [C:NUL.MAP]: Press ENTER
**LOAD COMPLETE
6. Turn on the 8086 microprocessor kit
7. Open the “Wincomm” window. Press “L” then “Enter”. You will see the following
message:
** Serial Monitor 1.0 **
** Midas 335-0964/5 **
8086 >L Press ENTER
Down load start !!
8. Strike PgUp or F3 key of your keyboard. A new window will appear. Locate the
“filename.ABS” file and open it.
9. You will observe that file download has started. A message like the following one will
be shown:
:14100000B800008ED88EC0BB00208B078A6F028A4F038BEBB6
:101014003E8B5604268B76068B7E088B1E0A20CCCC
:0E20000012345678ABCDF0146853B1C41020E2
5
:00000001FF
OK completed !!
10. After loading the program, execute it in single step mode. Fill up the data table and
verify the results.
11. Follow procedures 1 to 10 for program 2.
D. Experimental Table :
Program-1
Offset Instruction / Set Flag
AX BX CX DX IP
Address Mnemonics Bit(s)
Initial Status
MOV AX, 1027H
MOV BX, 5A27H
MOV CX, 54A5H
OR AX, BX
XOR AX, CX
NOT AX
TEST CX, BX
AND CX, AX
6
Program 2:
Offset Instruction Set
AX BX CX DX IP
Addres / Flag
s Mnemonics Bit(s)
Initial Status
MOV AX, 0055H
MOV DX, 0505H
MOV CL, 3
SAL AX, CL
SAR DX, CL
MOV CL, 2
ROR AX, CL
ROL DX, CL
STC
RCL AL, CL
RCR DX, CL
E. Report:
Discuss the effects of each instruction/ mnemonics that are used in this program.
F. References:
1. User’s manual of MDA-8086 microprocessor kit, Midas Engineering.
2. “Assembly Language Programming and Organization of the IBM PC”, Ytha Yu and Charles Marut,
Mitchell McGraw-Hill.