Вы находитесь на странице: 1из 47

SV COLLEGE OF ENGINEERING

DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING


MICROPROCESSOR & MICROCONTROLLER LABMANUAL

MICROPROCESSOR & MICROCONTROLLER


I. Microprocessor 8086:
1. Introduction to MASM/TASM.
2. Arithmetic operation Multi byte Addition and Subtraction, Multiplication and Division Signed
and unsigned Arithmetic operation, ASCII arithmetic operation.
3. Logic operations Shift and rotate Converting packed BCD to unpacked BCD, BCD to ASCII
conversion.
4. By using string operation and Instruction prefix: Move Block, Reverse string, Sorting, Inserting,
Deleting, Length of the string, String comparison.
5. DOS/BIOS programming: Reading keyboard (Buffered with and without echo) Display
characters, Strings.
II. Interfacing:
1. 8259 Interrupt Controller: Generate an interrupt using 8259 timer.
2. 8279 Keyboard Display: Write a small program to display a string of characters.
3. 8255 PPI: Write ALP to generate sinusoidal wave using PPI.
4. 8251 USART: Write a program in ALP to establish Communication between two processors.
III. Microcontroller 8051
1. Reading and Writing on a parallel port.
2. Timer in different modes.
3. Serial communication implementation.
Equipment required for Laboratories:
1. 8086 P Kits
2. 8051 Micro Controller kits
3. Interfaces/Peripheral subsystems
i.8259 PIC
ii.8279-KB/ Display
iii.8255 PPI
iv.8251 USART
4. ADC Interface
5. DAC Interface
6. Traffic Controller Interface
7. Elevator Interface

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

INTRODUCTION TO TASM/MASM

EXP.NO:1

Assembly language program can run in three models:


1. Standard lone mode (Using SDK 86 H/W Kit)
2. Assembler mode (Using PC loaded with assembler)
3. Serial mode (Using SDK 86 kit and PC)
STANDALONE MODE:
In this mode 8086 microprocessor hardware kit is used.ALP is entered directly into the
memory of H/W kit, if it has an board assembler otherwise enter the corresponding hex code of ALP
and by following suitable SDK 86 kit commands.
ASSEMBLER MODE:
In this mode user can run ALP using PC loaded with editor, assembler, linker and
debugger programs.
SERIAL MODE:
In this mode ALP is entered and assembled using PC, after assembling a hex file is
generated this file is sent to the SDK 86 H/W kit connected to the serial com port of PC using RS
232C. And this hex file will run on the kit by using SDK 86 kit commands.
When user wants to run in ALP in assembler mode the following programs are
required to make users PC as microprocessor kit.
1.
2.
3.
4.

Editor
Assembler
Linker
Debugger

EDITOR:
An editor is a program, which allows you to create a file containing the assembly
language statements for your program. As you type in your program the editor stores the ASCII
codes for the letters and numbers in successive RAM locations. When you have typed in all of
your programs you then save the file on a floppy of hard disk. This file is called source file. The
next step is to process the source file with an assembler. In the MASM/TASM assembler you
should give your source file name the extension .ASM

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

ASSEMBLER:
An assembler program is used to translate the assembly language mnemonics for
instructions to the corresponding binary codes. When you run the assembler it reads the source
file of your program the disk where you saved it after editing on the first pass through the source
program the assembler determines the displacement of named data items the offset of labels and
this information in a symbol table. On the second pass through the source program the assembler
produces the binary code for each instruction and inserts the offset etc that is calculated during
the first pass. The assembler generates two files on floppy or hard disk. The first file called the
object file is given the extension. OBJ. The object file contains the binary codes for the
instructions and information about the addresses of the instructions. The second file generated by
the assembler is called assembler list file. The list file contains your assembly language
statements the binary codes for each instructions and the offset for each instruction. In
MASM/TASM assembler MASM source file name ASM is used to assemble the file. Edit source
file name LST is used to view the list file which is generated, when you assemble the file.
LINKER:
A linker is a program used to join several object files into one large object file and
convert to an exe file. The linker produces a link file, which contains the binary codes for all the
combined modules. The linker however doesnt assign absolute addresses to the program, it
assigns is said to be re-locatable because it can be put anywhere in memory to be run. In
TASM/MASM LINK source filename is used to link the file.
DEBUGGER:
A debugger is a program which allows you to load your object code program into
system memory, execute the program and troubleshoot are debug it the debugger allows you to
look at the contents of registers and memory locations after your program runs. It allows you to
change the contents of register and memory locations after your program runs. It allows you to
change the contents of register and memory locations and return the program. A debugger also
allows you to set a break point at any point in the program. If you inset a breakpoint the
debugger will run the program up to the instruction where the breakpoint is set and stop

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

