Download as pdf or txt
Download as pdf or txt
You are on page 1of 29

Micro Processors and Micro Controllers

Laboratory Manual of Electronics and


Communication Engineering
Preface:

This Laboratory manual is for supporting students to learn practicals aspects of


Micro Processors and Micro Controllers Using Visual Studio software

The manual is prepared with intention to cover the Laboratary Experiments according to
Jntuh Syllabus with step by step procedure.The following are the list of Experiments included in
ths Manual

I. Programs for 16 bit arithmetic operations for 8086 (using Various Addressing Modes).
II. Program for sorting an array for 8086.
III. Program for searching for a number or character in a string for 8086.
IV. Program for string manipulations for 8086.
V. Program for digital clock design using 8086.
MPMC LAB MANUAL

CONTENTS

I. How to write programs in Visual Studio 01


II. Programs for 16 bit arithmetic operations for 8086 (using Various Addressing
Modes) 08
III. Program for sorting an array for 8086. 16
IV. Program for searching for a number or character in a string for 8086. 18
V. Program for string manipulations for 8086. 19
VI. Program for digital clock design using 8086. 23
MPMC LAB MANUAL

Implementation of Programs
MPMC LAB MANUAL

How to write Assembly language programs in Visual Studio


1. Go to Start All Programs Visual Studio 2015
2. Go to File menu New Project

3. In the New Project window, select Win32 under Visual C++ in the left panel, and
select Win32 Console Application in the middle panel. Give your project a suitable
name (near the bottom of the window):

1
MPMC LAB MANUAL

4. Click the OK button to continue. The Win32 Application Wizard window will appear.
Select Application Settings, and then select the Empty project check box.

5. Click the Finish button to save the new project.


6. Open the Solution Explorer window and add an assembly language source file to your
project. Here's how: Right-click the project name in the Visual Studio window, select
Add, select Existing Item. In the Add Existing Item dialog window, browse to the
location of the file you want to add, select the filename, and click the Add button to
close the dialog window.

Note: You may delete the Header Files, Resource Files, and Source Files folders if you
wish. They are not necessary.

 If You want create a assembly language source file then Right –click on the
project Name in the visual studio windows, select Add, select New Item
 In the Add New window, select Code under Visual C++ in the left panel,
and select C++ File (.cpp) in the middle panel. Give your file name with .asm
extension and then click on Add

2
MPMC LAB MANUAL

7. Next, right click your project name, select Build Dependencies, then select Build
Customizations from the popup menu. When you see the above window, select the
check box next to masm and click the OK button to close the dialog.

8. Right-click the project name in the Solution Explorer window and select Properties from
the popup menu. Expand the entry under Configuration Properties. Then expand the
entry named Microsoft Macro Assembler. This is what you should see:

9. Modify the Include Paths option so it equals "C:\Masm". This tells the assembler where
to find files having a filename extension of ".inc". Here is a sample:

3
MPMC LAB MANUAL

10. Next, select the Listing File entry, also in the Microsoft Macro Assembler group. Modify
the Assembled Code Listing File entry (shown below) so it contains $(ProjectName).lst.
This uses a built-in variable to identify the name of the source input file, with a file
extension of .lst. So, if your program were named main.asm, the listing file would be
named main.lst:

4
MPMC LAB MANUAL

11. Find the Linker entry under Configuration Properties. Select the Input entry, and
insert masm32.lib;at the beginning of the Additional Dependencies entry. The
filenames must be separated by semicolons.

12. Select Linker under Configuration Properties, and then select General. The Additional Library
Directories entry must contain c:\Masm32 so the linker can find the masm32.lib library file:

5
MPMC LAB MANUAL

13. Select Linker under the Configuration Properties and select Debugging. Verify that
the Generate Debug Info option is equal to either true or Optimize for debugging
(/DEBUG)

14. After Select Advanced under the Linker entry. Set the Image Has Safe Exception
Handlers option to No

6
MPMC LAB MANUAL

15. Then Click the OK button to close the Property Pages window. Verify that your project
has been created correctly by building and debugging the program as you did in an
earlier tutorial.

