Microprocessors AND Microcontrollers Lab ELE306L: Submitted By: Submitted To

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 50

MICROPROCESSORS

AND
MICROCONTROLLERS LAB
ELE306L

Submitted by: Submitted to:


Vidhu Chaudhary Dr. Rahul Vijay
B.Tech CS VI Semester
Section-B
Batch-B2
TABLE OF CONTENTS
S. No. Experiment Page No:
1 Introduction 1
2 Assign a specific value to different segments. 2
3 Differentiate between hexadecimal input and binary input. 3
4 Differentiate between formats of hexadecimal number 4
beginning with alphabet and number.
5 Demonstrate the use of byte pointer. 5
6 Demonstrate the use of ADD, ADC instruction. 7
7 Demonstrate 16-bit addition by using 16-bit registers for 9
each immediate value and store it in user defined address.
8 Demonstrate addition of two 16--bit numbers using the 10
concept of four 8-bit registers.
9 Demonstrate the use of ROL and ROR with single time 11
rotation.
10 Demonstrate the use of ROL and ROR with multiple times 12
rotation using CL register.
11 Demonstrate use of RCL and RCR instructions with single 13
rotation.
12 Demonstrate use of SHL and SHR 8086 instructions. 14
13 Demonstrate use of SAL and SAR 8086 instructions. 15
14 Demonstrate PUSH and POP. 16
15 Find an offset and segment address. 17
16 Print Hello World 18
17 Sum of elements in data segment using LODSB instruction. 20
18 Sum of elements in data segment without LODSB 22
instruction.
19 Demonstrate use of STOSB instruction. 24
20 Demonstrate MOVSB instruction. 26
21 Move data in reverse order. 28
22 Demonstrate use of CMP instruction. 30
23 Check even and odd in array. 31
24 Demonstrate 32-bit addition and store it in user defined 33
address.
25 Number is positive or negative in an array. 35
26 Store minimum digit of the array at AL register. 37
27 Store maximum digit of the array at AL register. 39
28 Bubble sort 41
29 Factorial of a number. 43
30 Square of a number. 45
31 Fibonacci Series 47
INTRODUCTION

8086 emulator is a microprocessor emulator with an integrated 8086 assembler. The emulator
can run programs on a virtual machine, and emulate real hardware including screen, memory
and input/output devices.
It helps in programming assembly language. The source code is compiled by assembler and
then executed on emulator step by step, allowing us to watch registers, flags and memory
while the program runs.
Registers help in speeding up the processor operations, the processor includes some internal
memory storage location called registers.
8086 processor has 8 general purpose registers:
1. AX: The accumulator register (AH/AL)
2. BX: The base address register (BH/BL)
3. CX: The count register (CH/CL)
4. DX: The data register (DH/DL)
5. SI: Source index register
6. DI: Destination index register
7. BP: Base pointer
8. SP: Stack pointer
There are 4 segment registers:
1. CS: Points at segment containing the current program.
2. DS: Generally, points at segment where variables are defined.
3. ES: Extra segment register, it is up to a coder to define its usage.
4. SS: Points at segment containing stack.
The segment registers work together with general purpose registers to access any memory
value.
Special purpose registers:
1. IP: Instruction Pointer- always works together with CS segment register and pints to
currently executing instruction.
2. Flag register: Determines the current state of microprocessor.
EXPERIMENT-1

Aim: To assign specific values to different segments.


Software required: Microprocessor Emulator 8086 (emu8086) with Integrated Assembler
Version 4.08
Program:
data segment
ends
stack segment
ends
code segment
start:
; set segment registers:
MOV ax, 1234h
MOV ds, ax
MOV es, ax
MOV bx, 2345h
MOV ss, bx
ENDS
end start
Output:

Result: Program executed successfully.


EXPERIMENT-2

Aim: To differentiate between hexadecimal input and binary input.


