0% found this document useful (0 votes)
737 views19 pages

MP Lab Manual

The document provides details about a laboratory manual for a subject on microprocessors. It includes an introduction and list of 12 experiments. The first experiment provides an overview of the 8086 microprocessor instruction set including data transfer, arithmetic, logical, branch, stack I/O, and machine control instructions. It also provides steps for executing assembly language programs using TASM assembler.

Uploaded by

GebBerhe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
737 views19 pages

MP Lab Manual

The document provides details about a laboratory manual for a subject on microprocessors. It includes an introduction and list of 12 experiments. The first experiment provides an overview of the 8086 microprocessor instruction set including data transfer, arithmetic, logical, branch, stack I/O, and machine control instructions. It also provides steps for executing assembly language programs using TASM assembler.

Uploaded by

GebBerhe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

TECHNOLOGY

RAMRAO ADIK INSTITUTE OF


Department Of Computer Engineering
Even Semester 2015-16

Laboratory Manual

Subject : Microprocessor

Experiment List :
Exp.
No.

Name of the experiment

1.

To study about instruction set of 8086 Microprocessor.

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.

Write an assembly language program to find the number / string is palindrome or


not.

3.

9.

Write an assembly language program to sort elements in ascending /descending


order.
Write an assembly language program to find the factorial of a number using
procedure.
Write a program to separate even or odd numbers from array using mixed language
programming.
Write a program to search number in an array using mixed language programming.

10.

Write a program to perform for a 5-stage scalar pipeline (Non Linear Pipeline).

11.

To Study The Effect Of Branch Operation On Linear Pipeline.

12.

To Study about pipelining in superscalar processor.

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

Load Register Pair with Immediate data


Load Accumulator from Address in Register Pair
Store Accumulator in Address in Register Pair
Exchange H & L with D & E
Exchange Top of Stack with H & L

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

Logical AND with Accumulator


Logical AND with Accumulator Using Immediate Data
Logical OR with Accumulator
Logical OR with Accumulator Using Immediate Data
Exclusive Logical OR with Accumulator
Exclusive OR Using Immediate Data

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

Rotate Accumulator Left


Rotate Accumulator Right
Rotate Left Through Carry
Rotate Right Through Carry

Complement and carry flag instructions:


CMA
CMC
STC

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)

Thus, the conditional branching instructions are specified as follows:


Jumps
C
INC
JZ
JNZ
JP
JM
JPE
JP0

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

Move H & L to Program Counter


Special Restart Instruction Used
with Interrupts

Stack I/O, and Machine Control Instructions:


The following instructions affect the Stack and/or Stack Pointer:
PUSH
POP
XTHL
SPHL

Push Two bytes of Data onto the Stack


Pop Two Bytes of Data off the Stack
Exchange Top of Stack with H & L
Move content of H & L to Stack Pointer

The I/0 instructions are as follows:


IN
OUT

Initiate Input Operation


Initiate Output Operation

The Machine Control instructions are as follows:


EI
Enable Interrupt System
DI
Disable Interrupt System
HLT
Halt
NOP
No Operation

Procedure for execute the Assembly program using TASM

Assembly language programs are converted into executable machine code by a


utility program referred to as an assembler, the conversion process being referred
to as assembly or assembling the program.

Assembly language (sometimes abbreviated as ASM, usually as the file


extension for a text file which is used as a code for a program written in Assembly
language, or in the names of assemblers, like FASM, MASM, NASM and TASM)
is a low-level programming language for computers, microprocessors,
microcontrollers, and other programmable devices in which each statement
corresponds to a single machine language instruction. An assembly language is
specific to a certain computer architecture, in contrast to most high-level
programming languages, which generally are portable to multiple systems.

What is TASM assembler?


The Turbo Assembler (TASM) is an x86 assembler that uses the Intel syntax for
MS-DOS and Microsoft Windows. Beginning with TASM 8.0 there are two versions
of the assembler - one for 16-bit and 32-bit assembly sources, and another (ML64)
for 64-bit sources only.

Assembling and Running Assembly Language Programs


An assembly language program must be assembled and linked before it can be
executed.
The assembler produces an object file (extension .OBJ). This file is taken by the
linker and an executable program (extension .EXE) is produced, assuming there were
no
errors
in
the
program. We use the MASM assembler and the LINK linker. These are available on
NAL
under
Programming: TASM files v 5.0.
When saving the file with Notepad, you MUST save it with the File Type set to
All
Files.
You should now select the MS-DOS Prompt (Command PROMPT) from the Start
button menu (sometimes under Programs option)

To do assembly language programming TASM assembler you can