7
MPMC LAB MANUAL

Program No 1
Programs for 32 bit arithmetic operations for 8086 (using
Various Addressing Modes)
a) Addition:
i) 16 bit addition:
AIM: - Write an assembly language program for Addition of two 32-bit numbers.
Tool Requirement: Visual Studio 2015 with Masm
Program:
Include masm32.inc
.code
main proc
mov eax,5
add eax,6
invoke ExitProcess,0
main endp
end main
OUTPUT

8
MPMC LAB MANUAL

ii) Multi byte addition

AIM: - Program to perform multi byte addition


Tool Requirement: Visual Studio 2015 with masm
Program TITLE (.asm)
INCLUDE masm32.inc
.data
str1 DB 01H,02H,03H,04H,05H
Str2 DB 01h,02h,03h,04h,05h
str3 DB 4 DUP(0)
.code
main PROC
MOV eAX, 0000h
LEA eSI,str1
LEA eDI,str3
LEA eBX,str2
MOV CL, 05
UP : MOV AL, [eSI]
ADD AL,[eBX]
MOV [eDI], AL
INC eSI
INC eBX
INC eDI
DEC CL
JNZ UP
exit
main ENDP
END main
OUTPUT

9
MPMC LAB MANUAL

b) Subtraction:
i) 16 bit Subtraction:
AIM: - Write an assembly language program for Subtraction of two 16-bit numbers.
Tool Requirement: Visual Studio 2015 with masm
Program TITLE (.asm)
INCLUDE masm32.inc
.data
.code
main PROC
MOV eAX, 6h
MOV eBX, 3h
SUB eAX, eBX
exit
main ENDP
END main
OUTPUT

10
MPMC LAB MANUAL

ii) Multi byte subtraction


AIM: - Program to perform multi byte subtraction
Tool Requirement: Visual Studio 2015 with masm
Program
TITLE (.asm)
INCLUDE masm32.inc
.data
str1 DB 02H,03H,04H,05H,06H
Str2 DB 01h,02h,03h,04h,05h
str3 DB 4 DUP(0)

.code
main PROC
MOV eAX, 0000h
LEA eSI,str1
LEA eDI,str3
LEA eBX,str2
MOV CL, 05
UP : MOV AL, [eSI]
SUB AL, [eBX]
MOV [eDI], AL
INC eSI
INC eBX
INC eDI
DEC CL
JNZ UP
exit
main ENDP
END main

OUTPUT

11
MPMC LAB MANUAL

c) Multiplication:
i) 32 bit multiplication and imultiplication:
AIM: - Wite an assembly language program for multiplication of two 16-bit numbers.
Tool Requirement: Visual Studio 2015 with masm
Program ; This program shows examples of both signed and unsigned multiplication.
INCLUDE masm32.inc
.code
main PROC
mov ax,255
mov bx,255
imul bx
;Example 1
mov al,5h
mov bl,10h
mul bl ; CF = 0
;Example 2
.data
val1 WORD 2000h
val2 WORD 0100h
.code
mov ax,val1
mul val2 ; CF = 1
;Example 3:
mov eax,12345h
mov ebx,1000h
mul ebx ; CF = 1
; IMUL Examples:
; Example 4:
.data
val3 SDWORD ?
.code
mov eax,+4823424
mov ebx,-423
imul ebx ; EDX=FFFFFFFFh, EAX=86635D80h
mov val3,eax
exit
main ENDP
END main

12
MPMC LAB MANUAL

OUTPUT

13
MPMC LAB MANUAL

d) iDivision:
32 bit division:
AIM: - Write an assembly language program for multiplication of two 32-bit numbers.

Tool Requirement: Visual Studio 2015 with masm

Program ; This program shows examples of various IDIV formats.


INCLUDE masm32.inc
.code
main PROC
; Example 1
.data
byteVal SBYTE -48
.code
mov al,byteVal ; dividend
cbw ; extend AL into AH
mov bl,+5 ; divisor
idiv bl ; AL = -9, AH = -3
call DumpRegs