Software required: Microprocessor Emulator 8086 (emu8086) with Integrated Assembler
Version 4.08
Program:
data segment
; add your data here!
pkey db "press any key...$"
ends
stack segment
DW 128 dup(0)
ends
code segment
start:
; set segment registers:
; add your code here
MOV ax, 0011h
MOV bx, 0011b
ends
end start
Output:

Result: Program executed successfully


EXPERIMENT-3

Aim: To differentiate between formats of hexadecimal number beginning with alphabet and
number.
Software required: Microprocessor Emulator 8086 (emu8086) with Integrated Assembler
Version 4.08
Program:
data segment
ends
stack segment
ends
code segment
start:
; set segment registers:
MOV ax, 0FFFFh
MOV bx, 1234h
ENDS
end start
Output:

Result: Program executed successfully.


EXPERIMENT-4

Aim: To demonstrate the use of byte pointer.


Software required: Microprocessor Emulator 8086 (emu8086) with Integrated Assembler
Version 4.08
Program:
data segment
ends
stack segment
ends
code segment
start:
; set segment registers:
MOV ax, data
MOV ds, ax
MOV es, ax
; add your code here
MOV ax, 0FFFFh
MOV bx, 2h
ADD ax, bx
MOV [1234h], ax
ENDS
end start
Output:

Result: Program executed successfully.


EXPERIMENT-5

Aim: To demonstrate the use of ADD, ADC instruction.


Software required: Microprocessor Emulator 8086 (emu8086) with Integrated Assembler
Version 4.08
Program:
data segment
ends
stack segment
ends
code segment
start:
STC
MOV ax,1291h
MOV bx,3491h
ADD ax,bx
STC
MOV cx,1291h
MOV dx,3491h
ADC dx,cx
ENDS
end start
Output:

Result: Program executed successfully.


EXPERIMENT-6

Aim: To demonstrate 16-bit addition by using 16-bit registers for each immediate value
an store it in user defined address.
Software required: Microprocessor Emulator 8086 (emu8086) with Integrated Assembler
Version 4.08
Program:
code segment:
start:
MOV ax,0FFFFh
MOV bx,2h
MOV ax,bx
MOV [1234h],ax
ENDS
end start
Output:

Result: Program executed successfully.


EXPERIMENT-7

Aim: To demonstrate addition of two 16-bit numbers using the concept of four 8 bits registers.
Software required: Microprocessor Emulator 8086 (emu8086) with Integrated Assembler
Version 4.08
Program:
data segment
ends
stack segment
ends
code segment
start:
MOV al, 0Efh
MOV ah, 0ffh
MOV bl,2h
MOV bh,0h
ADD bl, al
ADD bh, ah
ENDS
end start
Output:

Result: Program executed successfully.


EXPERIMENT-8

Aim: To demonstrate use of ROL and ROR with single time rotation.
Software required: Microprocessor Emulator 8086 (emu8086) with Integrated Assembler
Version 4.08
Program:
data segment
ends
stack segment
ends
code segment
start:
MOV ax, 5555h
ROL ax,1h
MOV bx,ax
ROR bx,1h
ENDS
end start
Output:

Result: Program executed successfully.


EXPERIMENT-9

Aim: To demonstrate use of ROL and ROR with multiple times rotation using CL register.
Software required: Microprocessor Emulator 8086 (emu8086) with Integrated Assembler
Version 4.08
Program:
data segment
ends
stack segment
ends
code segment
start:
MOV ax, 1111h
MOV cl, 3h
ROL ax, CL
MOV bx, ax
ROR bx, CL
ENDS
end start
Output:

Result: Program executed successfully.


EXPERIMENT-10

Aim: To demonstrate use of RCL and RCR instructions with single rotation.
Software required: Microprocessor Emulator 8086 (emu8086) with Integrated Assembler
Version 4.08
Program:
data segment
ends
stack segment
ends
code segment
start:
MOV ax, 0DDDDh
RCL ax, 1h
MOV bx, ax
RCR bx, 1h
ENDS
end start
Output:

Result: Program executed successfully.