execution. You can then examine register and memory contents to see whether the results are
correct at that point. In MASM, MD filename is used to debug the file.
PROCEDURE TO USE TASM:
Copy the TASM software into any one of the drives(C,D,E, or F).
Change the operating mode to DOS mode by following steps.
------> Click on start
------> Click on run
-------> Type CMD (and press enter key)
The following screen will be displayed
C: / Documents and settings/svew>-Chang directry to tasm using CD TASM
Create a source file using the following syntax: C:/TASM>EDIT
A blank screen will display now type your ALP as shown below.
Eg:-Write a program for the addition of two 8 bit numbers.
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
N1 DB 00H
N2 DB 00H
RES DB 00H
DATA ENDS
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
MOV AL, N1
MOV BL, N2
ADD AL, BL
MOV RES, AL
INT 3H
CODE ENDS
END START
After typing the program save with a file name of your choice with an extension.asm
And quit from editor this file is called as source file.
To generate an object file (filename.obj) and list file (filename.lst)
Syntax C:/TASM>tasm filename.asm (object file is generated)
C:/TASM>tasm/l filename.asm
If there are no errors in your program, this will create an object (binary) file named add.obj.other
wise, TASM will display an error message which indicates the line numbers where errors appear
together with descriptions of the errors.
4

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

To generate an exe file (filename.exe).


Syntax C:/TASM>tlink filename (exe file is generated)
To load exe file using debugger
Syntax C:/TASM>td filename
Run exe file by pressing F9 or F8 functional keys. We will get,

Press the OK button.


RESULT: Hence we studied the introduction to TASM/MASM.

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

EXP.NO-2. Arithmetic operation Multi byte Addition and Subtraction,


Multiplication and Division Signed and unsigned Arithmetic operation, ASCII
arithmetic operation.
AIM: To write an ALP to perform arithmetical, multi byte, ASCII operations using TASM
Assembler.
APPARATUS:
1. Tasm assembler
2. PC
Program No: 2(a)
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
NUM1 DB 00H
NUM2 DB 00H
RES
DB 00H
DATA ENDS
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
MOV AL, NUM1
MOV BL, NUM2
ADD AL, BL
MOV RES, AL
INT 3H
CODE ENDS
END START
Program No: 2(b)
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
NUM1 DB 00H
NUM2 DB 00H
RES
DB 00H
DATA ENDS
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
MOV AL, NUM1
MOV BL, NUM2
SUB AL, BL
MOV RES, AL
INT 3H
CODE ENDS
END START

8-Bit Addition

Input:

0000: 08h
0001: 02h
Output: 0002: 0Ah

8-Bit Subtraction

Input:

0000: 08h
0001: 02h
Output: 0002: 06h

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

Program No: 2(c)

8-Bit multiplication

ASSUME CS: CODE, DS: DATA


DATA SEGMENT
NUM1 DB 00H
NUM2 DB 00H
RES1
DB 00H
RES2
DB 00H
DATA ENDS
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
MOV AL, NUM1
MOV BL, NUM2
MUL BL
MOV RES1, AL
MOV RES2, AH
INT 3H
CODE ENDS
END START
Program No: 2(d)
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
NUM1 DB 00H
NUM2 DB 00H
RES
DB 00H
DATA ENDS
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
MOV AL, NUM1
MOV BL, NUM2
DIV BL
MOV RES, AL
INT 3H
CODE ENDS
END START