; Example 2
.data
wordVal SWORD -5000
.code
mov ax,wordVal ; dividend, low
cwd ; extend AX into DX
mov bx,+256 ; divisor
idiv bx ; quotient AX = -19, rem DX = -136
call DumpRegs

; Example 3

.data
dwordVal SDWORD +50000
.code
mov eax,dwordVal ; dividend, low
cdq ; extend EAX into EDX
mov ebx,-256 ; divisor
idiv ebx ; quotient EAX = -195, rem EDX = +80
call DumpRegs
exit
main ENDP
END main

14
MPMC LAB MANUAL

OUTPUT

15
MPMC LAB MANUAL

Program No 2:
Program for sorting an array for 8086.

i) ASCENDING ORDER
AIM:-Program to sort the given numbers in ascending order
Tool Requirement: Visual Studio 2015 with masm
Program TITLE (.asm)
; This program
; Last update:
INCLUDE masm32.inc
.data
STRING1 DB 99H,12H,56H,45H,36H
.code
main PROC
MOV AX, 00H
MOV CH, 04H
DEC CH
UP1: MOV CL, 04h
LEA eSI,STRING1
;MOV eSI, 2000
UP: MOV AL, [eSI]
INC SI
CMP AL, [eSI]
JC DOWN
XCHG AL, [eSI]
DEC SI
MOV [eSI], AL
INC eSI
DOWN: DEC CL
JNZ UP
DEC CH
JNZ UP1
exit
main ENDP
END main
OUTPUT

16
MPMC LAB MANUAL

ii) DESCENDING ORDER


AIM:-Program to sort the given numbers in descending order
Tool Requirement: Visual Studio 2015 with masm
Program
INCLUDE masm32.inc
.data
STRING1 DB 99H,12H,56H,45H,36H
.code
main PROC
MOV AX, 0000H
MOV CH, 0004H
DEC CH
UP1: MOV CL, 0004h
LEA eSI,STRING1
UP: MOV AL, [eSI]
INC eSI
CMP AL, [eSI]
JNC DOWN
XCHG AL, [eSI]
DEC eSI
MOV [eSI], AL
INC eSI
DOWN: DEC CL
JNZ UP
DEC CH
JNZ UP1
exit
main ENDP
END main
OUTPUT

17
MPMC LAB MANUAL

Program No: 3
Program for searching for a number or character in a string for 8086.

AIM: Write an alp program for to search a number or character from a string
Tool Requirement: Visual Studio 2015 with masm
Program TITLE (.asm)
INCLUDE masm32.inc
MsgBox PROTO
.data
STRING1 DB 11H,22H,33H,44H,55H
MSG1 BYTE "FOUND",0
MSG2 BYTE "NOT FOUND",0
SE DB 02H
.code
main PROC
MOV AL, SE
LEA eSI, STRING1
MOV CX, 04H
UP: MOV BL,[eSI]
CMP AL, BL
JZ FO
INC eSI
DEC CX
JNZ UP
mov edx,OFFSET MSG2
call WriteString
JMP END1

FO: mov edx,OFFSET MSG1


call WriteString
END1: call DumpRegs
exit
main ENDP
END main
OUTPUT

18
MPMC LAB MANUAL

Program NO.4
Program for string manipulations for 8086.

1) Moving Block Of Data From One Memory Location To Another Memory Location
AIM: To write an alp for transfer block of data from one memory location to another
memory location.
Tool Requirement: Visual Studio 2015 with masm
Program
TITLE (.asm)

INCLUDE masm32.inc
.data
STRING1 DB 01H,02H,03H,04H,05H
STRING2 DB 4 DUP(0)
.code
main PROC
LEA eSI,STRING1
LEA eDI,STRING2
MOV CX,05H
CLD
REP MOVSB
exit
main ENDP
END main

OUTPUT

19
MPMC LAB MANUAL