EXPERIMENT-11

Aim: To demonstrate use of SHL and SHR 8086 instructions.


Software required: Microprocessor Emulator 8086 (emu8086) with Integrated Assembler
Version 4.08
Program:
data segment
ends
stack segment
ends
code segment
start:
MOV ax, 2h
MOV cl, 2h
SHL ax, cl
MOV bx, ax
SHR bx, 1h
ENDS
end start
Output:

Result: Program executed successfully.


EXPERIMENT-12

Aim: To demonstrate use of SAL and SAR 8086 instructions.


Software required: Microprocessor Emulator 8086 (emu8086) with Integrated Assembler
Version 4.08
Program:
data segment
ends
stack segment
ends
code segment
start:
MOV ax, 0fffeh
SAR ax, 1h
MOV bx,ax
SAL bx,1h
ENDS
end start
Output:

Result: Program executed successfully.


EXPERIMENT-13

Aim: To demonstrate PUSH and POP.


Software required: Microprocessor Emulator 8086 (emu8086) with Integrated Assembler
Version 4.08
Program:
include 'emu8086.inc'
data segment
num dw 222h,111h,444h,555h
ends
code segment
start:
MOV ax,8712h
MOV ss,ax
MOV ax,02380h
MOV sp,0B0C1h
PUSH ax
POP ax
ENDS
end start
Output:

Result: Program executed successfully.


EXPERIMENT-14

Aim: To find an offset and segment address.


Software required: Microprocessor Emulator 8086 (emu8086) with Integrated Assembler
Version 4.08
Program:
data segment
a1 db 12h
ends
stack segment
ends
code segment
start:
MOV ax, data
MOV ds, ax
LEA dx, a1
MOV bx, offset a1
MOV bx, seg a1
ENDS
end start
Output:

Result: Program executed successfully.

Aim: Print Hello World.


EXPERIMENT-
15
Software required: Microprocessor Emulator 8086 (emu8086) with Integrated Assembler
Version 4.08
Program:
data segment
a1 db 'H','e','l','l','o',' ','W','o','r','l','d'
ends
code segment
start:
MOV ax, data
MOV ds, ax
MOV es, ax
LEA si,a1
MOV cx,11h
MOV ah,0Eh
m:LODSB
int 10h
LOOP m
HLT
ENDS
end start
Output:

Result: Program executed successfully.


EXPERIMENT-16

Aim: Sum of elements in data segment using LODSB instruction.


Software required: Microprocessor Emulator 8086 (emu8086) with Integrated Assembler
Version 4.08
Program:
data segment
; add your data here!
a1 dw 1111h,1112h,1113h,1114h
sum dw (0)
ends
code segment
start:
; set segment registers:
MOV ax, data
MOV ds, ax
LEA si,a1
MOV cx,4h
MOV ax,0000h
m:LODSB
ADC sum,ax
LOOP m
HLT
ENDS
end start
Output:

Result: Program executed successfully.


EXPERIMENT-17

Aim: Sum of elements in data segment without LODSB instruction.


Software required: Microprocessor Emulator 8086 (emu8086) with Integrated Assembler
Version 4.08
Program:
data segment
a1 dw 01h, 02h, 03h, 04h, 05h
ends
code segment
start:
MOV ax, data
MOV ds, ax
MOV ax, 000h
MOV bx,0000h
MOV cx, 0005h
LEA si, a1
rep:
MOV bx, [si]
ADD ax, bx
INC si
INC si
DEC cx
JNZ rep
HLT
ENDS
end start
Output:

Result: Program executed successfully.


EXPERIMENT-18

Aim: To demonstrate use of STOSB instruction.


Software required: Microprocessor Emulator 8086 (emu8086) with Integrated Assembler
Version 4.08
Program:
data segment
; add your data here!
a1 db 12h,34h,56h
ends
extra segment
a2 db 3 dup(0)
ends
code segment
start:
MOV ax, data
MOV ds, ax
MOV ax,extra
MOV es,ax
LEA si,a1
LEA di,a2
MOV cx,3h
m:LODSB
STOSB
LOOP m
ENDS
end start
Output:

