Jawaharlal Nehru Engineering College: Laboratory Manual
Jawaharlal Nehru Engineering College: Laboratory Manual
Jawaharlal Nehru Engineering College: Laboratory Manual
Laboratory Manual
MICROPROCESSORS
For
It is my great pleasure to present this laboratory manual for Second year Engineering students
for the subject Microprocessors.
As a student, many of you may be wondering with some of the questions in your mind
regarding the subject and exactly what has been tried is to answer through this manual.
You may be aware that MGM has already been awarded with ISO 9001:2000 certification
and it is our endure to technically equip our students taking the advantage of the procedural
aspects of ISO 9001:2000 Certification.
Faculty members are also advised that covering these aspects in initial stage itself, will
greatly relieve them in future as much of the load will be taken care by the enthusiasm
energies of the students once they are conceptually clear.
Dr. S.D.Deshmukh
Principal
LABORATORY MANUAL CONTENTS
This manual is intended for the Second year students of Computer Science and Engineering
in the subject of Microprocessors. This manual typically contains practical/Lab Sessions
related to 8086 Microprocessor covering various aspects of the subject to enhance
understanding.
Students' are advised to thoroughly go through this manual rather than only topics mentioned
in the syllabus as practical aspects are the key to understanding and conceptual visualization
of theoretical aspects covered in the books.
MGM’s
Jawaharlal Nehru Engineering College, Aurangabad
To develop computer engineers with necessary analytical ability and human values who can
creatively design, implement a wide spectrum of computer systems for welfare of the society.
Preparing graduates for higher education and research in computer science and
engineering enabling them to develop systems for society development.
I. To analyze, design and provide optimal solution for Computer Science & Engineering
and multidisciplinary problems.
II. To pursue higher studies and research by applying knowledge of mathematics and
fundamentals of computer science.
III. To exhibit professionalism, communication skills and adapt to current trends by
engaging in lifelong learning.
Programme Outcomes (POs):
Engineering Graduates will be able to:
2. Problem analysis: Identify, formulate, review research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.
5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and
modern engineering and IT tools including prediction and modeling to complex
engineering activities with an understanding of the limitations.
6. The engineer and society: Apply reasoning informed by the contextual knowledge to
assess societal, health, safety, legal and cultural issues and the consequent responsibilities
relevant to the professional engineering practice.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
norms ofthe engineering practice.
12. Life-long learning: Recognize the need for, and have the preparation and ability to
engage independent and life-long learning in the broadest context of technological
change.
LIST OF EXPERIMENTS
Programming
even or odd.
Numbers.
Hex.
12. Write an assembly language program to interface stepper motor using 8255.
DOs and DON’Ts in Laboratory:
1. Make entry in the Log Book as soon as you enter the Laboratory.
2. All the students should sit according to their roll numbers starting from their left to
right.
3. All the students are supposed to enter the terminal number in the log book.
5. All the students are expected to get at least the algorithm of the program/concept
to be implemented.
1. Submission related to whatever lab work has been completed should be done during the
next lab session. The immediate arrangements for printouts related to submission on the day
of practical assignments.
2. Students should be taught for taking the printouts under the observation of lab teacher.
Objectives:
To understand the working of EMU8086 as emulator for 8086 Programming and get
acquainted with Assembly Language Programming.
Theory:
Assembly Language Programming is less powerful than the high level languages like
C, C++, JAVA, etc. it is necessary to understand basics of assembly language as it helps in
understanding the working and the instruction set of microprocessors and microcontrollers.
Microprocessors like 8085 , 8086 and many other microcontrollers could be easily operated
via simple instructions of assembly languages. MASM (Microsoft Macro Assembler) is a
very efficient assembly language programming tool for windows and MS-DOS. It is not a
emulator but an actual programming tool helps in programming with processor. Emulator
EMU8086 is an emulator for 8086 providing an easy and user friendly environment for
assembly language programming for 8086.
1. EDITOR: An editor is a program, which allows you to create a file containing the
assembly language statements for your program.
2. ASSEMBLER: An assembler program is used to translate the assembly language
mnemonic instructions to the corresponding binary codes. The second file generated
by assembler is called the assembler List file.
3. LINKER: A Linker is a program used to join several object files in to one large object
file. The linkers produce link files with the .EXE extension.
MEMORY MODELS FOR THE ASSEMBLER
TINY All data and code must fit into one segment. Tiny
programs are written in .COM format, which
means that the program must be originated at
location 100H
SMALL This model contains two segments: one data
segment of 64K bytes and one code segment of
64K bytes.
MEDIUM This model contains one data segment of 64K
bytes and any number of code segments for large
programs.
COMPACT One code segment contains the program, and any
number of data segments contains the data.
LARGE The large model allows any number of code and
data segments.
HUGE This model is the same as large, but the data
segments may contain more than 64K bytes each.
FLAT Only available to MASM 6.X. The flat model
uses one segment of 512K bytes to tore all data
and code. Note that this model is mainly used
with Windows NT
ASSEMBLER DIRECTIVES:
An assembler is a program used to convert an assembly language program into the
equivalent machine code modules. The assembler decides the address of each label and
substitutes the values for each of the constants and variables. It then forms the machine code for
mnemonics and data in assembly language program. Assembler directives help the assembler to
correctly understand assembly language programs to prepare the codes. Commonly used
assembler directives are DB, DD, DW, DUP, ASSUME, BYTE, SEGMENT, MACRO, PROC,
OFFSET, NEAR, FAR, EQU, STRUC, PTR, END, ENDM, ENDP etc. Some directives generate
and store information in the memory, while others do not.
BYTE PTR :- This directive indicates the size of data referenced by pointer.
DUP (Duplicate) :- The DUP directive reserves memory locations given by the
number preceding it, but stores no specific values in any of these locations.
ASSUME : - The ASSUME statement is only used with full segment definitions. This statement
tells the assembler what names have been chosen for the code, data, extra and stack segments.
EQU : - The equate directive equates a numeric ASCII or label to another label.
ORG : - The ORG (origin) statement changes the starting offset address in a segment.
PROC and ENDP : - The PROC and ENDP directives indicate start and end of a procedure (Sub
routine). Both the PROC and ENDP directives require a label to indicate the name of the
procedure. The PROC directive, must also be followed with the NEAR or FAR. A NEAR
procedure is one that resides in the same code segment as the program. A FAR procedure may
reside at any location in the memory system.
OFFSET : - Offset of a label. When the assembler comes across the OFFSET operator along
with a label, it first computes the 16 – bit displacement of the particular label, and replaces the
string ‘OFFSET LABEL’ by the computed displacement.
LENGTH : - Byte length of the label. This directive is used to refer to the
length of data array or a string.
DOS Function Calls: - In order to use DOS function calls, always place function number into
register AH, and load other information into registers. Following is INT 21H, which is software
interrupt to execute a DOS function. All function calls use INT 21H, and AH contains function
call number. User can access the hardware of PC using DOS subroutine .DOS subroutines are
invoked or called via software interrupt INT 21H.
Conclusion: The assembly Language programming for 8086 and the Emulator EMU8086 is
studied.
EXPERIMENT No. 2
addition.
Objectives:
Describe the internal registers and access in different addressing modes for addition
operations both 8 bit and 16 bits.
Theory:
The 8086 has four groups of the user accessible internal registers. They are
1. general purpose registers
2. Segment registers
3. pointer and index registers
4. Flag register
Segment register:
Code segment (CS) is a 16-bit register containing address of 64 KB segment with
processor instructions. The processor uses CS segment for all accesses to instructions
referenced by instruction pointer (IP) register. CS register cannot be changed directly. The
CS register is automatically updated during far jump, far call and far return instructions.
Stack segment (SS) is a 16-bit register containing address of 64KB segment with
program stack. By default, the processor assumes that all data referenced by the stack
pointer (SP) and base pointer (BP) registers is located in the stack segment. SS register
can be changed directly using POP instruction.
Data segment (DS) is a 16-bit register containing address of 64KB segment with
program data. By default, the processor assumes that all data referenced by general
registers (AX, BX, CX, DX) and index register (SI, DI) is located in the data segment. DS
register can be changed directly using POP and LDS instructions.
Extra segment (ES) is a 16-bit register containing address of 64KB segment, usually
with program data. By default, the processor assumes that the DI register references the
ES segment in string manipulation instructions. ES register can be changed directly using
POP and LES instructions
Instruction Pointer (IP) is a 16-bit register that contains the offset address. IP is
combined with the CS to generate the address of the next instruction to be executed.
Stack Pointer (SP) is a 16-bit register pointing to program stack.
Base Pointer (BP) is a 16-bit register pointing to data in stack segment. BP register is
usually used for based, based indexed or register indirect addressing.
Source Index (SI) is a 16-bit register. SI is used for indexed, based indexed and register
indirect addressing, as well as a source data address in string manipulation instructions.
Destination Index (DI) is a 16-bit register. DI is used for indexed, based indexed and
register indirect addressing, as well as a destination data address in string manipulation
instructions.
Flag Register
Flags is a 16-bit register containing nine 1-bit flags. 06 flags are status flags and 3 are Control
Flags
Overflow Flag (OF) - set if the result is too large positive number, or is too small
negative number to fit into destination operand.
Direction Flag (DF) - if set then string manipulation instructions will auto-decrement
index registers. If cleared then the index registers will be auto-incremented.
Interrupt-enable Flag (IF) - setting this bit enables maskable interrupts.
Single-step Flag (TF) - if set then single-step interrupt will occur after the next
instruction.
Sign Flag (SF) - set if the most significant bit of the result is set.
Zero Flag (ZF) - set if the result is zero.
Auxiliary carry Flag (AF) - set if there was a carry from or borrow to bits 0-3 in the AL
register.
Parity Flag (PF) - set if parity (the number of "1" bits) in the low-order byte of the
result is even.
Carry Flag (CF) - set if there was a carry from or borrow to the most significant bit
during last result calculation.
Data transfer is one of the most common tasks when programming in an assembly
language. Data can be transferred between registers or between registers and the memory.
Immediate data can be loaded to registers or to the memory. The transfer can be done on an octet
or word. The two operands must have the same size. Data transfer instructions don’t affect the
condition indicators (excepting the ones that have this purpose). They are classified as follows:
classical transfer instructions
address transfer instructions
condition indicator transfer instructions
input/output instructions (peripheral register transfers)
The MOV instruction is used to transfer a byte or a word of data from a source
operand to a destination operand. These operands can be internal registers of the
8086 and storage locations in memory.
Mnemonic Meaning Format Operation Flags affected
MOV Move MOV D,S (S) → (D) None
These instructions add a number from some source to a number in some destination and put the
result in the specified destination. The ADC also adds the status of the carry flag to the result. The
source may be an immediate number, a register, or a memory location. The destination may be a
register or a memory location. The source and the destination in an instruction cannot both be
memory locations. The source and the destination must be of the same type (bytes or words). If
you want to add a byte to a word, you must copy the byte to a word location and fill the upper
byte of the word with 0’s before adding. Flags affected: AF, CF, OF, SF, ZF.
ADD AL, 74H ; Add immediate number 74H to content of AL. Result in AL
ADC CL, BL ;Add content of BL plus carry status to content of CL(CL = CL+BL+Carry
Flag)
ADD DX, BX ; Add content of BX to content of DX
ADD DX, [SI] ;Add word from memory at offset [SI] in DS to content of DX
Output:
Output:
PROGRAM -3 (Using Registers and Immediate Data)
Similarly all the above four programs can be repeated using 16 bit numbers.
Conclusion: The internal registers alogwith FLAG register is understood and 8-bit and 16-
bit addition is implemented.
EXPERIMENT No. 3
Objectives:
To use different addressing modes and understand the method of subtraction in 8086.
Theory
8086 ADDRESSING MODES
In the above two examples, the source operand is in immediate mode and the destination operand
is in register mode. A constant such as “VALUE” can be defined by the assembler EQUATE
directive such as VALUE EQU 35H
Example : MOV BH, VALUE
Used to load 35 H into BH
In the direct addressing mode, the 16 bit effective address (EA) is taken directly from the
displacement field of the instruction.
Example 1 : MOV CX, START
If the 16 bit value assigned to the offset START by the programmer using an
assembler pseudo instruction such as DW is 0040 and [DS] = 3050.
Then BIU generates the 20 bit physical address 30540 H.
The content of 30540 is moved to CL
The content of 30541 is moved to CH
Result in CH
SUB AX, 3427H Subtract immediate number 3427H from AX
SBB BX, [3427H] Subtract word at displacement 3427H in DS and content of CF
Decrement Instruction
DEC – DEC Destination
This instruction subtracts 1 from the destination word or byte. The destination can be a register or
a memory location. AF, OF, SF, PF, and ZF are updated, but CF is not affected. This means that if
an 8-bit destination containing 00H or a 16-bit destination containing 0000H is decremented, the
result will be FFH or FFFFH with no carry (borrow).
DEC CL Subtract 1 from content of CL register
DEC BP Subtract 1 from content of BP register
DEC BYTE PTR [BX] Subtract 1 from byte at offset [BX] in DS.
DEC WORD PTR [BP] Subtract 1 from a word at offset [BP] in SS.
DEC COUNT Subtract 1 from byte or word named COUNT in DS.
Increment instruction
INC – INC Destination
The INC instruction adds 1 to a specified register or to a memory location. AF, OF, PF, SF, and
ZF are updated, but CF is not affected. This means that if an 8-bit destination containing FFH or a
16-bit destination containing FFFFH is incremented, the result will be all 0’s with no carry.
Program:
8. Bit programs-
(Using registers)
MOV AL,09H ;Load immediate data 09h to register AL
MOV BL,06H ; Load immediate data to register BL
SUB AL, BL ;AL=AL-BL
Output-
(Using register and immediate data)
Output-
16 bit Program:
(Using Registers)
Conclusion: Thus the addressing modes are studied and the 8-bit and 16-bit subtraction is
implemented,
EXPERIMENT No.4
Objectives:
To get acquainted with the stack related instructions and operations.
To understand the concept of negative result ater subtraction and interpret the result
correctly.
Theory:
Program-
Objectives:
To study string related operations with the help of string instructions.
To use Multiplication instruction for 8 bit and 16 bit numbers.
Theory:
MOV DI, OFFSET DESTINATION Load offset of start of destination string in ES into DI
CLD Clear DF to auto increment SI and DI after move
MOV CX, 04H Load length of string into CX as counter
REP MOVSB Move string byte until CX = 0
LODS / LODSB / LODSW (LOAD STRING BYTE INTO AL OR STRING WORD INTO
AX)
This instruction copies a byte from a string location pointed to by SI to AL, or a word from a
string location pointed to by SI to AX. If DF is 0, SI will be automatically incremented (by 1 for a
byte string, and 2 for a word string) to point to the next element of the string. If DF is 1, SI will
be automatically decremented (by 1 for a byte string, and 2 for a word string) to point to the
previous element of the string. LODS does not affect any flag.
CLD Clear direction flag so that SI is auto-incremented
STOSB
“B” added to STOSB mnemonic tells assembler to replace byte in string with byte from AL.
STOSW would tell assembler directly to replace a word in the string with a word from AX.
REPE CMPSB Compare string bytes until end of string or until string bytes not equal.
REPNE and REPNZ are also two mnemonics for the same prefix. They stand for repeat if not
equal and repeat if not zero, respectively. They are often used with the Compare String instruction
or with the Scan String instruction. They will cause the string instruction to be repeated as long as
the compared bytes or words are not equal (ZF = 0) and CX is not yet counted down to zero.
REPNE SCASW Scan a string of word until a word in the string matches the word
Program-
8 bit multiplication
MOV AX,04H ;MOVE 04H TO REGISTER AX
MOV BX,05H ;MOVE 05H TO REGISTER BX
MUL BX ;ax=ax*bx
16 bit multiplication
MOV AX, 0111H ;MOVE 0111H TO REGISTER AX
MOV BX, 1212H ;MOVE 1212H TO REGISTER BX
MUL BX ;AX=AX*BX
Conclusion: Thus the string instructions are studied and multiplication for 8 bit and 16 bit
multiplication.
EXPERIMENT No. 6
Objectives:
Describe the conditional and unconditional jump instructions.
To study and implement the division instructions.
Theory:
CWB
CWD
TRANSFER-OF-CONTROL INSTRUCTIONS
This instruction fetches the next instruction from address at label CONTINUE. If the label is in
the same segment, an offset coded as part of the instruction will be added to the instruction
pointer to produce the new fetch address. If the label is another segment, then IP and CS will be
replaced with value coded in part of the instruction. This type of jump is referred to as direct
because the displacement of the destination or the destination itself is specified directly in the
instruction.
JNLE NEXT Jump to label NEXT if BL is not less than or equal to 39H
JGE / JNL (JUMP IF GREATER THAN OR EQUAL / JUMP IF NOT LESS THAN)
This instruction is usually used after a Compare instruction. The instruction will cause a jump to
the label given in the instruction, if the sign flag is equal to the overflow flag.
CMP BL, 39H Compare by subtracting 39H from BL
JGE NEXT Jump to label NEXT if BL more positive than or equal to 39H
CMP BL, 39H Compare by subtracting 39H from BL
JNGE AGAIN Jump to label AGAIN if BL not more positive than or equal to
39H
JLE / JNG (JUMP IF LESS THAN OR EQUAL / JUMP IF NOT GREATER)
This instruction is usually used after a Compare instruction. The instruction will cause a jump to
the label given in the instruction if the zero flag is set, or if the sign flag not equal to the overflow
flag.
CMP BL, 39H Compare by subtracting 39H from BL
JLE NEXT Jump to label NEXT if BL more negative than or equal to 39H
CMP BL, 39H Compare by subtracting 39H from BL
JNG NEXT Jump to label NEXT if BL not more positive than 39H
JE / JZ (JUMP IF EQUAL / JUMP IF ZERO)
This instruction is usually used after a Compare instruction. If the zero flag is set, then this
instruction will cause a jump to the label given in the instruction.
CMP BX, DX Compare (BX-DX)
DEC BX Decrement BX
JNZ NEXT Jump to label NEXT if BX 0
JS (JUMP IF SIGNED / JUMP IF NEGATIVE)
This instruction will cause a jump to the specified destination address if the sign flag is set. Since
a 1 in the sign flag indicates a negative signed number, you can think of this instruction as saying
“jump if negative”.
ADD BL, DH Add signed byte in DH to signed byte in DL
JO (JUMP IF OVERFLOW)
The overflow flag will be set if the magnitude of the result produced by some signed arithmetic
operation is too large to fit in the destination register or memory location. The JO instruction will
cause a jump to the destination given in the instruction, if the overflow flag is set.
ADD AL, BL Add signed bytes in AL and BL
Program-
8 bit division
MOV AX,20H
MOV BX,10H
DIV BX
16 bit division
MOV DX,0102H
MOV AX,1000H
MOV BX,1010H
DIV BX
AIM - Write an assembly language program to check whether entered number is even
or odd.
Objectives:
Describe the Miscellaneous Data Transfer Instructions.
To study and implement the jump instructions to find whether entered number is even
or odd.
Theory:
Miscellaneous Data Transfer Instructions
CMP – CMP Destination, Source
This instruction compares a byte / word in the specified source with a byte / word in the specified
destination. The source can be an immediate number, a register, or a memory location. The
destination can be a register or a memory location. However, the source and the destination
cannot both be memory locations. The comparison is actually done by subtracting the source byte
or word from the destination byte or word. The source and the destination are not changed, but
the flags are set to indicate the results of the comparison. AF, OF, SF, ZF, PF, and CF are updated
by the CMP instruction. For the instruction CMP CX, BX, the values of CF, ZF, and SF will be as
follows:
CF ZF SF
CX = BX 0 1 0 Result of subtraction is 0
CX > BX 0 0 0 No borrow required, so CF = 0
CX < BX 1 0 1 Subtraction requires borrow, so CF = 1
CMP AL, 01H Compare immediate number 01H with byte in AL
CMP BH, CL Compare byte in CL with byte in BH
CMP CX, TEMP Compare word in DS at displacement TEMP with word at CX
IN – IN Accumulator, Port
The IN instruction copies data from a port to the AL or AX register. If an 8-bit port is read, the
data will go to AL. If a 16-bit port is read, the data will go to AX.
The IN instruction has two possible formats, fixed port and variable port. For fixed port type, the
8-bit address of a port is specified directly in the instruction. With this form, any one of 256
possible ports can be addressed.
IN AL, OC8H Input a byte from port OC8H to AL
IN AX, 34H Input a word from port 34H to AX
For the variable-port form of the IN instruction, the port address is loaded into the DX register
before the IN instruction. Since DX is a 16-bit register, the port address can be any number
between 0000H and FFFFH. Therefore, up to 65,536 ports are addressable in this mode.
MOV DX, 0FF78H Initialize DX to point to port
For variable port form of the OUT instruction, the content of AL or AX will be copied to the port
at an address contained in DX. Therefore, the DX register must be loaded with the desired port
address before this form of the OUT instruction is used.
MOV DX, 0FFF8H Load desired port address in DX
Conclusion: Thus the program for even and odd number is implemented.
EXPERIMENT No.8
Objectives:
Describe the Logical Instructions.
To study and implement the concept of arrays in Assembly Language Programming.
Theory:
LOGICAL INSTRUCTIONS
AND – AND Destination, Source
This instruction ANDs each bit in a source byte or word with the same numbered bit in a
destination byte or word. The result is put in the specified destination. The content of the
specified source is not changed.
The source can be an immediate number, the content of a register, or the content of a memory
location. The destination can be a register or a memory location. The source and the destination
cannot both be memory locations. CF and OF are both 0 after AND. PF, SF, and ZF are updated
by the AND instruction. AF is undefined. PF has meaning only for an 8-bit operand.
AND CX, [SI] AND word in DS at offset [SI] with word in CX register;
Result in CX register
AND BH, CL AND byte in CL with byte in BH; Result in BH
AND BX, 00FFH 00FFH Masks upper byte, leaves lower byte unchanged.
OR – OR Destination, Source
This instruction ORs each bit in a source byte or word with the same numbered bit in a
destination byte or word. The result is put in the specified destination. The content of the
specified source is not changed.
The source can be an immediate number, the content of a register, or the content of a memory
location. The destination can be a register or a memory location. The source and destination
cannot both be memory locations. CF and OF are both 0 after OR. PF, SF, and ZF are updated by
the OR instruction. AF is undefined. PF has meaning only for an 8-bit operand.
OR AH, CL CL ORed with AH, result in AH, CL not changed
OR BP, SI SI ORed with BP, result in BP, SI not changed
OR SI, BP BP ORed with SI, result in SI, BP not changed
OR BL, 80H BL ORed with immediate number 80H; sets MSB of BL to 1
Program
.MODEL SMALL
.DATA
ARR DB 01H,02H,03H,04H,05H
.CODE
.STARTUP
MOV AX,00H
MOV CL,05H
MOV SI,00H
BACK:
ADD AL, ARR[SI]
INC SI
DEC CL
JNZ BACK
MOV BL,05H
DIV BL
.EXIT
END
Output-
Conclusion: Thus the concept of Arrays are studied and implemented to find average of
temperatures.
EXPERIMENT No.9
AIM : Write an assembly language program to perform sum of digits for 2, 3 digits
Numbers.
Objectives:
Describe the Rotate and Shift Instructions.
To implement the Rotate and Shift Instructions to perform sum of digits for 2, 3 digits
Numbers.
Theory:
ROTATE AND SHIFT INSTRUCTIONS
For multi-bit rotates, CF will contain the bit most recently rotated out of the MSB.
The destination can be a register or a memory location. If you want to rotate the operand by one
bit position, you can specify this by putting a 1 in the count position of the instruction. To rotate
by more than one bit position, load the desired number into the CL register and put “CL” in the
count position of the instruction.
RCL affects only CF and OF. OF will be a 1 after a single bit RCL if the MSB was changed by
the rotate. OF is undefined after the multi-bit rotate.
RCL DX, 1 Word in DX 1 bit left, MSB to CF, CF to LSB
MOV CL, 4 Load the number of bit positions to rotate into CL
RCL SUM [BX], CL Rotate byte or word at effective address SUM [BX] 4 bits left
Original bit 4 now in CF, original CF now in bit 3.
For multi-bit rotate, CF will contain the bit most recently rotated out of the LSB.
The destination can be a register or a memory location. If you want to rotate the operand by one
bit position, you can specify this by putting a 1 in the count position of the instruction. To rotate
more than one bit position, load the desired number into the CL register and put “CL” in the count
position of the instruction.
RCR affects only CF and OF. OF will be a 1 after a single bit RCR if the MSB was changed by
the rotate. OF is undefined after the multi-bit rotate.
RCR BX, 1 Word in BX right 1 bit, CF to MSB, LSB to CF
MOV CL, 4 Load CL for rotating 4 bit position
RCR BYTE PTR [BX], 4 Rotate the byte at offset [BX] in DS 4 bit positions right
CF = original bit 3, Bit 4 – original CF.
The destination can be a register or a memory location. If you to want rotate the operand by one
bit position, you can specify this by putting 1 in the count position in the instruction. To rotate
more than one bit position, load the desired number into the CL register and put “CL” in the count
position of the instruction.
ROL affects only CF and OF. OF will be a 1 after a single bit ROL if the MSB was changed by
the rotate.
ROL AX, 1 Rotate the word in AX 1 bit position left, MSB to LSB and CF
MOV CL, 04H Load number of bits to rotate in CL
The destination can be a register or a memory location. If you want to rotate the operand by one
bit position, you can specify this by putting 1 in the count position in the instruction. To rotate by
more than one bit position, load the desired number into the CL register and put “CL” in the count
position of the instruction.
ROR affects only CF and OF. OF will be a 1 after a single bit ROR if the MSB was changed by
the rotate.
ROR BL, 1 Rotate all bits in BL right 1 bit position LSB to MSB and to CF
MOV CL, 08H Load CL with number of bit positions to be rotated
ROR WORD PTR [BX], CL Rotate word in DS at offset [BX] 8 bit position right
The destination operand can be a byte or a word. It can be in a register or in a memory location. If
you want to shift the operand by one bit position, you can specify this by putting a 1 in the count
position of the instruction. For shifts of more than 1 bit position, load the desired number of shifts
into the CL register, and put “CL” in the count position of the instruction.
The flags are affected as follow: CF contains the bit most recently shifted out from MSB. For a
count of one, OF will be 1 if CF and the current MSB are not the same. For multiple-bit shifts,
OF is undefined. SF and ZF will be updated to reflect the condition of the destination. PF will
have meaning only for an operand in AL. AF is undefined.
SAL BX, 1 Shift word in BX 1 bit position left, 0 in LSB
MOV CL, 02h Load desired number of shifts in CL
The destination operand can be a byte or a word. It can be in a register or in a memory location. If
you want to shift the operand by one bit position, you can specify this by putting a 1 in the count
position of the instruction. For shifts of more than 1 bit position, load the desired number of shifts
into the CL register, and put “CL” in the count position of the instruction.
The flags are affected as follow: CF contains the bit most recently shifted in from LSB. For a
count of one, OF will be 1 if the two MSBs are not the same. After a multi-bit SAR, OF will be 0.
SF and ZF will be updated to show the condition of the destination. PF will have meaning only
for an 8- bit destination. AF will be undefined after SAR.
SAR DX, 1 Shift word in DI one bit position right, new MSB = old MSB
MOV CL, 02H Load desired number of shifts in CL
SHR – SHR Destination, Count
This instruction shifts each bit in the specified destination some number of bit positions to the
right. As a bit is shifted out of the MSB position, a 0 is put in its place. The bit shifted out of the
LSB position goes to CF. In the case of multi-bit shifts, CF will contain the bit most recently
shifted out from the LSB. Bits shifted into CF previously will be lost
The destination operand can be a byte or a word in a register or in a memory location. If you want
to shift the operand by one bit position, you can specify this by putting a 1 in the count position of
the instruction. For shifts of more than 1 bit position, load the desired number of shifts into the
CL register, and put “CL” in the count position of the instruction.
The flags are affected by SHR as follow: CF contains the bit most recently shifted out from LSB.
For a count of one, OF will be 1 if the two MSBs are not both 0’s. For multiple-bit shifts, OF will
be meaningless. SF and ZF will be updated to show the condition of the destination. PF will have
meaning only for an 8-bit destination. AF is undefined.
SHR BP, 1 Shift word in BP one bit position right, 0 in MSB
MOV CL, 03H Load desired number of shifts into CL
SHR BYTE PTR [BX] Shift byte in DS at offset [BX] 3 bits right; 0’s in 3 MSBs
Program-
2 Digit Addition
.MODEL SMALL
.DATA
N1 DB 23H
.CODE
.STARTUP
MOV AL,N1
MOV BL,AL
AND AL,0FH
AND BL,0F0H
ROR BL,04H
ADD BL,AL
.EXIT
END
Output-
3 Digit Addition
.MODEL SMALL
.DATA
N1 DW 0234H
.CODE
.STARTUP
MOV AX,N1
MOV BX,AX
MOV CX,AX
AND AX,000FH
AND BX,00F0H
ROR BX,04H
AND CX,0F00H
ROR CX,08H
ADD BX,AX
ADD BX,CX
.EXIT
END
Output
Conclusion: Thus the Rotate and Shift instructions were studied and implemented to perform
sum of digits for 2, 3 digits Numbers.
EXPERIMENT No.10
AIM – Write an assembly language program to perform conversion from two ASCII
no’s to packed BCD.
Objectives:
To study the concept of ASCII in Assembly Language programming.
To implement the instructions related to ASCII arithmetic.
Theory:
ASCII Arithmetic
AAA (ASCII ADJUST FOR ADDITION)
Numerical data coming into a computer from a terminal is usually in ASCII code. In this code,
the numbers 0 to 9 are represented by the ASCII codes 30H to 39H. The 8086 allows you to add
the ASCII codes for two decimal digits without masking off the “3” in the upper nibble of each.
After the addition, the AAA instruction is used to make sure the result is the correct unpacked
BCD.
Let AL = 0011 0101 (ASCII 5), and BL = 0011 1001 (ASCII 9)
Output-
Conclusion: Thus the ASCII arithmetic instructions were studied and implemented.
EXPERIMENT No.11
AIM – Write an assembly language program to perform conversion from
BCD to Hex.
Objectives:
To study the concept of BCD in Assembly Language programming.
To implement the instructions related to BCD arithmetic.
Theory:
BCD Arithmetic
Program-
MOV BH,35H ; Load value 35h in register BH
MOV AL,47H ; Load value 47h in register BH
ADD AL,BH ; Perform the hex addition that result in AL=7C H
DAA ; since lower nibble >09 , 06h is added to the result ,
; result is 7C + 06 = 82 H
Output
MOV BH,47H
MOV AL,35H
SUB BH,AL
MOV AL,BH
DAS
Output
Conclusion- Thus the BCD arithmetic instructions were studied and implemented.
EXPERIMENT No.12
AIM – To study an assembly language program to interface stepper motor using 8255.
Objectives:
To study the 8255 IC and interface the stepper motor using 8255.
Theory:
Stepper motor is a device used to obtain an accurate position control of rotating shafts. A stepper
motor employs rotation of its shaft in terms of steps, rather than continuous rotation as in case of
AC or DC motor. To rotate the shaft of the stepper motor, a sequence of pulses is needed to be
applied to the windings of the stepper motor, in proper sequence. The numbers of pulses required
for complete rotation of the shaft of the stepper motor are equal to the number of internal teeth on
its rotor. The stator teeth and the rotor teeth lock with each other to fix a position of the shaft.
With a pulse applied to the winding input, the rotor rotates by one teeth position or an angle x. the
angle x may be calculated as.
x = 3600 / no. of rotor teeth
After the rotation of the shaft through angle x, the rotor locks it self with the next tooth in the
sequence on the internal surface of the stator. The typical schematic of a typical stepper motor
with four windings is as shown below.
MOV AL,PHASEB
MOV DX,PORTC
OUT DX,AL
MOV CX,0FFFFH
UP1:
LOOP UP1
MOV AL,PHASED
MOV DX,PORTC
OUT DX,AL
MOV CX,0FFFFH
UP2:
LOOP UP2
MOV AL,PHASEA
MOV DX,PORTC
OUT DX,AL
MOV CX,0FFFFH
UP3:
LOOP UP3
JMP AGAIN ; REPEATE OUTPUT SEQUENCE
INT 03H
END START
.CODE
START:
MOV AL,@DATA
MOV DX,CTL
OUT DX,AL
AGAIN:
MOV AL,PHASEC
MOV DX,PORTC
OUT DX,AL
MOV CX,0FFFFH
UP:
LOOP UP
MOV AL,PHASEA
MOV DX,PORTC
OUT DX,AL
MOV CX,0FFFFH
UP1:
LOOP UP1
MOV AL,PHASED
MOV DX,PORTC
OUT DX,AL
MOV CX,0FFFFH
UP2:
LOOP UP2
MOV AL,PHASEB
MOV DX,PORTC
OUT DX,AL
MOV CX,0FFFFH
UP3:
LOOP UP3
JMP AGAIN ; REPEATE OUTPUT SEQUENCE
INT 03H
END START
PROCEDURE:-
1. Connect power supply 5V & GND to both microprocessor trainer kit & Stepper motor
interfacing kit.
2. Connect data bus between microprocessor trainer kit & Stepper motor interfacing kit.
3. Enter the program to rotate Stepper motor in clockwise & anticlockwise.
4. Execute the program by typing GO E000:00C0 ENTER for clockwise, GO E000:0030 ENTER
for anticlockwise.
5. Observe the rotation of stepper motor.
Conclusion: Thus the program and procedure to interface stepper motor using 8255.