You are on page 1of 29

LIST OF EXPERIEMENTS FOR MPMC LAB

CYCLE 1
S.n Title of the Experiment
o
1 8-Bit Arithmetic Programs
a. Addition
b. Subtraction
c. Multiplication
d. Division
2. Programs based on Arithmetic Instructions (16 bit)
a. Addition
b. Subtraction
c. Multiplication
d. Division
3. Programs based on (16 bit)Logical Instructions
a. AND
b. OR
c. NOT
d. NAND
e NOR
f XOR
g XNOR
4. Programs on mathematical Operations
a. Square of a number
b. Cube of a number
c. Factorial of a number
5. Programs based on code conversion
a. BCD to ASCII
b. ASCII to BCD
6. Programs based on searching and sorting
a. Find largest number in a array
b. Find smallest number in a array
c. Sort the array in ascending order
d. Sort the array in descending order
7. Programs based on String Instructions
a. Create a copy of the string
8. Programs based on DOS-BIOS Interrupts
a. Print a character to the screen
b. Print a string to the screen
c. Take input from keyboard and print the character on the screen
CYCLE 2
S.no Title of the Experiment
1 Programs based on 8051 instruction set
a. All arithmetic instructions
b. All logical instructions
e. Count 1s in a Byte using assembly language
2. Programs based on Timers and Interrupts
a. Write a 8051 C program to create a square wave with 50% duty
cycle on the P1.5 bit using polling method. Use Timer 0
[SQUARE WAVE]
b. Write a Assembly language program to generate a delay of 5 ms
(i.e a pulse with width 5ms) using polling method on P2.3. Use
timer 0 mode [DELAY GENERATION]
c. Write a 8051 C program to create a square wave with 50% duty
cycle on the P1.5 bit using interrupt method. Use Timer 0
[SQUARE WAVE]
3. Programs based on counters
a. Assuming that clock pulses are fed into pin T1, write a program for
counter 1 mode 2 to count the pulses and display the state of the
TL1 count on P2,
4. Programs based on Serial Communication
a. Write a program to transfer the letter ‘A’ serially at a 4800 baud
rate using polling method
b. Write a program to transfer the letter ‘Y’ serially at a 9600 baud
rate using
Steps to run the 8086 programs in DOSBOX
 In your C drive or D drive create a new folder with your name or roll number.
 In the folder created by you, copy the 8086 assembly files like link, masm debug etc.
There will be 10 files in total.
 Now, open a text editor like notepad, write your program and save the file in your created
folder with .asm extension .

Once you have saved your files, open dos box and mount your folder.

 The code for mounting is as follows Z:> mount c c:\ foldername


 Then enter C drive Z:> C:\
 Once you have entered C drive, type masm filename.asm

 Your file will be processed and checked for errors. If there are no errors you can
proceed to the next step.
 If there are no errors, run the following code link filename.obj
 To check the result all at once (final output) you can use g command
 To view the result in the segmentd ds:0000. Must note this result or the register
output value.
 Use q command to quit the program, debug it again and this time type u
command to get unassembled code. Must note down this output completely
2. Programs based on Arithmetic Instructions (16 bit)
a. Write an assembly language program to add two 16 bit numbers

data segment
num1 dw 2040h
num2 dw 4060h
res dw ?
data ends
Assume cs:code,ds:data
code segment
start: mov ax,data
mov ds,ax
mov ax,num1
mov bx,num2
add ax,bx
mov res,ax
int 3h
code ends
end start
b. Write an assembly language program to subtract two 16 bit numbers
data segment
num1 dw 2040h
num2 dw 4060h
res dw ?
data ends
Assume cs:code,ds:data
code segment
start: mov ax,data
mov ds,ax
mov ax,num1
mov bx,num2
subb ax,bx
mov res,ax
int 3h
code ends
end start
c. Write an assembly language program to subtract two 16 bit numbers