Result: Program executed successfully.


EXPERIMENT-19

Aim: To demonstrate MOVSB instruction.


Software required: Microprocessor Emulator 8086 (emu8086) with Integrated Assembler
Version 4.08
Program:
data segment
a1 db 12h, 34h, 56h
ends
extra segment
a2 db 3 dup(?)
ends
code segment
start:
MOV ax, data
MOV ds, ax
MOV ax, extra
MOV es, ax
LEA si, a1
LEA di, a2
MOV cx, 3h
m: MOVSB
LOOP m
HLT
ENDS
end start
Output:

Result: Program executed successfully.


EXPERIMENT-20

Aim: To move data in reverse


order.
Software required: Microprocessor Emulator 8086 (emu8086) with Integrated Assembler
Version 4.08
Program:
data segment
; add your data here!
a1 db 1,2,3,4,5
a2 db 5 dup(0)
ends
code segment
start:
; set segment registers:
MOV ax, data
MOV ds, ax
MOV es, ax
std
LEA si, a1+04
LEA di, a2
MOV cx, 5
m:
MOVSB
INC di
INC di
LOOP m
HLT
ENDS
end start
Output:

Result: Program executed successfully.


EXPERIMENT-21

Aim: To demonstrate use of CMP instruction.


Software required: Microprocessor Emulator 8086 (emu8086) with Integrated Assembler
Version 4.08
Program:
code segment
start :
MOV ax,09h
MOV bx,04h
CMP ax,bx
MOV ax,09h
MOV bx,09h
CMP ax,bx
MOV ax,08h
MOV bx,09h
CMP ax,bx
HLT
ENDS
end start
Output:

Result: Program executed successfully.


EXPERIMENT-22

Aim: To check even and odd in an array.


Software required: Microprocessor Emulator 8086 (emu8086) with Integrated Assembler
Version 4.08
Program:
data segment
; add your data here!
a1 db 12h,89h,31h,74h
ends
stack segment
dw 128 dup(0)
ends
code segment
start:
; set segment registers:
MOV ax, data
MOV ds, ax
LEA si,a1
MOV cx,04h
MOV ah,0Eh
m:LODSB
RCR al,01h
JC l1
MOV al,'E'
INT 10h
JMP exit
l1:
MOV al,'O'
INT 10h
exit:
LOOP m
HLT
ENDS
end start
Output:

Result: Program executed successfully.


EXPERIMENT-23

Aim: To demonstrate 32-bit addition and store it in user defined address.


Software required: Microprocessor Emulator 8086 (emu8086) with Integrated Assembler
Version 4.08
Program:
data segment
ends
code segment
ends
start:
; set segment registers:
MOV ax, data
MOV ds, ax
MOV es, ax
MOV ax,01234h
MOV bx,04512h
MOV cx,0ABCDh
MOV dx,0EDC8h
ADD ax,dx
es:MOV [5671h],ax
ADC bx,cx
es:MOV [5673h],bx
ENDS
end start
Output:

Result: Program executed successfully.


EXPERIMENT-24

Aim: To check number is positive or negative in an array.


Software required: Microprocessor Emulator 8086 (emu8086) with Integrated Assembler
Version 4.08
Program:
data segment
list dw 11h ,33h,89h
count dw 3
ends
include 'emu8086.inc'
code segment
start:
MOV ax,data
MOV ds,ax
MOV es,ax
LEA si,list
MOV cx,count
l1:
LODSW
ROL ax,01 ;msb
JC xx
print 'positive'
JMP exit ;like break statement
xx:
print 'negative'
exit: loop l1
HLT
ENDS
end start
Output:

Result: Program executed successfully.


EXPERIMENT-25

Aim: To store minimum digit of the array at AL register.