Input: 0000: 04h


0001: 02h
Output: 0002: 08h

8-Bit Division

Input:

0000:08h
0001:02h
Output: 0002:04h

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

Program No: 2(e)

16-Bit Addition

ASSUME CS: CODE, DS: DATA


DATA SEGMENT
NUM1 DW 00H
NUM2 DW 00H
RES1
DW 00H
RES2
DW 00H
DATA ENDS
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
MOV AX, NUM1
MOV BX, NUM2
MOV CL, 00H
ADD AX, BX
JNC L1
INC CL
L1: MOV RES1, AX
MOV RES2, CL
INT 3H
CODE ENDS
END START
Program No: 2(f)
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
NUM1 DW 00H
NUM2 DW 00H
RES
DW 00H
DATA ENDS
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
MOV AX, NUM1
MOV BX, NUM2
SUB AX, BX
MOV RES, AX
INT 3H

Input: 0000:08h
0002:02h
Output: 0004:04h

16-Bit Subtraction

Input:

0000:08h
0002:02h
8

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

CODE ENDS
END START

Program No: 2(g)


ASSUME CS: CODE, DS: DATA
DATA SEGMENT
NUM1 DW 00H
NUM2 DW 00H
RES1
DW 00H
RES2
DW 00H
DATA ENDS
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
MOV AX, NUM1
MOV BX, NUM2
MUL BX
MOV RES1, AX
MOV RES2, DX
INT 3H
CODE ENDS
END START
Program No: 2(h)

Output: 0004:04h

16-Bit Multiplication

Input:

0000:08h
0002:02h

Output: 0004:04h

16-Bit Division

ASSUME CS: CODE, DS: DATA


EDATA SEGMENT
NUM1 DW 00H
NUM2 DW 00H
RES1
DW 00H
RES2
DW 00H
DATA ENDS
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
MOV AX, NUM1
9

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

MOV BX, NUM2


DIV BX
MOV RES1, AX
MOV RES2, DX
INT 3H
CODE ENDS
END START

Program No: 2(i)

Input:

0000:08h
0002:02h

Output: 0004:04h

Multi byte Addition

Assume cs: code, ds: data


Data segment
Ip1 dd 12233449h
Ip2 dd 56677889h
Res dd 00000000h
Data ends
Code segment
Start: mov ax, data
mov ds,ax
mov si,offset ip1
mov di,offset ip2
mov bx,offset res
mov cx,03
sub ax,ax
mov al,[si]
mov dl,[di]
add al,dl
mov [bx],al
10

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

back:inc si
inc di
inc bx
mov al,[si]
mov dl,[di]
adc al,dl
mov [bx],al
loop back
nop
int 03h
code ends
end start
******************
INPUT:
IP1: 11223344H
IP2: 55667788H
OUTPUT:
RES: 6688AACCH
Program No: 2(j)

Multi byte Subtraction

Assume cs:code,ds:data
data segment
ip1 dd 55667788h
ip2 dd 11223344h
res dd 00000000h
data ends
code segment
start: mov ax,data
mov ds,ax
mov si,offset ip1
11

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

mov di,offset ip2


mov bx,offset res
mov cx,03
sub ax,ax
mov al,[si]
mov dl,[di]
sub al,dl
mov [bx],al
back:inc si
inc di
inc bx
mov al,[si]
mov dl,[di]
sbb al,dl
mov [bx],al
loop back
nop
int 03h
code ends
end start

******************
INPUT:
IP1: 55667788H
IP2: 11223344H
OUTPUT:
RES: 44444444H

ASCII ARTHMETICAL OPERATIONS


Program No: 2(k)

ASCII Addition

Assume cs: code, ds: data


data segment
asc1 db 09H
asc2 db 06H
res dw 00h
data ends
12

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