data segment
num1 dw 2040h
num2 dw 4060h
res dw ?
data ends
Assume cs:code,ds:data
code segment
start: mov ax,data
mov ds,ax
mov ax,num1
mov bx,num2
mul bx
mov word ptr c, ax
mov word ptr c+2,dx
int 3h
code ends
end start
d. Write an assembly language program to subtract two 16 bit numbers
data segment
num1 dw 2040h
num2 dw 0040h
quotient dw ?
remainder dw ?
data ends
Assume cs:code,ds:data
code segment
start: mov ax,data
mov ds,ax
mov ax,num1
mov bx,num2
div bx
mov quotient,ax
mov remainder,dx
int 3h
code ends
end start
3. Programs based on logical Instructions (16 bit)
a. Write an assembly language program to perform AND operation
data segment
num1 dw 2040h
num2 dw 4060h
res dw ?
data ends
Assume cs:code,ds:data
code segment
start: mov ax,data
mov ds,ax
mov ax,num1
mov bx,num2
and ax,bx
mov res,ax
int 3h
code ends
end start
b. Write an assembly language program to perform OR operation
data segment
num1 dw 2040h
num2 dw 4060h
res dw ?
data ends
Assume cs:code,ds:data
code segment
start: mov ax,data
mov ds,ax
mov ax,num1
mov bx,num2
or ax, bx
mov res,ax
int 3h
code ends
end start
c. Write an assembly language program to perform XOR operation
data segment
num1 dw 2040h
num2 dw 4060h
res dw ?
data ends
Assume cs:code,ds:data
code segment
start: mov ax,data
mov ds,ax
mov ax,num1
mov bx,num2
xor ax,bx
mov res,ax
int 3h
code ends
end start
d. Write an assembly language program to perform NOT operation
data segment
num1 dw 2040h
res dw ?
data ends
Assume cs:code,ds:data
code segment
start: mov ax,data
mov ds,ax
mov ax,num1
not ax
mov res,ax
int 3h
code ends
end start
e. Write an assembly language program to perform NAND operation
data segment
num1 dw 2040h
num2 dw 4060h
res dw ?
data ends
Assume cs:code,ds:data
code segment
start: mov ax,data
mov ds,ax
mov ax,num1
mov bx,num2
and ax,bx
not ax
mov res,ax
int 3h
code ends
end start
f. Write an assembly language program to perform NOR operation
data segment
num1 dw 2040h
num2 dw 4060h
res dw ?
data ends
Assume cs:code,ds:data
code segment
start: mov ax,data
mov ds,ax
mov ax,num1
mov bx,num2
or ax,bx
not ax
mov res,ax
int 3h
code ends
end start
g. Write an assembly language program to perform XNOR operation
data segment
num1 dw 2040h
num2 dw 4060h
res dw ?
data ends
Assume cs:code,ds:data
code segment
start: mov ax,data
mov ds,ax
mov ax,num1
mov bx,num2
xor ax,bx
not ax
mov res,ax
int 3h
code ends
end start
4. Programs on mathematical Operations

a. Write an assembly language program to find square of a number


data segment
num1 dw 008H
res dw ?
data ends
Assume cs:code,ds:data
code segment
start: mov ax,data
mov ds,ax
mov ax,num1
mov bx,num1
mul bx
mov res, ax
int 3h
code ends
end start
b. Write an assembly language program to find cube of a number
data segment
num1 dw 008H
res dw ?
data ends
Assume cs:code,ds:data
code segment
start: mov ax,data
mov ds,ax
mov ax,num1
mov bx,num1
mul bx
mul bx
mov res, ax
int 3h
code ends
end start
c. Write an assembly language program to find factorial of a number

data segment
num dw 6h
res dw ?
data ends
code segment
assume cs:code,ds:data
start: mov ax,data
mov ds,ax
mov cx, num
mov ax,01h
fact: mul cx
dec cx
jnz fact
mov res,ax
int 3h
code ends
end start
5. Code Conversion
a. Write an assembly language program to convert given ASCII number to
BCD number

data segment
ascii dw 3538h
bcd db ?
data ends
code segment
assume cs :code, ds :data
start :
mov ax , data
mov ds ,ax
mov bx,ascii
and bx,0f0fh
mov cl,4
shl bh,cl
or bh,bl
mov bcd,bh
int 3h
code ends
end start
b. Write an assembly language program to convert given bcd number to
ASCII number
data segment
bcd db 25
ascii dw ?
data ends
code segment
assume cs :code, ds :data
start :
mov ax , data
mov ds ,ax
mov bl,bcd
mov bh,bcd
and bl,0fh
and bh,0f0h
mov cl,4
shr bh,cl
or bx,3030h
mov ascii,bx
int 3h
code ends
end start
6. Sorting and Searching

a. Write an ALP to find the largest number in a given array

data segment
STRING1 DB 08h,14h,05h,0Fh,09h
res db ?
data ends

code segment
assume cs:code, ds:data
start: mov ax, data
mov ds, ax
mov cx, 04h

LEA SI, STRING1


mov bl, [si+1]

up:
mov al, [SI]
cmp al, bl
jc nxt
mov bl, al
nxt:
inc si
dec cx
jnz up

mov res,bl

int 3h
code ends
end start

b. Write an ALP to find the smallest number in a given array


data segment
STRING1 DB 08h,14h,05h,0Fh,09h
res db ?
data ends
code segment
assume cs:code, ds:data
start: mov ax, data
mov ds, ax
mov cx, 04h
mov bl, [si+1]
LEA SI, STRING1
up:
mov al, [SI]
cmp al, bl
jnc nxt
mov bl, al
nxt:
inc si
dec cx
jnz up
mov res,bl
int 3h
code ends
end start
c. Write an ALP to arrange the array in ascending order
data segment
string1 db 99h,12h,56h,45h,36h
data ends

