KEMBAR78
MPMC Lab Manual | PDF | Assembly Language | Computer File
0% found this document useful (0 votes)
8 views45 pages

MPMC Lab Manual

Uploaded by

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

MPMC Lab Manual

Uploaded by

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

JNTUHCER ECE

JAWAHARLAL NEHRU TECHNOLOGICAL


UNIVERSITY HYDERABAD
UNIVERSITY COLLEGE OF ENGINEERING RAJANNA SIRCILLA
Govt. Degree College, Agraharam, RajannaSircilla Dist. Telangana State-505302

This is to certify that this book is the Bonafide record of jobs done by Mr./Miss
of Roll No:
B. Tech 3rd Year Ⅰ Semester Electronics & Communication Engineering Course,
studying this college during the academic year 2024-25.
It is also certified that all the jobs mentioned in this record are completedby the
candidate him/herself in the MICRO PROCESSOR AND MICROCONTROLLER lab
of the J.N.T.U.H. College of Engineering, Rajanna Sircilla

Signature of the Examiner Head of the Department

Date…………… Lab Incharge

JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA


DIST.
JNTUHCER ECE
2

INDEX

S.NO LIST OF THE PAGE. DATE OF DATE OF SIGNATURE


EXPERIMENTS NO EXPERIME SUBMISSIONS
NTS
1. Program for 16-bit 8-12
arithmetic operations for
8086(using various
addressing modes)
2. ALP to 13-14
add,subtract,multiply two
16-bit unsigned numbers
and store the result in extra
segment
3. ALP to divide a 32-bit 15-16
unsigned number by a 16-
bit unsigned number and
store the result in stack
segment
4. ALP to sort the given array 17-18
in 32-bit ascending
order/decending order
5. ALP to pick the median 19-20
from the given array of
numbers
6. ALP to find the length of a 21-22
given string which
terminates with a special
character($)
7. ALP to reverse the string 23-24
and verify for palindrome
8. ALP to insert a character to 25-26
the given string
9. ALP to delete a character 27-28
from the given string

10. Logical operations of 16- 29-32


bit data(software)

JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA


DIST.
JNTUHCER ECE
3

11. Interfacing seven segment 33-34


display with 8051

12. Interfacing keyboard with 35-37


8051
13. Interfacing ADC with 8051 38-40
14. Interfacing DAC with 41-42
8051
15. Interfacing sequence 43-45
generator with 8051.

JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA


DIST.
JNTUHCER ECE
4

Microprocessor and Microcontroller Lab

INTRODUCTION
The Microsoft Macro Assembler (MASM) is an 8086(x86) assembler that uses the INTEL syntax for
MS DOS and Microsoft Windows. The earlier versions were released in the year 1981. Turbo Assembler
(TASM) is also an assembler package developed by Borland which runs on and produces code for 16-
bit or 32-bit x86 MS DOS or Microsoft Windows. These software’s provide the assembly language
tools to program the 8086 processor-based systems.
To program the x86 processor using in MASM certain concepts are very important. They arereserved
words, identifiers, predefined symbols, constants, expressions, operators, registersand statements.
Reserved Words:
A reserved word has a special meaning fixed by the language. This must be used under certainspecial
conditions. These reserved words are
• Instructions, which corresponds to operations the processor can execute.
• Directives, which give commands to the assembler.
• Attributes, which provide a value for a field, such as segment alignment.
• Operators, which are used in expressions.
MASM reserved words are not case sensitive except for predefined symbols. The assembly generates
an error if you use a reserved word as a variable.
For example: The following operands are reserved words. Reserved words are not case sensitive.
$ DWORD PASCAL SWORD
? FAR QWORD SYSCALL
@B FAR16 REAL4 TBYTE
@F FORTRAN REAL8 VARARG
ADDR FWORD REAL 16 WORD
BASIC NEAR SBYTE ZERO?
BYTE NEAR16 SDWORD
C OVERFLOW SIGN?
CARRY? PARITY STDCALL

Predefined Symbols: Unlike most MASM reserved words, predefined symbols are case sensitive.
@CatStr* @Environ* @Model*
@Code @fardata @SizeStr*
@CodeSize @fardata? @stack*
@Cpu @FileCur* @SubStr*
@CurSeg @FileName @Time*
@data @InStr* @Version
@DataSize @Interface* @WordSize
@Date @Line @Model*

JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA


DIST.
JNTUHCER ECE
5

Registers:

AL CX EAX SP
AX DH EBP SS
BH DI EBX ST
BL DL ECX TR3*
BP DR0 EDI TR4*
BX DR1 EDX TR5*
CH DR2 ES TR6
CL DR3 ESI TR7