2) Reverse of a data:
AIM: To write a alp for reverse of a given string
Tool Requirement: Visual Studio 2015 with masm
Program
TITLE (.asm)
INCLUDE masm32.inc
.data
STRING1 DB 01H,02H,03H,04H,05H
STRING2 DB 4 DUP(0)
.code
main PROC
LEA eSI,STRING1
LEA eDI,STRING2
MOV CX, 0008
ADD eSI, 07
UP: MOV AL, [eSI]
MOV [eDI], AL
DEC eSI
INC eDI
DEC CX
JNZ UP
exit
main ENDP
END main
OUTPUT

20
MPMC LAB MANUAL

3) INSERT A BYTE IN A GIVEN STRING


AIM: Write an alp for insert a new byte in a given string.
Tool Requirement: Visual Studio 2015 with masm
Program
TITLE (.asm)
INCLUDE masm32.inc
.data
STRING1 DB 01H,02H,03H,04H,05H
STRING2 DB 4 DUP(0)
STRING3 DB 01h
.code
main PROC
LEA eSI,STRING1
LEA eDI,STRING2
LEA eBX,STRING3
MOV CX, 0004
CLD
L1: MOV eAx, [eSI]
CMP eax, [eBX]
JZ L2
MOVSB
L2: MOVSB
INC eBx
MOV eax, [eBX]
MOV [eDI], eax
DEC CX
;INC eDI
REP MOVSB
L3: exit
main ENDP
END main
OUTPUT

21
MPMC LAB MANUAL

4) DELETE A BYTE IN A GIVEN STRING


AIM: To write a alp for delete a byte in a given string
Tool Requirement: Visual Studio 2015 with masm
Program TITLE (.asm)
INCLUDE masm32.inc
.data
STRING1 DB 01H,02H,03H,04H,05H
STRING2 DB 04 DUP(0)
;STRING3 DB 01H
.code
main PROC
LEA eSI,STRING1
LEA eDI,STRING2
mov ebx , 01h
MOV CX, 0006
CLD
L1: MOV Eax, [eSI]
CMP al, bl
Jz l2
JMP L3
L2: INC eSi
DEC CX
jz l4
jmp l1
REP MOVSB
L3: MOVSB
mov [edi],eax
loop L1
l4: ;call DumpRegs
;call DumpMem
exit
main ENDP
END main

OUTPUT

22
MPMC LAB MANUAL

Program NO.5
Program for digital clock design using 8086.

AIM: To write an ALP program for displaying the system clock


Tool Requirement: Visual Studio 2015 with masm
Program
; Display the Date and Time (DateTime.asm)
; This Real-mode program displays the date and time.
Include masm32.inc
Write PROTO char:BYTE
.data
str1 BYTE "Date: ",0
str2 BYTE ", Time: ",0

.code
main PROC
mov ax,@data
mov ds,ax

; Display the date:


mov dx,OFFSET str1
call WriteString
mov ah,2Ah ; get system date
int 21h
movzx eax,dh ; month
call WriteDec
INVOKE Write,'-'
movzx eax,dl ; day
call WriteDec
INVOKE Write,'-'
movzx eax,cx ; year
call WriteDec

; Display the time:


mov dx,OFFSET str2
call WriteString
mov ah,2Ch ; get system time
int 21h
movzx eax,ch ; hours
call WritePaddedDec
INVOKE Write,':'
movzx eax,cl ; minutes
call WritePaddedDec
INVOKE Write,':'

23
MPMC LAB MANUAL

movzx eax,dh ; seconds


call WritePaddedDec
call Crlf
exit
main ENDP
;---------------------------------------------
Write PROC char:BYTE
; Display a single character.
;---------------------------------------------
push ax
push dx mov
ah,2 mov
dl,char int
21h
pop dx
pop ax
ret
Write ENDP
;---------------------------------------------
WritePaddedDec PROC
; Display unsigned integer in EAX, padding
; to two digit positions with a leading zero.
;---------------------------------------------
.IF ax < 10
push ax
push dx
mov ah,2
mov dl,'0'
int 21h
pop dx
pop ax
.ENDIF
call WriteDec
ret
WritePaddedDec ENDP
END main
OUTPUT

24
MPMC LAB MANUAL

25

You might also like