code segment
assume cs:code,ds:data
start: mov ax,data
mov ds,ax

mov ch,04h

up2: mov cl,04h


lea si,string1
up1: mov al,[si]
mov bl,[si+1]
cmp al,bl
jc down
mov dl,[si+1]
xchg [si],dl
mov [si+1],dl

down: inc si
dec cl
jnz up1
dec ch
jnz up2

int 3h
code ends
end start

d. Write an ALP to arrange the array in descending order

data segment
string1 db 99h,12h,56h,45h,36h
data ends

code segment
assume cs:code,ds:data
start: mov ax,data
mov ds,ax

mov ch,04h

up2: mov cl,04h


lea si,string1

up1: mov al,[si]


mov bl,[si+1]
cmp al,bl
jnc down
mov dl,[si+1]
xchg [si],dl
mov [si+1],dl

down: inc si
dec cl
jnz up1
dec ch
jnz up2

int 3h
code ends
end start

7. Programs based on String Instructions


a. Write an ALP to copy string from one segment to other
data segment
str1 db 09h, "admin",'$' ; str1 is the given string to be transferred
str2 db ? ; str2 is the location for the transfer
st1 db 09h, "str1:$" ; to display str1:
st2 db 09h, "str2:$" ; to display str2:
len db 0ah ; length of the string is loaded here
data ends
Assume cs:code,ds:data
code segment
start: mov ax,@data
mov ds,ax
mov es,ax
lea si,str1 ; location of str1 is loaded to si
lea di,str2 ; location of str2 is loaded to di

;to display str1:


lea dx,st1
mov ah,09h
int 21h

;to display contents of str1


lea dx,str1
mov ah,09h
int 21h

;to display str2:


lea dx,st2
mov ah,09h
int 21h

;transferring part
cld ; clear the contents of direction flag
mov ch,00h ; since cx should be 00xx
mov cl,len
rep movsb ; repeat the transfer untill cl=0

;to display the transferred contents of str1 to str2


lea dx,str2
mov ah,09h
int 21h
;program termination
mov ah,4ch
int 21h
code ends
end start

8. Programs based on DOS BIOS Interrupts


a. Write an Assembly language program to program to display the
letter ‘a‘ on the screen:
.model small
.stack 100h
.code
start:
mov dl, ‘a’ ; store ascii code of ‘a’ in dl
mov ah, 2h ; ms-dos character output function
int 21h ; displays character in dl register
mov ax, 4c00h ; return to ms-dos
int 21h
end start

b. Write a program to read a character from the keyboard and display it on


the screen:
.model small
.stack 100h
.code
start:
mov ah, 1h ; keyboard input subprogram
int 21h ; read character into al
mov dl, al
mov ah, 2h ; display subprogram
int 21h ; display character in dl
mov ax, 4c00h ; return to ms-dos
int 21h
end start

c. Write a program to display the message ‘Hello world’ followed by


Return and Line-feed :
.model small
.stack 100h
.data
message db ‘Hello World‘, 13, 10, ‘$‘
.code
start:
mov ax, @data
mov ds, ax ; copy address of message to dx
mov dx, offset message
mov ah, 9h ; string output
int 21h ; display string
mov ax, 4c00h
int 21h
end start

8051 Programming Using Keil µVision


Download the software from
https://www.keil.com/demo/eval/c51.htm
1. Start the Keil software. Go to the Project > New µvision Project then
choose a location to store your program, and give a name and Save.

2. Now in the next window select the device from different manufacturers.
We are selecting NXP, and then by expanding we are
selecting 89V51RD2 device and click ok.

3. Now go to the New in the menu and select New. It will open a new editor
to write code.

4. Go to the save option and save the program file with .c extension.

5. Write the code for 8051 Microcontroller and Save it.

6. Now from the left panel, select Source Group 1, and Add Existing Files
to Group ‘Source Group 1’. Then select the program (c file) then add and
close.

7. Now go to the Project > Build Target to build the project. If there is some
error the building will be failed, after correcting the errors it can be build.

8. Now click on the Target1 from the left panel and select Options for
Target ‘Target1’. Then set the xtal (mhz) value to 11.0592. Check mark on
the Use On Chip ROM. Then go to the output tab. In this tab
check Create Hex File, and click OK. Then build it again.

9. If there are no errors, then go to DEBUG > Start Stop Debug Session. A
window appears, Click on OK, it take you to debug window. Again DEBUG
> RUN

10. For step by step execution Press F11, For single step execution press F5

1. Programs based on instruction set


a. Write a assembly language program to perform all arithmetic
operations

Aim: To perform arithmetic operations

Software used : Keil µVision

Program