code segment
start: mov ax,data
mov ds,ax
xor ax,ax
mov al,asc1
mov bl,asc2
add al,bl
aaa
or ax,3030h
mov res,ax
int 3H
code ends
end start
****************
INPUT: ASC1: 09H
ASC2: 06H
OUTPUT:
RES: 3135H

Program No: 2(l)

ASCII Subtraction

Assume cs:code,ds:data
data segment
asc1 db 09H
asc2 db 06H
res dw 00h
data ends
code segment
13

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

start: mov ax,data


mov ds,ax
xor ax,ax
mov al,asc1
mov bl,asc2
sub al,bl
aas
or ax,3030h
mov res,ax
int 3
code ends
end start
****************
INPUT: ASC1: 09H
ASC2: 06H
OUTPUT:
RES: 3033H

Program No: 2(m)

ASCII Multiplication

Assume cs:code,ds:data
data segment
asc1 db 06H
asc2 db 02H
res dw 00h
data ends
code segment
start: mov ax,data
14

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

mov ds,ax
xor ax,ax
mov al,asc1
mov bl,asc2
mul bl
aam
or ax,3030h
mov res,ax
int 3H
code ends
end start
****************
INPUT: ASC1: 06H
ASC2: 02H
OUTPUT:
RES: 3132H

Program No: 2 (n)

ASCII Divisions

Assume cs: code, ds: data


Data segment
asc1 db 09H
asc2 db 03H
res dw 00h
Data ends
code segment
start: mov ax,data
15

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

mov ds,ax
xor ax,ax
mov al,asc1
mov bl,asc2
aad
div bl
or ax,3030h
mov res,ax
int 3H
code ends
end start

****************
INPUT: ASC1: 09H
ASC2: 03H
OUTPUT:
RES: 3033H
RESULT: Hence we obtained the arithmetical operations, multi byte operations, ASCII operations.

Logic Operations - Shift and Rotate Converting packed BCD


to unpacked BCD, BCD to ASCII conversion.
EXP.NO: 3

AIM: To write an ALP to perform arithmetical, multi byte, ASCII operations using TASM
Assembler.
APPARATUS:
1. Tasm assembler
2. PC
Program No: 3(a)

Logical AND operation


16

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

Assume cs: code, ds: data


Data segment
op1 dw 00h
op2 dw 00h
res dw 00h
Data ends
Code segment
start: mov ax,data
mov ds,ax
mov ax,op1
mov bx,op2
and ax,bx
mov res,ax
int 3h
code ends
end start

*************
INPUT: OP1:01h
OP2:01h
OUTPUT:
RES:01h

Program No: 3(b)

Logical OR operation

assume cs:code,ds:data
data segment
op1 dw 00h
op2 dw 00h
res dw 00h
data ends
code segment
start: mov ax,data
mov ds,ax
17

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

mov ax,op1
mov bx,op2
or ax,bx
mov res,ax
int 3h
code ends
end start
*************
INPUT: OP1:01h
OP2:00h
OUTPUT:
RES:01h
Program No: 3(c)

Logical NOT operation

Assume cs:code,ds:data
data segment
op1 dw 00h
res dw 00h
data ends
code segment
start: mov ax,data
mov ds,ax
mov ax,op1
not ax
mov res,ax
int 3h
code ends
end start
*************
INPUT: OP1:04h

18

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

OUTPUT:
RES: FBh
Program No: 3(d)

Logical XOR operation

Assume cs:code,ds:data
data segment
op1 dw 00h
op2 dw 00h
res dw 00h
data ends
code segment
start: mov ax,data
mov ds,ax
mov ax,op1
mov bx,op2
xor ax,bx
mov res,ax
int 3h
code ends
end start
*************
INPUT: OP1:01h
OP2:00h
OUTPUT:
RES:01h
Program No: 3(e)

RCL

Assume cs:code,ds:data
data segment
op1 db 0h
cnt db 00h
res db 00h
data ends
code segment
start: mov ax,data
mov ds,ax
19

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

