MP Lab Manual
MP Lab Manual
Laboratory Manual
Subject : Microprocessor
Experiment List :
Exp.
No.
1.
2.
4.
Write an assembly language program to accept and display Hello World on screen
using DOS / BIOS.
Write an assembly language program to implement basic arithmetic operations on
two 8 / 16 bit numbers.
Write an assembly language program to transfer data block using string instructions
and without using string instructions.
5.
3.
9.
10.
Write a program to perform for a 5-stage scalar pipeline (Non Linear Pipeline).
11.
12.
6.
7.
8.
Experiment No : 1
Aim : To study about instruction set of 8086 Microprocessor.
Theory :
8086 INSTRUCTION SET
The mnemonics assigned to the instructions are designed to indicate the function of the
instruction. The instructions fall into the following functional categories:
1. Data Transfer Croup:
The data transfer instructions move data between registers or between memory and
registers.
MOV
MVI
LDA
STA
LHLD
SHLD
Move
Move Immediate
Load Accumulator Directly from Memory
Store Accumulator Directly in Memory
Load H & L Registers Directly from Memory
Store H & L Registers Directly in Memory
An 'X' in the name of a data transfer instruction implies that it deals with a register pair
(16-bits);
LXI
LDAX
STAX
XCHG
XTHL
2. Arithmetic Group:
The arithmetic instructions add, subtract, increment, or decrement data in registers or
memory.
ADD
ADI
ADC
ACI
SUB
SUI
SBB
SBI
INR
DCR
INX
DCX
DAD
Add to Accumulator
Add Immediate Data to Accumulator
Add to Accumulator Using Carry Flag
Add Immediate data to Accumulator Using Carry
Subtract from Accumulator
Subtract Immediate Data from Accumulator
Subtract from Accumulator Using Borrow (Carry) Flag
Subtract Immediate from Accumulator Using Borrow (Carry) Flag
Increment Specified Byte by One
Decrement Specified Byte by One
Increment Register Pair by One
Decrement Register Pair by One
Double Register Add; Add Content of Register
Pair to H & L Register Pair
3. Logical Group:
This group performs logical (Boolean) operations on data in registers and memory and on
condition flags.
The logical AND, OR, and Exclusive OR instructions enable you to set specific bits in
the accumulator ON or OFF.
ANA
ANI
ORA
OR
XRA
XRI
The Compare instructions compare the content of an 8-bit value with the contents of the
accumulator;
CMP
CPI
Compare
Compare Using Immediate Data
The rotate instructions shift the contents of the accumulator one bit position to the left or
right:
RLC
RRC
RAL
RAR
Complement Accumulator
Complement Carry Flag
Set Carry Flag
4. Branch Group:
The branching instructions alter normal sequential program flow, either unconditionally
or conditionally. The unconditional branching instructions are as follows:
JMP
CALL
RET
Jump
Call
Return
Conditional branching instructions examine the status of one of four condition flags to
determine whether the specified branch is to be executed. The conditions that may be
specified are as follows:
NZ
Z
NC
C
PO
PE
P
M
Not Zero (Z =
Zero (Z = 1)
No Carry (C =
Carry (C = 1)
Parity Odd (P
Parity Even (P
Plus (S = 0)
Minus (S = 1)
0)
0)
= 0)
= 1)
Calls
CC
CNC
CZ
CNZ
CP
CM
CPE
CPO
Returns
RC
RNC
RZ
RNZ
RP
RM
RPE
RPO
(Carry)
(No Carry)
(Zero)
(Not Zero)
(Plus)
(Minus)
(Parity Even)
(Parity Odd)
Two other instructions can affect a branch by replacing the contents or the program
counter:
PCHL
RST
repeat the above steps to assemble and link your program, before running it.
Similarly, if you modify your program, you must assemble and link it before running
it again.
Experiment No : 2
Aim : Write an assembly language program to accept and display Hello World on
screen using DOS / BIOS.
Theory :
For 8086 two types interrupt can be generated software and software
The DOS (Disk Operating System) provides a large number of procedures to access
devices, files and memory. These procedures can be called in any user program
using software interrupts INT n instruction.
The steps involved in accessing DOS services are :
Prepare buffers, ASCIIZ (ASCII string terminated by zero) and control blocks
if necessary.
Invoke DOS service INT 21H which will return the required parameters in
the specified register.
Many software programs written for 8086 computers are designed to run under the
MS-DOS operation system. Included as part of this operating system are the DOS
functions and BIOS calls. These are subprograms, callable from applications
software,that can be used to access the hardware of the PC. The intention is to save
the programmer from having to reinvent the wheel with each new applications
program. In addition, by providing a standard set of input/output routines, these
subprograms ensure software compatibility between computers with different
hardware configurations.
The BIOS routines are the most primitive in a computer as they talk
directly to the system hardware. Accordingly, the BIOS is hardware specific that is ,
it must know the exact port address and control bit configurations for each I/O
Algorithm:
Conclusion:
Experiment No : 3
Aim : Write an assembly language program to implement basic arithmetic operations on
two 8 / 16 bit numbers.
Theory :
Following instruction may be used for implementation and its formats are as follows
ADD
AX =
1234
H
BX =
0100
H
1234
H
+
0100
H
1334
H
SUB
MUL
Unsigned multiply
Syntax:
mul
op8
mul op16 op8: 8bit register or memory
op16: 16-bit register or memory
Action: If operand is op8, unsigned AX = AL * op8
If operand is op16, unsigned DX::AX = AX *
op16 Flags Affected: OF, SF=?, ZF=?, AF=?, PF=?,
CF
DIV
Syntax:
Unsigned
divide
div
op8
div
op16
IDIV
Syntax:
Signed
divide
idiv
op8
idiv
op16
IMUL
Syntax:
Signed
multiply
imul
op8
imul
op16
Algorithm :
Flow Chart :
Conclusion :
Experiment No : 4
Aim : Write an assembly language program to transfer data block using string
instructions and without using string instructions.
Theory :
Consider that a block of data of N bytes is present at source location. Now this
block of N bytes is to be moved from source location to a destination location.
We know that source address is in the SI register and destination address is in the
DI register.
Using the string instruction move the data from source location to the destination
location. It is assumed that data is moved within the same segment. Hence the DS
and ES are initialized to the same segment value.
Algorithm :
Decrement CX.
Stop.
Flowchart :
Conclusion :
Experiment No : 5
Aim : Write an assembly language program to find the number / string is palindrome or
not.
Theory :
This program is used to check whether the given string is palindrome or not. Here
palindrome means we compare the character sequence from left to right and right to left
in which they sound same.
Algorithm :
Start.
Decrement counter.
Stop.
Flowchart :
Conclusion :
Experiment No : 6
Aim : Write an assembly language program to sort elements in ascending / descending
order.
Theory :
Bubble sort is basic technique to sort the numbers in ascending or descending order but
writing code in assembly language is bit challenging. Sorting numbers stored in memory
can be performed by transferring every number into register and comparing second
number in memory using CMP instruction. This comparisons can be done for all number
in pair.
Algorithm :
Compare 2nd number with 1st number(ax and memory location) using CMP
Do comparisons with all remaining number and smallest number will be in accumulator
USING LOOP AND JZ/JS INSTRUCTION.
Repeat the same for 2nd smallest number and hence forth all number USING INC SI
AND DI.
Stop.
INSTRUCTION
Flowchart :
Conclusion :
Experiment No : 7
Aim : Write an assembly language program to find the factorial of a number using
procedure.
Theory :
To compute the factorial of a number means to multiply a number n with (n-1) (n2) 2 1.
Example : to compute 5! = 54321=120.
We will initialize AX=1 and load the number whose factorial is to be computed in
BX. Call procedure fact, which will calculate the factorial of the number.
Algorithm :
Initialize AX = 1.
AX = AX BX.
Decrement BX.
Stop.
Flowchart :
No
No
Yes
Conclusion :
Experiment No : 8
Aim : Write a program to separate even or odd numbers from array using mixed language
programming.
Theory :
Mixed-language programming allows you to combine the unique
strengths of C++ with your assembly-language routines. There are some
cases where you want to achieve things using inline assembly, such as
improving speed, reducing memory needs and getting more efficiency.
However, inline assembler is not as powerful as TASM, it does not
support macros or directives.
You can write small assembly language routines within your C or C++
code. These routines are compiled using the inline or embedded
assembler of the TURBOC compiler. However, there are a number of
restrictions to the assembly language code you can write if you are
using the inline or embedded assembler. These restrictions are such as
For every element, check modulus of 2 After bring element into accumulator
register (DIV instruction can be used).
If remainder is zero then it is even otherwise it odd number put into respective
array.
Flowchart :
Conclusion :
Experiment No : 9
Aim : Write a program to search number in an array using mixed language programming.
Theory :
Search for given array can be performed with simple c++ code but using mixed language
program can be quite time consuming since searching array which is defined in high level
language such as c++ or java has more memory allocation than assembly language.
Binary search or sequential search can be applied to achieve this objective. Here in this
case number which is to be found can be stored into register AX and then either simple
CMP OR SCAS can be used to search a number by comparing array with number.
Following figure depicts searching number.
Number to
A[0]
find
A[1]
A[2]
A[3]
A[4]
ax
A[5]
Algorithm :
Flowchart :
Conclusion :
Experiment No : 10
Aim : Write a program to perform for a 5-stage scalar pipeline (Non Linear Pipeline).
Theory :
Experiment No : 11
Aim : To Study The Effect Of Branch Operation On Linear Pipeline.
Theory :
Experiment No : 12
Aim : To Study about pipelining in superscalar processor.
Theory :