org 00h
mov A, #08h
mov B, #05h
Add A,B
Mov R1,A
Subb A,B ; A = 0Dh and B = 05h
Mov R2, A
Inc A ; A is 08h before inc
Dec B ; B is 05h before dec
MUL AB ; Here A is 09h and B is 04h
Mov R3,A
Mov A, #95h
Mov B, #10h
DIV AB
Mov R4,A
Mov R5,B
End

RESULT :
Unassembled Code:

b. Write a ALP to perform all logical instructions

org 00h
mov A, #08h
mov B, #05h

ANL A,B
Mov R1,A
mov A, #08h
mov B, #05h

ORL A,B
Mov R2, A

mov A, #08h
mov B, #05h

XRL A,B
MOV R3,A

mov A, #03h
RL A
MOV R4,A

mov A, #03h
RL A
MOV R4,A

mov A, #03h
RLC A
MOV R5,A

mov A, #03h
RR A
MOV R6,A

mov A, #03h
RRC A
MOV R7,A
End

c. Write an ALP to Count no of 1s in a byte


ORG 0H
; SUBROUTINE TO COUNT NUMBER OF 1S IN A BYTE.
; FIRST THREE INSTRUCTIONS COMPLETE THE INITIALIZATION
PROCEDURE.
MOV A, #0FH ; GET TARGET BYTE IN THE
ACCUMULATOR
MOV R7, #08H ; COUNTER FOR 8 BITS
MOV R6, #00H ; FOR TEMPORARY RESULT
STORAGE
; ITERATION TO COUNT NUMBER OF 1S IN THE ACCUMULATOR
STARTS FROM HERE.
SHIFT1: RLC A ; SHIFT MSB IN TO THE CY FL AG
JNC NEXT1 ; THIS BIT IS NOT 1
INC R6 ; THE BIT IS 1, INCREMENT COUNT
NEXT1: DJNZ R7, SHIFT1 ; CONTINUE FOR 8 BITS
; ITERATION COMPLETE. RESULT IN R6. COPY IT TO THE
ACCUMULATOR.
MOV A, R6 ; RESULT IN THE ACCUMULATOR
END

2. TIMER and Counter PROGRAMMING


1. Write a 8051 C program to create a square wave with 50% duty cycle on the P1.5 bit using
polling method. Use Timer 0

Program

ORG 00H

MOV TMOD,#01 ; timer 0 mode 1 ( 16 bit mode)


HERE: MOV TL0,#0F2H
MOV TH0,#0FFH
CPL P1.5
ACALL DELAY
SJMP HERE
;-------------- Delay using timer 0
Delay:
SETB TR0
AGAIN: JNB TR0 ,AGAIN

CLR TR0
CLR TF0
RET
2. Write a Assembly language program to generate a delay of 5 ms (i.e a pulse with width 5ms)
using polling method on P2.3. Use timer 0 mode 1

Program
Org 00H

CLR P2.3
MOV TMOD, #01
HERE: MOV TL0, #0
MOV TH0, #0EEH
SETB P2.3
SETB TR0
AGAIN: JNB TF0, AGAIN
CLR P2.3
CLR TR0
END

3. Write a 8051 C program to create a square wave with 50% duty cycle on the P1.5 bit using
interrupt method. Use Timer 0

Program
Org 0
LJMP MAIN
ORG 0000BH ;ISR FOR TIMER 0
CPL P1.2 ;Complement P1.2
MOV TL0, #00 ;Reload timer values
Mov TH0,#0DCH
RETI ; Return from interrupt
Org 30H
;--------------Main Program for initialization
MAIN MOV TMOD, #01H ; Timer 0, Mode 1
MOV TL0,#00
MOV TH0, #0DCH
MOV IE, #82H ;Enable timer 0 interrupt
SETB TR0
HERE: SJMP HERE
END
COUNTER PROGRAMMING
4. Assuming that clock pulses are fed into pin T1, write a program for counter
1 mode 2 to count the pulses and display the state of the TL1 count on P2,

Program:
ORG 00
MOV TM0D,#01100000B ;counter 1, mode 2
MOV TH1,#0
SETB P3.5
AGAIN: SETB TR1
BACK: MOV A,TL1
MOV P2,A
JNB TF1,Back
CLR TR1
CLR TF1
SJMP AGAIN
END
3. SERIAL COMMUNICATION PROGRAMMING
Write a program to transfer the letter ‘A’ serially at a 4800 baud rate using
polling method

Program
ORG 00
MOV TMOD, #20H ;Timer 1 Mode 2
MOV TH1, #-6H ;4800 baud rate
MOV SCON,#50H ; 8 bit start stop mode
SETB TR1 ;Start the timer
AGAIN: MOV SBUF,#'A'
HERE: JNB TI, HERE
CLR TI
SJMP AGAIN
End

You might also like