sub ax,ax
mov al,op1
mov cl,cnt
rcl al,cl
mov res,al
int 3h
code ends
end start
*************
INPUT: OP1:25h
cnt:03h
OUTPUT:
RES:28h
Program No: 3(f)

RCR

Assume cs:code,ds:data
data segment
op1 db 0h
cnt db 00h
res db 00h
data ends
code segment
start: mov ax,data
mov ds,ax
sub ax,ax
mov al,op1
mov cl,cnt
rcr al,cl
mov res,al
int 3h
code ends
end start
*************
20

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

INPUT: OP1:25h
cnt:03h
OUTPUT:
RES:44h
ROL

Program No: 3(g)

Assume cs:code,ds:data
data segment
op1 db 0h
cnt db 00h
res db 00h
data ends
code segment
start: mov ax,data
mov ds,ax
sub ax,ax
mov al,op1
mov cl,cnt
rol al,cl
mov res,al
int 3h
code ends
end start
*************
INPUT: OP1:25h
cnt:03h
OUTPUT:
RES:29h
Program No: 3(h)

ROR

Assume cs:code,ds:data
data segment
op1 db 0h
21

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

cnt db 00h
res db 00h
data ends
code segment
start: mov ax,data
mov ds,ax
sub ax,ax
mov al,op1
mov cl,cnt
ror al,cl
mov res,al
int 3h
code ends
end start
*************
INPUT: OP1:25h
cnt:03h
OUTPUT:
RES:A4h
Program No: 3(i)

SAR

Assume cs:code,ds:data
data segment
op1 db 0h
cnt db 00h
res db 00h
data ends
code segment
start: mov ax,data
mov ds,ax
sub ax,ax
mov al,op1
mov cl,cnt
sar al,cl
mov res,al
22

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

int 3h
code ends
end start
*************
INPUT: OP1:25h
cnt:03h
OUTPUT:
RES:04h
Program No: 3(j)

SHL

Assume cs:code,ds:data
data segment
op1 db 00h
cnt db 00h
res db 00h
data ends
code segment
start: mov ax,data
mov ds,ax
sub ax,ax
mov al,op1
mov cl,cnt
shl al,cl
mov res,al
int 3h
code ends
end start
*************
INPUT: OP1:25h
cnt:03h
OUTPUT:
RES:28h
Program No: 3(k)

SHR
23

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

Assume cs:code,ds:data
data segment
op1 db 0h
cnt db 00h
res db 00h
data ends
code segment
start: mov ax,data
mov ds,ax
sub ax,ax
mov al,op1
mov cl,cnt
shr al,cl
mov res,al
int 3h
code ends
end start
*************
INPUT: OP1:25h
cnt:03h
OUTPUT:
RES:04h
Program No: 3(l)

PACKED TO ASCII

Assume cs:code,ds:data
data segment
ip1 db 56h
res dw 00h
data ends
code segment
start:mov ax,data
mov ds,ax
xor ax,ax
mov al,ip1
24

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

mov dl,al
and al,0f0h
mov cl,4
ror al,cl
mov bh,al
and dl,0fh
mov bl,dl
add bx,3030h
mov res,bx
int 03h
code ends
end start
************
INPUT: OP1:56h
OUTPUT:
RES:3536h

Program No: 3(m)