follow these steps:
Following are steps to execute a assembly program in tasm assembler.
1. Save .asm extention file by writing code in text editor.
2. Open dos prompt
3. Go the target file by prompt
4. Write tasm filename.asm and press enter
5. Write tlink filename.obj and press enter
6. Write debug filename.exe and press enter
7. Cursor will be displayed. Press t for single step debugging mode otherwise g for
direct compilation.
Tasm folder must contains
Tasm exe
Tlink exe
Td.exe
Following are steps to execute a mixed language program in TURBOC.
1. Write a program in turbo c editor and save it as .cpp file
2. Go the compile
3. Run the compile file
Note: GUI based Emulator 8086 can also be used to write and execute assembly
programs.
In the event of errors, you must edit your program and correct the errors. Then you

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 :

Load a DOS function number in AH register. If there is a sub-function then it


is loaded in AL register.

Load the other registers as indicated in the DOS service formats.

Prepare buffers, ASCIIZ (ASCII string terminated by zero) and control blocks
if necessary.

Set the location of the disk area 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:

Declare Hello world as string


Initialize to program's Data Segment
Use DOS Function 09 H to Display a string and interrupt Int 21h
Execute DOS Function.

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

Add two numbers


Syntax: add
dest, src
dest: register or memory
src: register, memory, or immediate
Action: dest = dest + src
Flags Affected: OF, SF, ZF, AF, PF, CF
Notes: Works for both signed and unsigned numbers.
For
example
:

AX =
1234
H
BX =
0100
H

1234
H
+

0100
H
1334
H

SUB

Subtract two numbers


Syntax: sub
dest, src
dest: regsiter or memory
src: register, memory, or immediate
Action: dest = dest - src
Flags Affected: OF, SF, ZF, AF, PF, CF
Notes: Works for both signed and unsigned numbers.

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

op8: 8-bit register or memory


op16: 16-bit register or
memory
Action: If operand is op8, unsigned AL = AX / op8 and AH = AX % op8
If operand is op16, unsigned AX = DX::AX / op16 and DX = DX::AX %
op16
Flags Affected: OF=?, SF=?, ZF=?, AF=?, PF=?, CF=?
Notes: Performs both division and modulus operations in one instruction.

IDIV
Syntax:

Signed
divide
idiv
op8
idiv
op16

op8: 8-bit register or memory


op16: 16-bit register or
memory
Action: If operand is op8, signed AL = AX / op8 and AH = AX % op8
If operand is op16, signed AX = DX::AX / op16 and DX = DX::AX %
op16 Flags Affected: OF=?, SF=?, ZF=?, AF=?, PF=?, CF=?
Notes: Performs both division and modulus operations in one instruction.

IMUL
Syntax:

Signed
multiply
imul
op8
imul
op16

op8: 8-bit register or memory


op16: 16-bit register or
memory
Action: If operand is op8, signed AX = AL * op8
If operand is op16, signed DX::AX = AX * op16
Flags Affected: OF, SF=?, ZF=?, AF=?, PF=?, CF

Algorithm :

Initialize the data segment.


Get the first number in AX register.
Get the second number in BX register.
Perform arithmetic operation on two numbers.
Display the AX/DX result.
Stop.

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.

Let the number of bytes N = 10.

We will have to initialize this as count in the CX register.

We know that source address is in the SI register and destination address is in the
DI register.

Clear the direction flag.

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 :

Initialize the data in the source memory and destination memory.

Initialize SI and DI with source and destination address.

Initialize CX register with the count.

Initialize the direction flag to zero.

Transfer the data block byte by byte to destination.

Decrement CX.

Check for count in CX, if not zero go to step 5 else to step 8.

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.

Initialize pointer at the start of string.

Initialize pointer at the end of string.

Initialize counter = length/2.

Decrement counter.

All Character equal if yes, display the message.

Is count = 0 if yes display the message string is palindrome else go to step 5.

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 :

Declare 10 elements array.

Put 1st number in accumulator i.e AX.

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.

Transfer this accumulator content in new memory location USING MOV.

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 the Data Segment.

Initialize AX = 1.

Load the number in BX.

Call procedure fact.

Compare BX with 1, if not go to step 7.

AX = 1 and return back to the calling program.

AX = AX BX.

Decrement BX.

Compare BX with 1, if not go to step 7.

Return back to calling program.

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

instruction set and number of registers can be used.


In c++ , every integer will take 2 bytes therefore for accessing any
element using from array assembly pointer should increment and
decrement by 2.
Algorithm :

Accept array of elements using cin or scanf functions.

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.

Display respective even and odd arrays.

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 :

Declare array of 10 elements in c++ .

Accept number which is to be searched.

Compare number either by CMP or SCAS.

Use interrupt to display found message if it is found.

Else exit the loop.

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 :

You might also like