Identifiers:
An identifier is a name that you invert and attach to a definition. Identifiers can be symbols
representing variables, constants, procedure names, code labels, segment names and user
defined data types such as structures, unions, records and types defined with TYPEDEF.
Identifiers longer than 247 characters generate an error.
• The first character of the identifier can be an alphabetic character (A - Z) or any of
these four characters. They are @ _ $ ?
• The other characters in the identifier can be any of the characters listed above or a
decimal digit(0 - 9).
Predefined Symbols:
The assembler includes a number of predefined symbols (also called predefined equates). These
symbols can be used at any point in the code to represent the equate value. For example: The
predefined equate @FileName represents the base name of the current file. If the current source
file is TASK.ASM, the value of the @FileName is TASK.
Integer Constants and Constant Expressions:
An integer constant is a series of one or more numerals followed by an optional radix specifier.
For example, in the following statements:
mov ax,25
mov bx,0B3
the number 25 and 0B3H are integer constants.
Operators:
Operators are used in expressions. The assembler evaluates the expressions that containsmore
than one operator according to the following rules:
• Operations in parenthesis are performed before adjacent operations.
• Binary operations of highest precedence are performed first.
• Operations of equal precedence are performed from left to right.
• Unary Operations of equal precedence are performed right to left.
Examples of the operators are: +, - (unary), &, *, /, %(MOD), SHL, SHR, +, - (binary), EQ, NE,
LT, LE, GT, GE, NOT, AND, OR, XOR, OPATTR, SHORT, TYPE.
Data Types;
JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA
DIST.
JNTUHCER ECE
6

A “data type” describes a set of values. For example: BYTE, SBYTE,


WORD,SWORD, DWORD, SDWORD, FWORD, QWORD and TBYTE.
Registers:
The 8086 family of processors have a set of 16-bit registers. They are AX, BX, CX, DX
(General purpose registers). Segment registers like SS, CS, DS, ES and Pointer registers likeSP
and BP and Index register like DI and SI etc.
Statements:
Statements are the line by line components of source files. Each MASM statement specifies an
instruction or directive for the assembler. Statements have up to four fields[[name:]]
[[operation]] [[operands]][[;comment]]
Assembly Language Development Tools:
To develop an assembly language program, we need certain program development tools. The
various development tools required for 8086 programming are explained below.
1. Editor: An editor is a program which allows us to create a file containing the assembly
language statements for the program. Examples of some editors are PC Write, Word-
Star. As we the program the editor stores the ASCII codes for the letters and numbers in
successive RAM locations. If any typing mistake is done editor will alert us to correct it.
If we leave out a program statement an editor will let you move everything down and
insert a file. After typing all the program, we have to save the program for a hard disk.
This we call it as source file. The next step is to process the source file with an
assembler. While using TASM or MASM we should give a filename and extension as
.ASM forexample: Sample.asm
2. Assembler: An assembler is used to translate the assembly language mnemonics to
machine level language (i.e., binary codes). When you run the assembler, it reads the
source file of your program from where you have saved it. The assembler generates two
files. The first file is the Object file with .OBJ extension. The Object file consists ofthe
binary codes for the instructions and information about the addresses of the instructions.
After further processing, the contents of the file will be loaded in to memory and run.
The second file is the assembler list file with the. LST extension.
3. Linker: A linker is a program used to connect several object files into one large object
file. While writing large programs it is better to divide the large programs into smaller
modules. Each module can be individually written, tested and debugged. Then all the
object modules can also be kept in library file and linked into other programs as needed.
A linker produces a link file which contains the binary codes for all the combined
modules. The linker also produces a link map file which contains the addressinformation
about the linked files. The linkers which come with TASM or MASM assemblers
produce link files with the .EXE extension
4. Locator: A locator is a program used to assign the specific address of where the
segments of object code are to be loaded into memory. A locator program called
EXE2BIN comes with the IBMPC Disk Operating System (DOS). EXE2BIN converts
aEXE file to a .BIN file which has a physical address.
5. Debugger: A debugger is a program which allows to load your object code program
into system memory, execute the program and troubleshoot or debug it. The debugger
allows to look into the contents of registers and memory locations after the program
runs. We can also change the contents of registers and memory locations and rerun the
JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA
DIST.
JNTUHCER ECE
7

program. Some debuggers allow to stop the program after each instruction so thatyou
can check or alter the memory and register contents. This is called Single Step.
Debug. A debugger also allows to set a breakpoint, the debugger will run the program
up to the instruction where the breakpoint is put and then stop the execution.
6. Emulator: An emulator is a mixture of hardware and software. It is usually used to test
and debug the hardware and software of an external system such as the prototype ofa
microprocessor-based instrument.
Assembler Directives:
Assembler Directives are the directions to the assembler which indicate how an operand or
section of the program is to be processed. These are also called pseudo operations which
are not executable by the microprocessor. The various directives are explained below.
1. ASSUME: The ASSUME directive is used to inform the assembler the name of the
logical segment it should use for a specified segment.Ex:ASSUME DS:DATA tells
the assembler that for any program instruction which refers to the data segment it
should use the logical statement called DATA.
2. DB: Define Byte. It is used to declare a byte variable or set aside one or more storage
locations of type byte in memory. For
example, CURRENT_VALUE DB 36H tells the assembler to reserve one byte of
memory for a variable named CURRENT_VALUE and put the value 36H in that
memory location when the program is loaded into RAM.
3. DW: Define Word. It tells the assembler to define a variable of type word or to
reserve storage locations of type word in memory.
4. DD: Define Double Word. This directive is used to declare a variable of type double
word or restore memory locations which can be accessed as type double word
5. DQ: Define Quadword. This directive is used to tell the assembler to declare a
variable word in length or to reserve four words of storage in memory.
6. DT: Define Ten bytes. It is to inform the assembler to define a variable which is 10
bytes in length or to reserve 10 bytes of storage in memory.
7. EQU: Equate. It is used to give a name to some value or symbol. Every time the
assembler finds the given name in the program, it will replace the name with the
value or symbol we have equated with that name.
8. ORG: Originate. The ORG statement changes the starting offset address of the data.
It allows to set the location counter to a desired value at any point in the program.
For example, the statement ORG 3000H tells the assembler to set the location
counter to 3000H.
9. PROC: Procedures. It is used to identify the start of a procedure or subroutine.
10. END: End program. This directive indicates the assembler that is the end of the
program module. The assembler ignores any statements after the END directive.
11. ENDP: End Procedure. It indicates the end of the procedure (subroutine) to the
assembler.
12. ENDS: End Segment. This directive is used with the name of the segment to
indicate the end of the logical statement. Ex
: CODE SEGMENT : Start of logical significant containing code.
COD
EENDS: End of the segment named code.

JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA


DIST.
JNTUHCER ECE
8

Experiment no. 1
PROGRAM FOR 16-BIT ARITHMETIC OPERATIONS FOR 8086(USING
VARIOUS ADDRESSING MODES)
ADDITION:
a) Code:

assume cs:code
code segment
mov
ax,0ABCDH
mov
bx,0ABCDHadd
ax,bx
int 03H
code ends
end
Result:

JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA


DIST.
JNTUHCER ECE
9

a) Code:
data segment
num1 dW 1111H
num2 dW 2222H
res dW ?
data ends
assume cs:code,ds:data
code segment
movax,data
movds,ax
mov ax,num1
mov bx,num2
add ax,bx
movres,ax
int 03H
code ends
end
Result:

JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA


DIST.
JNTUHCER ECE
10

Subtraction:

Code:
assume cs:code
code segment
mov ax,2222H
mov bx,1111H
sub ax,bx
int 03H
code ends
end
Result:

JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA


DIST.
JNTUHCER ECE
11

Multiplication:
Code:
assume cs:code
code segment
mov ax,2222H
mov bx,1111H
mulbx
int 03H
code ends
end
Result:

JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA


DIST.
JNTUHCER ECE
12

Division:
Code:
assume cs:code
code segment
mov ax,2222H
mov bx,1111H
div bx
int 03H
code ends
end
Result:

JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA


DIST.
JNTUHCER ECE
13

EXPERIMENT NO.2

ALP TO ADD, SUBTRACT, MULTIPLY TWO 16-BIT UNSIGNED NUMBERS


AND STORE THE RESULT IN EXTRA SEGMENT

ASSUME CS:CODE,ES:EXTRA
CODE SEGMENT
MOVAX,EXTRA
MOV ES,AX
MOV DI,OFFSET SUM
XOR AX,AX
MOV AX,2222H
MOV CX,AX
MOV BX,1111H
ADD AX,BX
CLD
STOSW
XOR AX,AX
XOR DX,DX
MOV AX,CX
SUB AX,BX
STOSW
XOR AX,AX
MOV AX,C
MUL BX
STOSW
MOV BP,AX
MOV AX,DX
STOSW
INT 03H
CODE ENDS
EXTRA SEGMENT
SUM DW 01H DUP(?)

JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA


DIST.
JNTUHCER ECE
14
DIF DW 01H DUP(?)
PRO DW 02H DUP(?)

EXTRA ENDS
END

OBSERVE THE RESULT IN EXTRA SEGMENT

ALP TO ADD, SUBTRACT, MULTIPLY TWO 16-BIT UNSIGNED NUMBERS WITH


MACHINE CODE AND ADDRESSES

JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA


DIST.
JNTUHCER ECE
15

EXPERIMENT NO.3
ALP TO DIVIDE A 32-BIT UNSIGNED NUM BY A 16-BIT UNSIGNED
NUM AND STORE THE RESULT IN STACK SEGMENT
ASSUME CS:CODE,SS:STACK
CODE SEGMENT
MOV AX,STACK
MOV SS,AX
MOV BP,OFFSET QUOTIENT
MOV SP,BP
XOR AX,AX
MOV AX,2000H /* TAKE THE DIVISOR VALUE IN BX THAT DOESN'TLEAD
TO DIVIDE OVERFLOW */
MOV DX,4000H
MOV BX,8000H
DIV BX
PUSH AX
PUSH DX
INT 03H
CODE ENDS
STACK SEGMENT
ORG 2000H
QUOTIENT DW 01H DUP(?)
REMAINDER DW 01H DUP(?)
STACK ENDS
END

JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA


DIST.
JNTUHCER ECE
16

OBSERVE THE RESULT IN STACK SEGMENT

ALP TO DIVIDE32-BIT UNSIGNED NUMBER BY A 16-BIT UNSIGNED NUMBER WITH


MACHINE CODE AND ADDRESSES

JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA


DIST.
JNTUHCER ECE
17

EXPERIMENT NO.4

ALP TO SORT THE GIVEN ARRAY IN


32-BIT ASCENDING ORDER / DESCENDING ORDER

ASSUME CS:CODE,DS:DATA
CODE SEGMENT
MOV AX,DATA
MOV DS,AX
XOR AX,AX
MOV DX,0003H
L4: MOV CX,DX
MOV SI,OFFSET LIST
L3: XOR AX,AX
MOV AX,[SI+2]
CMP AX,[SI+6]
JC/JNC L1 /* For ascending JC L1,For descending JNC L1*/
JE L2
XCHG [SI+6],AX
XCHG [SI+2],AX
MOV BP,[SI]
XCHG [SI+4],BP
XCHG [SI],BP
JMP L1
L2: MOV DI,[SI]
CMP DI,[SI+4]
JC L1
XCHG DI,[SI+4]
XCHG DI,[SI]
L1: ADD SI,04H
LOOP L3
DEC DX
JNZ L4
INT 03H

JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA


DIST.
JNTUHCER ECE
18

CODE ENDS
DATA SEGMENT
LIST DD 0000CD34H,0000AB12H,002344AAH,00549120H
DATA ENDS
END

OBSERVE THE RESULT IN DATA SEGMENT

ALP TO SORT THE GIVEN ARRAY IN 32-BIT ASCENDING ORDER / DESCENDING


ORDER WITH MACHINE CODE AND ADDRESSES

JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA


DIST.
JNTUHCER ECE
19

EXPERIMENT NO.5
ALP TO PICK THE MEDIAN FROM THE GIVEN ARRAY OF NUMBERS
ASSUME CS:CODE,DS:DATA
CODE SEGMENT
MOV AX,DATA
MOV DS,AX
XOR AX,AX
MOV DX,0007H
L3: MOV CX,DX
MOV SI,OFFSET LIST
XOR AX,AX
L2: MOV AL,[SI]
CMP AL,[SI+1]
JC L1
JE L1
XCHG [SI+1],AL
XCHG [SI],AL
L1: INC SI
LOOP L2
DEC DX
JNZ L3
MOV SI,OFFSET LIST
MOV BL,02H
MOV AL,[SI+3]
ADD AL,[SI+4]
DIV BL
MOV [SI+8],AX
INT 03H
CODE ENDS
DATA SEGMENT
LIST DB 08H,07H,09H,06H,04H,03H,01H,02H
RESULT DW 01H DUP(?)

JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA


DIST.
JNTUHCER ECE
20

DATA ENDS
END
OBSERVE THE RESULT IN DATA SEGMENT

ALP TO PICK THE MEDIAN FROM THE GIVEN ARRAY OF NUMBERS WITH MACHINE
CODE AND ADDRESSES

JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA


DIST.
JNTUHCER ECE
21

EXPERIMENT NO.6
ALP TO FIND THE LENGTH OF A GIVEN STRING WHICH TERMINATES WITH A
SPECIAL CHARACTER ($)
ASSUME CS:CODE,ES:EXTRA
CODE SEGMENT
MOV AX,EXTRA
MOV ES,AX
XOR AX,AX
LEA DI,STRING
MOV AL,KEY
CLD
L1: SCASB
JNE L1
MOV AX,DI
DEC AX
INT 03H
CODE ENDS
EXTRA SEGMENT
STRING DB "MICROPROCESSORS","$"
KEY EQU "$"
EXTRA ENDS
END

JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA


DIST.
JNTUHCER ECE
22

OBSERVE THE OUTPUT IN REGISTERS AND EXTRA SEGMENT

ALP TO FIND THE LENGTH OF A GIVEN STRINGWITH MACHINE CODE AND


ADDRESSES

JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA


DIST.
JNTUHCER ECE
23

EXPERIMENT NO.7
ALP TO REVERSE THE STRING AND VERIFY FOR PALINDROME
ASSUME CS:CODE,DS:DATA,ES:DATA
CODE SEGMENT
MOV AX,DATA
MOV DS,AX
MOV ES,AX
XOR AX,AX
XOR BX,BX
MOV CX,COUNT
LEA SI,SOURCE
LEA DI,DEST+4
L1: MOV AL,[SI]
MOV [DI],AL
INC SI
DEC DI
LOOP L1
MOV CX,COUNT
LEA SI,SOURCE
LEA DI,DEST
CLD
REPE CMPSB
JNZ L2
MOV BL,0FFH /*RETURN 0FFH IN BL REGISTER FOR PALINDROME */
L2: INT 03H
CODE ENDS
DATA SEGMENT
SOURCE DB "MADAM"
ORG 2000H
DEST DB 0FH DUP(?)
COUNT EQU 0005H

DATA ENDS

JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA


DIST.
JNTUHCER ECE
24

END

OBSERVE THE OUTPUT IN DATA SEGMENT AND RETURN CODE IN BX REGISTER

ALP TO REVERSE THE STRING AND VERIFY FOR PALINDROMEWITH MACHINE CODE
AND ADDRESSES

JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA


DIST.
JNTUHCER ECE
25

EXPERIMENT NO.8
ALP TO INSERT A CHARACTER TO THE GIVEN STRING

ASSUME CS:CODE,DS:DATA
CODE SEGMENT
MOV AX,DATA
MOV DS,AX
MOV ES,AX
XOR AX,AX
LEA SI,SOURCE
LEA DI,DEST
MOV CX,COUNT1
CLD
REP MOVSB
LEA BX,INSERT
MOV AL,[BX]
STOSB
MOV CX,COUNT2
REP MOVSB
INT 03H
CODE ENDS
DATA SEGMENT
SOURCE DB "TOMJERRY"
INSERT DB "&"
ORG 2000H
DEST DB 0FH DUP(?)
COUNT1 EQU 0003H
COUNT2 EQU 0005
DATA ENDS
END

JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA


DIST.
JNTUHCER ECE
26

OBSERVE THE OUTPUT IN DATA SEGMENT

ALP TO INSERT A CHARACTER TO THE GIVEN STRING WITH MACHINE CODE AND
ADDRESSES

JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA


DIST.
JNTUHCER ECE
27

EXPERIMENT NO.9
ALP TO DELETE A CHARACTER FROM THE GIVEN STRING

ASSUME CS:CODE,DS:DATA
CODE SEGMENT
MOV AX,DATA
MOV DS,AX
MOV ES,AX
XOR AX,AX
LEA SI,SOURCE
LEA DI,DEST
MOV CX,COUNT1
CLD
REP MOVSB
INC SI
MOV CX,COUNT2
REP MOVSB
INT 03H
CODE ENDS
DATA SEGMENT
SOURCE DB "TOM&JERRY"
ORG 2000H
DEST DB 0FH DUP(?)
COUNT1 EQU 0003H
COUNT2 EQU 0005H
DATA ENDS
END

JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA


DIST.
JNTUHCER ECE
28

OBSERVE THE OUTPUT IN DATA SEGMENT

ALP TO DELETE A CHARACTER FROM THE GIVEN STRINGWITH MACHINE CODE AND
ADDRESSES

JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA


DIST.
JNTUHCER ECE
29

EXPERIMENT NO.10
LOGICAL OPERATIONS OF 16-BIT DATA (SOFTWARE)
AIM:TO WRITE A ASSEMBLY LANGUAGE PROGRAM FOR LOGICAL
OPERATIONS OF 16-BIT DATA USING IMMEDIATE ADDRESSING MODE.
COMPONENTS: MASM SOFTWARE, DOS BOX
PROGRAM:

A.AND GATE:
ASSUME CS: CODE
CODE SEGMENT
START: MOV AX, 3214H
MOV BX, 6839H
AND AX, BX
INT O3H
CODE ENDS
END START

B.OR GATE
ASSUME CS: CODE
CODE SEGMENT
START: MOV AX 5472H
MOV BX, 9283H
OR AX, BX
INT 03H
CODE ENDS
END START
C.NOT GATE:
ASSUME CS: CODE
CODE SEGMENT
START: MOV AX, 4286H
NOT AX
INT O3H
CODE ENDS
END START

JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA


DIST.
JNTUHCER ECE
30

D.EX-OR GATE:
ASSUME CS: CODE
CODE SEGMENT
START: MOV AX, 1750H
MOV BX, 6573H
XOR AX, BX
INT O3H
CODE ENDS
END START
E.NOR GATE:
ASSUME CS: CODE
CODE SEGMENT
START: MOV AX, 9784H
MOV BX, 4653H
OR AX, BX
NOT AX
INT O3H
CODE ENDS
END START
F.NAND GATE:
ASSUME CS: CODE
CODE SEGMENT
START: MOV AX, 2330H
MOV BX, 3728H
AND AX, BX
NOT AX
INT O3H
CODE ENDS
END START

JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA


DIST.
JNTUHCER ECE
31

G.EX-NOR GATE:
ASSUME CS: CODE
CODE SEGMENT
START: MOV AX, 3928H
MOV BX, 4287H
XOR AX, BX
NOT AX
INT O3H
CODE ENDS
END START

RESULT:

AND GATE:
INPUT1:3214H
INPUT2: 6879H
OUTPUT: 2010H

OR GATE:
INPUT1: 5472H
INPUT2: 6839H
OUTPUT: D673H

NOT GATE:
INPUT: 4286H
OUTPUT: BD79H

EX-OR GATE:
INPUT1: 1750H
INPUT2: 6573H
OUTPUT: 7223H

JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA


DIST.
JNTUHCER ECE
32

NOR GATE:
INPUT1: 9784H
INPUT2: 4653H
OUTPUT: 2828H

NAND GATE:
INPUT1: 2330H
INPUT2: 3728H
OUTPUT: DCDFH

EX-NOR GATE:
INPUT1: 3928H
INPUT2: 4287H
OUTPUT: 8450H

JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA


DIST.
JNTUHCER ECE
33

EXPERIMENT NO.11
INTERFACING SEVEN SEGMENT DISPLAY WITH 8051

; Define port addresses for 8255


PORTA EQU 2020H ; Address for Port A
PORTB EQU 2021H ; Address for Port B
PORTC EQU 2022H ; Address for Port C
CNTRL EQU 2023H ; Control port address
CNT EQU 40H ; Counter variable address
; Start of the program
ORG E000H
LJMP MAIN ; Jump to MAIN program

; Timer interrupt vector


ORG 8020H
LJMP TMR0_ISR ; Jump to Timer0 interrupt service routine

MAIN:
MOV A,#80H ; Load A with control word for 8255
MOV DPTR,#CNTRL ; Set DPTR to control port address
MOVX @DPTR,A ; Send control word to control port

MOV TMOD,#01H ; Set Timer0 to Mode 1 (16-bit timer mode)


MOV TL0,#CDH ; Load initial value into Timer0 low byte
MOV TH0,#F8H ; Load initial value into Timer0 high byte

MOV CNT,#00H ; Initialize counter to 0

MOV A,#07H ; Load A with value to turn on all LEDs


MOV DPTR,#PORTC ; Set DPTR to Port C
MOVX @DPTR,A ; Write value to Port C

SETB ET0 ; Enable Timer0 interrupt


SETB EA ; Enable global interrupts
SETB TR0 ; Start Timer0
SETB P1.0 ; Set P1.0 (assume LED ON)

HERE: SJMP HERE ; Infinite loop (idle here)

TMR0_ISR:
CPL P1.0 ; Toggle P1.0 (toggle LED)
JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA
DIST.
JNTUHCER ECE
34

MOV DPTR,#DISP ; Point to DISP table


MOV A,DPL ; Load lower byte of DPTR into A
ADD A,CNT ; Add counter value to A
MOV DPL,A ; Update DPL with new value
MOVX A,@DPTR ; Get display data from memory

MOV DPTR,#PORTA ; Set DPTR to Port A


MOVX @DPTR,A ; Output display data to Port A

MOV A,CNT ; Load counter value into A


MOV DPTR,#PORTC ; Set DPTR to Port C
MOVX @DPTR,A ; Output counter value to Port C

INC CNT ; Increment counter


MOV A,CNT ; Load updated counter value
CJNE A,#06H,L1 ; Check if counter equals 6, if not, jump to L1

MOV DPTR,#DISP ; Reset DPTR to DISP table


MOV CNT,#00H ; Reset counter to 0

L1: MOV TL0,#CDH ; Reload Timer0 low byte


MOV TH0,#F8H ; Reload Timer0 high byte

RETI ; Return from interrupt

DELAY:
MOV R0,#7FH ; Load R0 with 127 (outer loop counter)
OLOOP: MOV R1,#FFH ; Load R1 with 255 (inner loop counter)
ILOOP: DJNZ R1,ILOOP ; Decrement R1 and loop if not zero
DJNZ R0,OLOOP ; Decrement R0 and loop if not zero
RET ; Return from subroutine

ORG F000H
DISP: DB 6DH,66H,4FH,5BH,06H,3FH ; Display table for 7-segment display

END ; End of the program

RESULT :
Hence result observed on trainer kit.

JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA


DIST.
JNTUHCER ECE
35

EXPERIMENT NO.12

INTERFACING KEYBOARD WITH 8051

; PROGRAM FOR KEYBOARD DISPLAY


CNTRL EQU 2023H ; Control port address of 8255
PORTA EQU 2020H ; Port A address of 8255
PORTB EQU 2021H ; Port B address of 8255
PORTC EQU 2022H ; Port C address of 8255

KEY_CD EQU F800H ; Memory location for key code


UPDAT EQU 676FH ; Address of display update routine
TSAVE EQU 0196H ; Temporary save location

ORG E000H ; Set starting address of program

; Initialization
MOV A,#90H ; Set control word for 8255
MOV DPTR,#CNTRL ; Load control port address into DPTR
MOVX @DPTR,A ; Write control word to control port

MOV DPTR,#KEY_CD ; Load key code address into DPTR


MOVX @DPTR,A ; Clear the key code memory location

; Main loop
START: LCALL SCAN ; Call SCAN subroutine to read keyboard
MOV DPTR,#TSAVE ; Load temporary save location into DPTR
MOVX @DPTR,A ; Save key code
LCALL UPDAT ; Call display update routine
SJMP START ; Repeat the process

; Keyboard scanning routine


SCAN:
MOV R5,#00H ; Initialize R5 for key code calculation
MOV A,#07H ; Enable all rows of the keyboard
MOV DPTR,#PORTC ; Load Port C address into DPTR
MOVX @DPTR,A ; Write to Port C

BK:
MOV DPTR,#PORTA ; Load Port A address into DPTR
MOVX A,@DPTR ; Read data from Port A
JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA
DIST.
JNTUHCER ECE
36
CJNE A,#00H,L1 ; Check if any key is pressed
SJMP BK ; If no key, keep checking

L1:
LCALL DELAY ; Debounce delay
MOV DPTR,#PORTA ; Load Port A address again
MOVX A,@DPTR ; Read data from Port A
CJNE A,#00H,L2 ; Check if key is still pressed
SJMP BK ; If not, recheck
L2:
MOV R5,#00H ; Reset key code accumulator
MOV A,#01H ; Enable first row
MOV R7,A ; Save row selection in R7
MOV R6,#00H ; Initialize column tracker R6

REV:
MOV DPTR,#PORTC ; Load Port C address
MOVX @DPTR,A ; Set row selection on Port C
MOV DPTR,#PORTA ; Load Port A address
MOVX A,@DPTR ; Read column data from Port A
CJNE A,#00H,L3 ; Check if key is pressed in current row
SJMP L4 ; If pressed, find the key
L3:
SJMP NEXT ; Otherwise, check next row

L4:
MOV A,R6 ; Add column offset to R6
ADD A,#08H
MOV R6,A ; Save updated column offset in R6
MOV A,R7 ; Rotate row selection
RL A
MOV R7,A ; Update row selection
CJNE A,#08H,L5 ; Check if all rows are scanned
SJMP SCAN ; If done, rescan
L5:
SJMP REV ; Continue scanning in the next row

NEXT:
CLR C ; Clear carry bit
RRC A ; Rotate column bits
JC FND ; If bit set, key found
INC R5 ; Otherwise, increment column
JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA
DIST.
JNTUHCER ECE
37
SJMP NEXT ; Check next column

FND:
MOV A,R7 ; Get row selection
CJNE A,#01H,L6 ; Determine row number
MOV A,R5 ; Get column code
SJMP L7 ; Combine row and column
L6:
CJNE A,#02H,L8 ; Check for next row
MOV A,R5 ; Add offset for second row
ADD A,#08H
MOV R5,A
SJMP L7 ; Save key code
L8:
MOV A,R5 ; Add offset for third row
ADD A,#10H
MOV R5,A
L7:
RET ; Return from SCAN

; Delay subroutine for debouncing


DELAY:
MOV R2,#0FFH ; Outer loop counter
L9: MOV R1,#0FFH ; Inner loop counter
L10: DJNZ R1,L10 ; Inner loop
DJNZ R2,L9 ; Outer loop
RET ; Return from DELAY

END ; End of program

RESULT :
Hence result observed on trainer kit.

JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA


DIST.
JNTUHCER ECE
38

EXPERIMENT NO.13

INTERFACING ADC WITH 8051

CONTROL EQU 2023H ; Address of the control port for the 8255
PORTA EQU 2020H ; Address of Port A
PORTB EQU 2021H ; Address of Port B
PORTC EQU 2022H ; Address of Port C
UPDD EQU 677DH ; Address of the display routine
TEMP EQU 40H ; Temporary memory location for intermediate storage

ORG E000H ; Set the program starting address to E000H

; Initialize the control port to set Port A as input, Port B and Port C as
output
MOV DPTR, #CONTROL
MOV A, #90H ; Configuration: Port A input, Port B and Port C output
MOVX @DPTR, A ; Write configuration to the control port

GET_NEXT:
MOV TEMP, #00H ; Clear TEMP register
MOV DPTR, #F000H ; Set DPTR to point to memory location F000H
MOVX A, @DPTR ; Read data from external memory
ANL A, #0FH ; Mask the upper nibble (only keep the lower 4 bits)
MOV TEMP, A ; Store the masked value in TEMP

; Output the channel number from TEMP to Port C


MOV A, TEMP
MOV DPTR, #PORTC
MOVX @DPTR, A

NOP ; Short delay


NOP

; Set PC6 to enable output


MOV A, #0DH ; Set PC6 (OE)
MOV DPTR, #CONTROL
MOVX @DPTR, A

JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA


DIST.
JNTUHCER ECE
39
; Set PC7 to start data conversion
MOV DPTR, #CONTROL
MOV A, #0FH ; Set PC7 (START/ALE)
MOVX @DPTR, A

; Delay loop for 30 milliseconds


MOV R3, #30H ; Outer loop counter
LOP: MOV R4, #FFH ; Inner loop counter
LOP1: NOP ; Short delay
NOP
DJNZ R4, LOP1 ; Decrement R4 and loop if not zero
DJNZ R3, LOP ; Decrement R3 and loop if not zero

; Reset PC7
MOV A, #0EH ; Clear PC7 (START)
MOVX @DPTR, A

NOP ; Short delay


NOP
; Reset PC6 to prepare for End of Conversion (EOC) signal
MOV DPTR, #CONTROL
MOV A, #0CH ; Clear PC6
MOVX @DPTR, A

AD2: ; Wait for End of Conversion (EOC) signal


MOV DPTR, #PORTA ; Point DPTR to Port A
MOVX A, @DPTR ; Read data from Port A
ANL A, #80H ; Mask all bits except ACC.7
JNB ACC.7, AD2 ; If ACC.7 (EOC) is not set, keep polling

; Set PC6 to enable output


MOV A, #0DH ; Set PC6 (OE)
MOV DPTR, #CONTROL
MOVX @DPTR, A

; Read the digital value from Port A


MOV DPTR, #PORTA
MOVX A, @DPTR
MOV R6, A ; Store the digital value in R6
LCALL UPDD ; Call display routine at address UPDD

; Loop back to get the next input


JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA
DIST.
JNTUHCER ECE
40
SJMP GET_NEXT

END ; End of program

RESULT :
Hence result observed on trainer kit.

JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA


DIST.
JNTUHCER ECE
41

EXPERIMENT NO.14

INTERFACING DAC WITH 8051

PORTCP EQU 2023H ; Define the address of the 8255 control port
PORTA EQU 2020H ; Define the address of Port A
PORTB EQU 2021H ; Define the address of Port B
PORTC EQU 2022H ; Define the address of Port C
DELAY EQU 684EH ; Define a delay constant (not directly used here)

; ****** SQUARE WAVE GENERATION FROM DUAL DAC ******

ORG E000H ; Set the program's starting address to E000H

; Initialize the 8255 control port


MOV DPTR, #PORTCP ; Set DPTR to point to the 8255 control port
MOV A, #80H ; Load 80H into accumulator to configure 8255
MOVX @DPTR, A ; Write 80H to the control port to set Port C as
output

BEGIN:
; Generate a low state for the square wave
MOV A, #00H ; Load 00H (minimum value) into the accumulator
LCALL SUBR ; Call SUBR to output the value to both DACs

; Generate a high state for the square wave


MOV A, #FFH ; Load FFH (maximum value) into the accumulator
LCALL SUBR ; Call SUBR to output the value to both DACs

; Repeat indefinitely
LJMP BEGIN ; Jump back to BEGIN for continuous square wave
generation

SUBR:
; Output the current value of A to both DACs
MOV DPTR, #PORTA ; Set DPTR to point to Port A
MOVX @DPTR, A ; Output the value of A to Port A (DAC 1)
MOV DPTR, #PORTB ; Set DPTR to point to Port B
MOVX @DPTR, A ; Output the value of A to Port B (DAC 2)

; Implement a delay to maintain the waveform period


PUSH R0 ; Save R0 on the stack
PUSH R1 ; Save R1 on the stack

MOV R0, #06H ; Load R0 with 06H (outer loop counter for delay)
SB2: MOV R1, #FFH ; Load R1 with FFH (inner loop counter for delay)
SB1: NOP ; No operation (short delay)
DJNZ R1, SB1 ; Decrement R1 and loop to SB1 if not zero
DJNZ R0, SB2 ; Decrement R0 and loop to SB2 if not zero

POP R1 ; Restore R1 from the stack


POP R0 ; Restore R0 from the stack

JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA


DIST.
JNTUHCER ECE
42
RET ; Return from SUBR

END ; End of the program

RESULT :
Hence result observed on trainer kit

JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA


DIST.
JNTUHCER ECE
43

EXPERIMENT NO.15

INTERFACING SEQUENCE GENERATER WITH 8051

A51 MACRO ASSEMBLER SEQUENCE

12/12/2024 14:44:08 PAGE 1

MACRO ASSEMBLER A51 V8.00b

OBJECT MODULE PLACED IN sequence.OBJ

ASSEMBLER INVOKED BY: C:\Keil\C51\BIN\A51.EXE sequence.asm


SET(SMALL) DEBUG EP

LOC OBJ LINE SOURCE

---- 3 cseg at 100h

0100 6 MAIN:

0100 120122 7 lcall uart_init

0103 AC08 8 MOV R4,08

0105 E501 9 MOV A,1H

0107 FE 10 NXT_CH: MOV R6,A

0108 2430 11 ADD A,#30H ; convert to


ASCII

010A B43A00 12 CJNE A,#3AH,N00 ;


check the no is 0 - 9

010D 4002 13 N00: JC N05


; yes jump out

010F 2407 14 ADD A,#07H ;


add 07 to convert 10 - 15

15
; as A to F

0111 311A 16 N05: CALL SEND ;


o/p to serial

0113 EE 17 MOV A,R6


;get the number back

JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA


DIST.
JNTUHCER ECE
44
0114 2402 18 ADD A,#02
; add 2 to it.

0116 DCEF 19 DJNZ R4, NXT_CH ; if


8 terms are not yet over continue

0118 80FE 20 L0: JMP L0 ;


stay here

21

22 ; Send routine to send character to


serial port

011A 23 SEND:

011A 3099FD 24 L10: JNB TI,L10 ;wait for


TI flag to set

011D F599 25 MOV SBUF,A ;put the


data into SBUF

011F C299 26 CLR TI

0121 22 27 RET

28

29

0122 30 uart_init:

31

0122 7450 32 mov a,#50h ;SCON is


initialised with 8-bit,1 start,

0124 F598 33 mov SCON,a ;1 stop


bit,in mode1

0126 7400 34 mov a,#00h

0128 F588 35 mov TCON,a

012A 7420 36 mov a,#20h ;8-bit


auto reload used to set baud rate

012C F589 37 mov TMOD,a

012E 74FD 38 mov a,#0fdh

0130 F58D 39 mov TH1,a

0132 F58B 40 mov TL1,a

0134 D28E 41 setb TR1 ;start


timer1

0136 D299 42 setb TI

0138 22 43 ret

JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA


DIST.
JNTUHCER ECE
45
44

45 end

A51 MACRO ASSEMBLER SEQUENCE


12/12/2024 14:44:08 PAGE 2

SYMBOL TABLE LISTING

------ ----- -------

NAME T Y P E V A L U E ATTRIBUTES

L0 . . . . . . . . C ADDR 0118H A

L10. . . . . . . . C ADDR 011AH A

MAIN . . . . . . . C ADDR 0100H A

N00. . . . . . . . C ADDR 010DH A

N05. . . . . . . . C ADDR 0111H A

NXT_CH . . . . . . C ADDR 0107H A

SBUF . . . . . . . D ADDR 0099H A

SCON . . . . . . . D ADDR 0098H A

SEND . . . . . . . C ADDR 011AH A

TCON . . . . . . . D ADDR 0088H A

TH1. . . . . . . . D ADDR 008DH A

TI . . . . . . . . B ADDR 0098H.1 A

TL1. . . . . . . . D ADDR 008BH A

TMOD . . . . . . . D ADDR 0089H A

TR1. . . . . . . . B ADDR 0088H.6 A

UART_INIT. . . . . C ADDR 0122H A

REGISTER BANK(S) USED: 0

ASSEMBLY COMPLETE. 0 WARNING(S), 0 ERROR(S)

RESULT :
Hence result observed on trainer kit.

JNTUH COLLEGE OF ENGINEERING, AGRAHARAM, RAJANNA SIRICILLA


DIST.

You might also like