PAC`KED TO UNPACKED

assume cs:code,ds:data
data segment
ip1 db 56h
res dw 00h
data ends
code segment
start:mov ax,data
mov ds,ax
xor ax,ax
mov al,ip1
25

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

mov dl,al
and al,0f0h
mov cl,4
ror al,cl
mov bh,al
and dl,0fh
mov bl,dl
mov res,bl
int 03h
code ends
end start
*************
INPUT: OP1:56h
OUTPUT:
RES:0506h
REAULT: Hence we obtained the logical, shift, rotate operations by using assembler.

EXP NO: 4) By Using String Operation and Instruction Prefix: Move


Block, Reverse String, Sorting, Inserting, Deleting, Length of the String,
String Comparison.
AIM: To write an ALP to perform arithmetical, multi byte, ASCII operations using TASM
Assembler.
APPARATUS:
1. Tasm assembler
2. PC
Program No: 4(a)

ASCENDING ORDER

Assume cs: code, ds: data


data segment
26

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

list db 76h,34h,23h,22h,02h,49h,15h,00h,00h
cnt db 08h
data ends
code segment
start: mov ax,data
mov ds,ax
mov cl,cnt
up: mov dl,cnt
mov si,offset list
xor ax,ax
again: mov al,[si]
cmp al,[si+1]
jl next
xchg al,[si+1]
mov [si],al
next: inc si
dec dl
jnz again
dec cl
jnz up
int 3h
code ends
end start

Input: ds: 76 34 23 22 02 49 15 00 00
Output: ds: 0000:00 00 02 15 22 23 34 49 76 08.
Program No: 4(b)

BLOCK TRANSFER

Assume cs:code,ds:data,es:extra
data segment
ipstr db 'empty vessels make much noise',24h
data ends
extra segment
opstr db 100h dup(00)
extra ends
code segment
start: mov ax,data
27

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

mov ds,ax
mov ax,extra
mov es,ax
mov si,offset ipstr
mov di,offset opstr
cld
mov cx,29
rep movsb
nop
int 03h
code ends
end start
*******************

OUTPUT: es: 0000 : empty vessels make much noise.

Program No: 4(c)

STRING LENGTH

Assume cs:code,ds:data
data segment
string1 db 'empty vessels make more noise$'
strlen equ($-string1)
org 0100h
res db 00h
cort db 'strlength found correct$'
incort db 'strlength found incorrect$'
data ends
code segment
28

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

start:mov ax,data
mov ds,ax
sub cl,cl
mov bl,strlen
mov si,offset string1
back: lodsb
inc cl
cmp al,'$'
jnz back
mov res,cl
int 3h
code ends
end start
*******************

INPUT: empty vessels make more noise


OUTPUT: depending on string

Program No: 4(d)

STRING COMPARISION

Assume cs: code, ds: data, es: data


data segment
string1 db 'empty1$'
strlen equ($-string1)
op1 db 'strings are unequal$'
op2 db 'strings are equal$'
org 100h
res db 00h
data ends
extra segment
29

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

string2 db 'empty$'
extra ends
code segment
start: mov ax,data
mov ds,ax
mov ax,extra
mov es,ax
mov si,offset string1
mov di,offset string2
cld
mov cx,strlen
repe cmpsb
jz next
mov ah,09h
mov dx,'u'
int 21h
jmp exitp
next:mov ah,09h
mov dx,'e'
int 21h
exitp:nop
mov res,dl
mov ah,4ch
int 21h
code ends
end start
*******************
Program No: 4(e)

STRING REVERSE

Assume cs: code, ds: data, es: data


data segment
string1 db 'Empty$'
strlen equ($-string1)
string2 db 5h dup(0)
data ends
code segment
start:mov ax,data
mov ds,ax
mov es,ax
30

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

mov bx,offset string1


mov si,bx
mov di,offset string2
add di,5
cld
mov cx,strlen
sl: mov al,[si]
mov es:[di],al
inc si
dec di
loop sl
rep movsb
nop
int 03h
code ends

end start
**************
INPUT: string1: empty
OUTPUT: string2: ytpme
RESULT: Hence we obtained ascending order, block transfer, string operations.

EXP.NO:5) DOS / BIOS Programming: Reading Keyboard (buffered with


and without echo) - Display Characters & Strings.
AIM: To write an ALPs to perform read a character from key board with and without echo, display
of message, character using TASM Assembler.
APPARATUS:
1. Tasm assembler
2. PC

a) Read a character(s) from keyboard and echo using DOS function calls
31

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

Assume cs:code,ds:data
data segment
msg db 'enter characters from keyboard (# to end):','$'
data ends
code segment
start:mov ax,data
mov ds,ax
mov ah,09h
mov dx,offset msg
int 21h
next:mov ah,08h
int 21h
mov ah,02h
mov dl,al
int 21h
cmp al,'#'
jne next
mov ah,4ch
mov al,00h
int 21h
code ends
end start
********************
OUTPUT: enter the character from keyboard: o/p string #

b) Reads a character(s) from keyboard without echo using DOS function


calls.
assume cs:code,ds:data
data segment
msg db 'enter characters from keyboard (# to end):','$'
data ends
code segment
start:mov ax,data
mov ds,ax
mov ah,09h
32

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

mov dx,offset msg


int 21h
next: mov ah,08h
int 21h
cmp al,'#'
jne next
mov ah,4ch
mov al,00h
int 21h
code ends
end start
********************
OUTPUT: enter characters from keyboard: #

c) Display a message on screen using only code segment, and press any key
to return.
assume cs:code
code segment
start: jmp skip
msg db 'S.V.ENGINEERING COLLEGE FOR WOMEN','$'
skip: mov ax,cs
mov ds,ax
mov ah,09h
mov dx,offset msg
int 21h
mov ah,08h
int 21h
mov ah,4ch
mov al,00h
int 21h
code ends
end start
********************
OUTPUT: S.V.ENGINEERING COLLEGE FOR WOMEN (press any key to return)
33

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

d) Display a character on screen


Assume cs:code
code segment
start: mov ax,cs
mov ds,ax
mov ah,02h
mov dl,s
int 21h
mov ah,08h
int 21h
mov ah,4ch
mov al,00h
int 21h
code ends
end start
********************
OUTPUT: s
RESULT: Hence we obtained reading a character with and without echo, display a message,
character.

34

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

INTERFACING

35

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

INTERRUPTS
MOV AX,0000H
MOV CS,AX
MOV ES,AX
MOV CS,AX
MOV SP,3000H
MOV DX,DFFC8H
MOV AL,17H
OUT DX,AL
MOV DX,0FFCAH
MOV AL,48H
OUT DX,AL
MOV AL,03H
OUT DX,AL
MOV AL,00H
OUT DX,AL
STI
HERE: JMP
ORG 3000H
CLI
MOV SI,4000H
MOV AL,0A
MOV [SI],AL
STI
IRET
INT 3H
ORG 3100H
CLI
MOV SI,4100H
MOV AL,0B
MOV [SI],AL
STI
IRET
INT 3H
ORG 3200H
CLI
MOV SI,4002H
MOV AL,0C
36

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

MOV [SI],AL
STI
IRET
INT 3H
ORG 3300H
CLI
MOV SI,4003H
MOV AL,0D
MOV [SI],AL
STI
IRET
INT 3H
ORG 3400H
CLI
MOV SI,4004H
MOV AL,0E
MOV [SI],AL
STI
IRET
INT 3H
ORG 3500H
CLI
MOV SI,4005H
MOV AL,0F
MOV [SI],AL
STI
IRET
INT3H
ORG 3600H
CLI
MOV SI,4006H
MOV AL,10
MOV [SI],AL
STI
IRET
INT 3H
ORG 3700H
CLI
MOV SI,4007H
37

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

MOV AL,11
MOV [SI],AL
STI
IRET
INT 3H
*******************
OUTPUT:

38

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

8279 KEYBOARD DISPLAY


MOV CX, 08
MOV AL, 00
MOV DX, 0FFC2
OUT DX, AL
MOV AL, 90
OUT DX, AL
RPT: MOV AL, 00
MOV DX, 0FFC0
OUT DX, AL
LOOP RPT
MOV DX, 0FFC2
MOV AL, 10
OUT DX, AL
MOV DX, 0FFC2
MOV AL, 90
OUT DX, AL
BCK: MOV SI, 2100
MOV CX, 08
BC0: MOV AL,[SI]
MOV DX, 0FFC0
OUT DX, AL
INC SI
CALL DLY
LOOP BC0
MOV CX, 08
BC1: MOV AL,[SI]
MOV DX, 0FFC0
OUT DX, AL
INC SI
CALL DLY
LOOP BC1
MOV CX, 08
BC2: MOV AL,[SI]
MOV DX, 0FFC0
OUT DX, AL
INC SI
39

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

CALL DLY
LOOP BC2
JMP BCK
PUSH CX
MOV CX, 0000
L1: LOOP L1
POP CX
RET
**********************
INPUT:
ORG 2100H: ASC SVEW
OUT PUT: SVEW

40

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

8255-PPI (SINUSOIDAL WAVE)


ORG 8000H
MOV AX, 0000
MOV CS, AX
MOV ES, AX
MOV DX, 0FFE6
MOV AL, 80
OUT DX, AL
MOV DX, 0FFE0
Back: MOV AL, 00
L1: OUT DX, AL
INC AL
CMP AL, 0F
JB L1
MOV DX, 0FFE0
L2: OUT DX, AL
INC AL
INC AL
INC AL
CMP AL, 0EF
JB L2
MOV DX, 0FFE0
L3: OUT DX, AL
INC AL
CMP AL, 0FF
JB L3
MOV DX, 0FFE0
L4: OUT DX, AL
DEC AL
CMP AL, 0EF
JNBE L4
MOV DX, 0FFE0
L5: OUT DX, AL
DEC AL
DEC AL
CMP AL, 0F
JNBE L5
MOV DX, 0FFE0
41

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

L6: OUT DX, AL


DEC AL
CMP AL, 00
JNBE L6
JMP Back
****************
OUTPUT:

42

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

8251- USART
M53 equ 0FFC6
TM0 equ DFFC0
M51 EQU 0FFCA
V51 EQU 0FFC8
MOV AL, 36
MOV DX, 0FFC6
OUT DX, AL
MOV DX, 0FFC0
MOV AL, 0A
OUT DX, AL
MOV AL, 00
MOV DX, AL
MOV SP, 3000
MOV DX, 0FFCA
OUT DX, AL
OUT DX, AL
OUT DX, AL
OUT DX, AL
CALL DLY
MOV AL, 40
OUT DX, AL
CALL DLY
MOV AL, 0CE
OUT DX, AL
CALL DLY
MOV AL, 27
OUT DX, AL
CALL DLY
MOV SI, 2100
STS: MOV DX, 0FFCA
* IN AL, DX
AND AL, 81
CMP AL, 81
JNE STS
MOV AL, [SI]
INC SI
43

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

CMP AL, 00
JE OVR
MOV DX, 0FFC8
OUT DX, AL
JMP STS
OVR: INT 03H
DLY: MOV CX, 2
L1: LOOP L1
RET
***********************
INPUT: 2100:
OUTPUT:

44

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

MICROCONTROLLER 8051

Read and write on parallel ports


45

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

MOV DPTR, #F183


MOV A, #30
MOVX @DPTR, A
MOV DPTR, #F180
MOV A, #AA
MOVX @DPTR, A
INC DPTR
MOV A, #55
MOVX @DPTR, A
L1: SJMP L1
MOV DPTR, #F183
MOV A, #32
MOV @DPTR, A
MOV DPTR, #F181
MOVX A,@DPTR
MOV DPTR, #F180
MOVX @DPTR, A
L1: SJMP L1
MOV DPTR, #F183
MOV A, #90
MOV DPTR, A
MOV DPTR, #F180
MOVX A,@DPTR
MOV DPTR, #F181
MOVX @DPTR, A
L1: SJMP L1
******************************

SERIAL COMMUNICATION
46

SV COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
MICROPROCESSOR & MICROCONTROLLER LABMANUAL

TRANSMITTER
MOV R2,#05
MOV DPTR,#8500
MOVX A,@DPTR
L1: LCALL 11AEH
INC DPTR
DEC R2
CJNE R2,#00,8005(L1)
L2: SJMP L2
INPUT:
RECEIVER
MOV R2,#05
MOV DPTR,#9500
L1: LCALL 12A5H
MOVX @DPTR,A
INC DPTR
DEC R2
CJNE R2,#00,L1
L2: SJMP L2
OUTPUT:

47

Вам также может понравиться