Software required: Microprocessor Emulator 8086 (emu8086) with Integrated Assembler
Version 4.08
Program:
data segment
; add your data here!
a1 db 24h,5h,45h,48h
ends
stack segment
dw 128 dup(0)
ends
code segment
start:
; set segment registers:
MOV ax, data
MOV ds, ax
LEA si,a1
MOV cx,3h
MOV al,[si]
m:
CMP [si+1],al
JC l1
INC si
JMP exit
l1:
MOV al,[si+1]
INC si
exit:
LOOP m
HLT
; add your code here
ENDS
end start
Output:

Result: Program executed successfully.


EXPERIMENT-26

Aim: To store maximum digit of the array at AL register.


Software required: Microprocessor Emulator 8086 (emu8086) with Integrated Assembler
Version 4.08
Program:
data segment
; add your data here!
a1 db 24h,55h,45h,48h
ends
stack segment
dw 128 dup(0)
ends
code segment
start:
; set segment registers:
MOV ax, data
MOV ds, ax
LEA si,a1
MOV cx,3h
MOV al,[si]
m:
CMP al,[si+1]
JC l1
INC si
JMP exit
l1:
MOV al,[si+1]
inc si
exit:
LOOP m
HLT
ENDS
end start
Output:

Result: Program executed successfully.


EXPERIMENT-27

Aim: To implement Bubble sort.


Software required: Microprocessor Emulator 8086 (emu8086) with Integrated Assembler
Version 4.08
Program:
data segment
; add your data here!
a1 db 65h, 45h, 87h, 76h, 56h, 31h
count db 6
ends
stack segment
dw 128 dup(0)
ends
code segment
start:
; set segment registers:
MOV ax, data
MOV ds, ax
MOV dx, count-1
l1:
MOV cx,dx
LEA si, a1
l2:
LODSB
CMP al ,[si]
JC xx
XCHG [si], al
XCHG [si-1], al
xx:
LOOP l2
DEC dx
JNZ l1
HLT
ENDS
end start
Output:

Result: Program executed successfully.

EXPERIMENT-28

Aim: To find factorial.


Software required: Microprocessor Emulator 8086 (emu8086) with Integrated Assembler
Version 4.08
Program:
; multi-segment executable file template.
DATA SEGMENT
COUNT DW 04H
A1 DB 04h
FACTORIAL DW ?
ENDS
CODE SEGMENT
START:
MOV BX, DATA
MOV DS, BX
MOV ES, BX

MOV CL, A1
MOV AX, 0001H

LEA DI, FACTORIAL

M:

MUL CL
LOOP M
STOSB
HLT
ENDS

END START
Output:

Result: Program executed successfully


EXPERIMENT-29

Aim: To find square of a number.


Software required: Microprocessor Emulator 8086 (emu8086) with Integrated Assembler
Version 4.08
Program:
DATA SEGMENT
A1 DW 2H,4H,6H,8H
A2 DD DUP(0)
ENDS
COD SEGMENT
START:
MOV AX,DATA
MOV DS,AX
MOV ES,AX
MOV CX,4
LEA SI,A1
LEA DI,A2
SQ:LODSW
MUL AX
MOV [DI],AX
INC DI
INC DI
MOV [DI],DX
INC DI
INC DI
LOOP SQ
HLT
ENDS
END START
Output:

Result: Program executed successfully


EXPERIMENT-30

Aim: To implement Fibonacci series.


Software required: Microprocessor Emulator 8086 (emu8086) with Integrated Assembler
Version 4.08
Program:
; multi-segment executable file template.
data segment
count dw 08h
fibo db ?
ends
code segment
start:
; set segment registers:
MOV dx, data
MOV ds, dx
; add your code here
MOV cx, count
SUB cx, 2h
MOV al, 00h
LEA si, fibo
MOV [si], al
INC al
INC si
MOV [si], al
m:
MOV al, [si-1]
ADD al,[si]
INC si
MOV [si], al
LOOP m
HLT
ENDS
end start
Output:

Result: Program executed successfully

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy