MPMC Lab Manual 2023-24
MPMC Lab Manual 2023-24
V Semester
(Autonomous)
Signature Signature
Date: Date:
List of experiments
Lab Content
Number
Experiments Based On 8086 Microprocessor using MASM IDE
1 Data transfer program using different addressing modes in assembly language
programming.
2 Perform arithmetic operations on 8 bit and 16 bit numbers in assembly language
programming.
3 Data transfer program using string instruction in assembly language programming.
4 Program for data conversion in assembly language programming.
5 Write assembly language program using procedure.
6 Write assembly language program using macro.
7 Program to reject negative numbers from a series of bytes.
Experiments Are Based On 8051 Microcontroller using MCU8051 IDE
8 Perform Arithmetic operations on 8-bit numbers in assembly language programming
using 8051 microcontroller.
9 Program to toggle the LED
10 Programming and interfacing of traffic light logic.
11 Program to generate square wave using interrupts.
12 Programming and interfacing of the key pad matrix.
13 Programming and interfacing of seven-segment display.
14 Programming and interfacing of the LCD.
15 Programming and interfacing of the relay.
16 Programming and interfacing of the dc/Stepper motor.
Introduction to MASM Assembler:
The main advantage of machine language programming is that the memory control is directly in the hands
of the programmer enabling him to manage the memory of the system more efficiently. However, there are
more disadvantages. The programming, coding and resource management techniques are tedious. As the
programmer has to consider all these functions, the chances of human errors are more. To understand the
programs one has to have a thorough technical knowledge o the processor architecture and instruction set.
The assembly language programming is simpler as compared to the machine language programming. The
instruction mnemonics are directly written in the assembly language programs. The advantage that
assembly language has over machine language is that now the address values and the constants can be
identified by labels. If the labels are clear then certainly the program will become more understandable,
and each time the programmer will not have to remember the different constants and the addresses at
which they are stored, throughout the programs.
An assembler is a program that converts an assembly language input file also called as source file to an
object file that can further be converted into machine codes or an executable file using a linker. It decides
the address of each label and substitutes the values for each of the constants and variables. Two types of
assemblers are available, one is MASM (Microsoft Macro Assembler) and TASM (Turbo Assembler).
MASM is the popular assemblers used along with a LINK program to structure the codes generated by
MASM in the form of an executable file.
While writing a program for an assembler, the first step will be to use a text editor and type the program.
Before quit the editor program, do not forget to save it. A number of text editors are available in the
market, e.g. Norton's Editor [NE}, Turbo C [TC], EDLIN, etc. Thus for writing a program in assembly
language, one will need editor, MASM assembler, linker and DEBUG utility of DOS.
The main task of any assembler program is to accept the text_assembly language program file as an input
and prepare an object file. The MASM accepts the file names only with the extension .ASM. Even if a
filename without any extension is given as input, it provides an .ASM extension to it.
or
If the program contains syntax errors, they are displayed using error code number and the corresponding
line number at which they appear. Once these syntax errors and warnings are taken care of by the
programmer, the assembly process is completed successfully.
The DOS linking program LINK.EXE links the different object modules of a source program and function
library routines to generate an integrated executable code of the source program. The main input to the
linker is the .OBJ file that contains the object modules of the source programs.
The output of the LINK program is an executable file with the entered filename and .EXE extension. This
executable filename can further be enterd at the DOS prompt to execute the file.
DEBUG.COM is a DOS utility that facilitaes the debugging and trouble-shooting of assembly language
programs.
The DEBUG offers a good platform for trouble shooting, executing and observing the results of the
assembly language programs.
-F SEG:OFFSET1 OFFSET2 BYTE1, Fill the memory area as abpve with the
BYTE2, BYTE3<ENTER> sequence BYTE1, BYTE2, BYTE3, ETC.
5 c:\masm name_of_file.asm
c:\debug name_of_file.exe
Type “t”
Single step execution of program will takes place
Experiment No-1
AIM: Write an ALP of 8086 microprocessor using MASM IDE for accessing data using:
(i) Immediate Addressing Mode (ii) Direct Addressing Mode (iii) Register Addressing Mode (iv)
Register Indirect Addressing Mode
APPARATURS:
1. PC with windows
2. MASM software
PROGRAM:
CODE SEGMENT
HLT
CODE ENDS
END START
END
RESULTS:
CONCLUSION:
2. Direct Addressing Mode
PROGRAM:
DATA SEGMENT
N1 DB 34H, 56H
DATA ENDS
CODE SEGMENT
MOV DS, AX
HLT
CODE ENDS
END START
END
RESULTS:
CONCLUSION:
3. Register Addressing Mode
PROGRAM:
CODE SEGMENT
MOV BX, AX
MOV CX, AX
MOV DL, AH
MOV DH, AL
HLT
CODE ENDS
END START
END
RESULTS:
CONCLUSION:
4. Register Indirect Addressing Mode
PROGRAM:
DATA SEGMENT
N1 DB 38H
DATA ENDS
CODE SEGMENT
MOV DS, AX
HLT
CODE ENDS
END START
END
RESULTS:
CONCLUSION:
Experiment No-2
AIM: To write an Assembly language program for addition of two 16-bit numbers.
APPARATURS:
2. MASM software
THEORY:
ADD/ADC Instruction:
These instructions add a number from source to a number from destination and put the result in the destination.
The ADC, instruction also adds the status of carry flag into the result. The source may be an immediate number, a
register, or a memory location. The source and the destination in an instruction cannot both be memory locations.
The source and destination both must be a word or byte.
PROGRAM:
DATA SEGMENT
NUM1 DW 3423H
NUM2 DW 6789H
DATA ENDS
CODE SEGMENT
MOV DS,AX
MOV AX,NUM1
MOV BX,NUM2
XOR CX,CX
ADD AX,BX
ADC CX,0000H
MOV [RESULT],AX
MOV [RESULT+2],CX
HLT
CODE ENDS
END START
RESULTS:
Input
Output
CONCLUSION:
(b) Division of 16/8 bit numbers
APPARATURS:
2. MASM software
THEORY:
DIV Instruction:
This instruction is used to divide an unsigned word by a byte or to divide an unsigned double word by a word.
When dividing a word by a byte, the word must be in AX register. After the division AL will contain an 8-bit
quotient and AH will contain an 8-bit remainder. If an attempt is made to divide by 0 or the quotient is too large to
fit in AL, the 8086 will automatically execute a type 0 interrupt.
When a double word is divided by a word, the most significant word of the double word must be in DX and the
least-significant word must be in AX. After the division AX will contain a 16-bit quotient and DX will contain a 16-bit
quotient and DX will contain a 16-bit remainder.
PROGRAM:
DATA SEGMENT
OPR1 DB 12H
OPR2 DW 0156H
DATA ENDS
CODE SEGMENT
MOV DS,AX
MOV BL,OPR1
MOV [RESULT], AX
HLT
CODE ENDS
END START
RESULT:
Input
Output
CONCLUSION:
Experiment No-3
AIM: Write an ALP of 8086 microprocessor to transfer five bytes from one memory location to another using string
instruction. Use assembler directives to write the program.
APPARATURS:
1. PC with windows
2. MASM software
PROGRAM:
DATA SEGMENT
TRANSFER DB ?
DATA ENDS
CODE SEGMENT
MOV DS, AX
MOV ES, AX
REP MOVSB
HLT
CODE ENDS
END START
END
RESULTS:
CONCLUSION:
Experiment No-4
AIM: Write an ALP of 8086 microprocessor to convert a packed BCD to ASCII number
APPARATURS:
1. PC with windows
2. MASM software
PROGRAM:
DATA SEGMENT
N1 DB 45H
RESULT DB ?
DATA ENDS
CODE SEGMENT
MOV DS,AX
MOV SI,OFFSET N1
MOV BL,[SI]
MOV BH,BL
AND BL,0FH
AND BH,0F0H
MOV CL,04H
ROL BH,CL
ADD BX,3030H
MOV [DI],BX
HLT
CODE ENDS
END START
END
RESULTS:
CONCLUSION:
Experiment No-5
APPARATURS:
1. PC with windows
2. MASM software
THEORY:
Whenever to use a group of instructions several times throughout a program, there are two ways that can
avoid having to write the group of instructions each time to use them. One way is to write the group of
instructions as a separate procedure. Then just CALL the procedure whenever to execute that group of
instructions. For calling the procedure, have to store the return address onto the stack. This process takes
some time. If group of instructions is big enough then this overhead time is negligible with respect to
execution time. But if the group of instructions is too short, the overhead time and execution time are
comparable. In such cases, it is not desirable to write procedures. For these cases, the macros can be used.
The type of procedure depends on where the procedure is stored in the memory. If it is in the same code
segment where the main program is stored then it is called near procedure otherwise it is referred to as
far procedure. For near procedure CALL instruction pushes only IP register contents on to the stack, since
CS register contents remain unchanged for main program and procedure. But far procedure CALL
instruction pushes both IP and CS on the stack.
PROGRAM:
DATA SEGMENT
NUM1 DW 5678H
NUM2 DW 1234H
DATA ENDS
CODE SEGMENT
MOV DS,AX
CALL XYZ
ADD AX,BX
MOV RESULT,AX
CALL XYZ
SUB AX,BX
MOV RESULT+02H,AX
HLT
XYZ PROC
MOV AX,NUM1
MOV BX,NUM2
RET
XYZ ENDP
CODE ENDS
END START
RESULTS:
Input
Output
CONCLUSION:
Experiment No-6
APPARATURS:
1. PC with windows
2. MASM software
THEORY:
Macro is a group of instructions. The macro assembler generates the code in the program each time where
the macro is called. Macro can be defined by MACRO and ENDM assembler directives.
It is important to note that macro sequences execute faster than procedures because there are no CALL and
RET instructions to execute.
Procedure Macro
Accessed by CALL and RET instruction during Accessed during assembly with name given to macro
program execution. when defined.
Machine code for instructions is put only Machine code is generated for instructions each time
once in the memory. when macro is called.
With procedures less memory is required. With macros more memory is required.
Parameters can be passed in registers, Parameters passed as part of statement which calls
memory locations or stack. macro.
PROGRAM:
DATA SEGMENT
NUM1 DW 5678H
NUM2 DW 1234H
CODE SEGMENT
MOV DS,AX
XYZ MACRO
MOV AX,NUM1
MOV BX,NUM2
ENDM
XYZ
ADD AX,BX
MOV RES,AX
XYZ
SUB AX,BX
MOV RES+04H,AX
HLT
CODE ENDS
END START
RESULTS:
Input
Output
CONCLUSION:
Experiment No-7
AIM: Write an ALP of 8086 microprocessor to reject negative numbers from a series of five bytes and store the
positive numbers in memory
APPARATURS:
1. PC with windows
2. MASM software
PROGRAM:
DATA SEGMENT
RESULT DB ?
DATA ENDS
CODE SEGMENT
MOV DS, AX
MOV CX,0005H
ROL AL,01H
JC REJECT
ROR AL,01H
MOV [DI],AL
INC DI
REJECT: INC SI
LOOP REPEAT
HLT
CODE ENDS
END START
END
RESULTS:
Memory location
1st Number
2nd Number
3rd Number
4th Number
5th Number
Memory location
1st Number
2nd Number
3rd Number
4th Number
5th Number
CONCLUSION:
Experiment No-8
APPARATURS:
1. PC with windows
2. MCU8051
3. Development Board
(a) PROGRAM:
Multiplication of two 8-bit numbers stored in internal RAM memory location 30H and 31H and
store the result at 40H.
ORG 0000h
MOV R0,#30H
MOV R1,#40H
MOV A,@R0
INC R0
MOV B,@R0
MUL AB
MOV @R1,A
INC R1
MOV @R1,B
END
RESULT:
Data Set
Source
30H
31H
Destination
40H
Data Set
Destination
40H
CONCLUSION:
(b) PROGRAM:
Subtract two 8-bit numbers stored in internal RAM memory location 30H and 31H.
ORG 0000h
MOV R0,#30H
MOV A,@R0
INC R0
SUBB A,@R0
END
RESULT:
Data Set-1
Before of Program
Source
30H
31H
Data Set-2
Before of Program
Source
30H
31H
CONCLUSION:
Experiment No-9
AIM: Write a program for 8051 microcontroller to toggle a LED connected at P1.0 pin.
APPARATURS:
1. PC with windows
2. MCU8051
3. Development Board
PROGRAM:
ORG 0000H
REPEAT:
SETB P1.0
LCALL DELAY
CLR P1.0
LCALL DELAY
SJMP REPEAT
ORG 0030H
DJNZ R0, B2
RET
END
CONCLUSION:
Experiment No-10
APPARATURS:
1. PC with windows
2. MCU8051
3. Development Board
Program
The traffic light logic can be observed at P0.0 pin, P0.1 pin and P0.2 pin. Let Red LED is connected at P0.0,
Yellow LED is connected at P0.1 and Green LED is connected at P0.2. Red and LED is ON for 15 seconds and
Yellow LED is ON for 5 seconds.
ORG 0000H
REPEAT:
LCALL DELAY10SEC
LCALL DELAY5SEC
LCALL DELAY10SEC
LCALL DELAY5SEC
SJMP REPEAT
ORG 0030H
MOV R0,#200D
MOV TL1,#0FDH
SETB TR1
CLR TR1
CLR TF1
DJNZ R0,L1
RET
ORG 0090H
MOV R0,#100D
MOV TL1,#0FDH
SETB TR1
CLR TR1
CLR TF1
DJNZ R0,L2
RET
END
CONCLUSION:
Experiment No-11
AIM: Write an ALP for 8051 microcontroller to generate square wave using interrupts.
APPARATURS:
1. PC with windows
2. MCU8051
Program
ORG 0000H
LJMP MAIN
ORG 001BH
LJMP ISR
ORG 0300
MOV IE,#10001000B
MOV TH1,#0FFH
MOV TL1,#0F0H
MOV R0,#02H
SETB TR1
ORG 0400
CLR TR1
DJNZ R0,AHEAD
MOV R0,#02H
CPL P2.0
AHEAD: MOV TH1,#0FFH
MOV TL1,#0F0H
SETB TR1
RETI
END
CONCLUSION:
Experiment No-12
APPARATURS:
1. PC with windows
2. MCU8051
INTERFACING DIAGRAM:
Fig. 1: Interfacing of 3x3 key matrix with 8051 Fig. 2: Interfacing of CC 7-Segment Display with 8051
Instruction for Execution: Execute in single step execution mode by pressing F7 key every time.
PROGRAM:
ORG 0000H
MOV P1,#00H
SCAN:
COL_1:
MOV P1,#11111110B
JNB P0.0,ONE
MOV P1,#11111101B
JNB P0.0,FOUR
MOV P1,#11111011B
JNB P0.0,SEVEN
COL_2:
MOV P1,#11111110B
JNB P0.1,TWO
MOV P1,#11111101B
JNB P0.1,FIVE
MOV P1,#11111011B
JNB P0.1,EIGHT
COL_3:
MOV P1,#11111110B
JNB P0.2,THREE
MOV P1,#11111101B
JNB P0.2,SIX
MOV P1,#11111011B
JNB P0.2,NINE
SJMP REP
SJMP REP
SJMP REP
SJMP REP
SJMP REP
SJMP REP
SJMP REP
SJMP REP
NINE: MOV P2,#67H ;Control word to display 9
SJMP REP
ORG 0100h
MOV TH1,#00H
MOV TL1,#00H
SETB TR1
CLR TF1
RET
END
CONCLUSION:
Experiment No-13
AIM: Interface 8051 microcontroller with a common cathode Seven segment display and develop an ALP to display
numbers from 0 to 9
APPARATURS:
1. PC with windows
2. MCU8051
3. Development Board
Develop the control words to display numbers from 0 to 9 in a common cathode Seven segment display
INTERFACING DIAGRAM:
ORG 0000h
LCALL DELAY
LCALL DELAY
LCALL DELAY
LCALL DELAY
LCALL DELAY
LCALL DELAY
LCALL DELAY
LCALL DELAY
LCALL DELAY
LCALL DELAY
SETB TR1
CLR TR1
CLR TF1
RET
END
CONCLUSION:
Experiment No-14
AIM: Interfacing of LCD with 8051 microcontroller and display the message.
APPARATURS:
1. PC with windows
2. MCU8051
3. Development Board
PROGRAM:
ORG 0000H
LCALL COMANDWR1
LCALL DATAWR1
LCALL COMANDWR2
LCALL DATAWR2
ORG 0020H
REP1: CLR A
MOVC A,@A+DPTR
JZ LAST1
MOV P1,A
LCALL DELAY
CLR P0.7
INC DPTR
SJMP REP1
LAST1: RET
ORG 0050H
REP2: CLR A
MOVC A,@A+DPTR
JZ LAST2
MOV P1,A
LCALL DELAY
CLR P0.7
INC DPTR
SJMP REP2
LAST2: RET
ORG 0080H
REP3: CLR A
MOVC A,@A+DPTR
JZ LAST3
MOV P1,A
CLR P0.6
SETB P0.7
LCALL DELAY
CLR P0.7
INC DPTR
SJMP REP3
LAST3: RET
ORG 00B0H
REP4: CLR A
MOVC A,@A+DPTR
JZ LAST4
MOV P1,A
SETB P0.6
SETB P0.7
LCALL DELAY
CLR P0.7
INC DPTR
SJMP REP4
LAST4: RET
ORG 00E0H
COMMANDWORD1: DB 38H,0FH,80H,00H
ORG 00F0H
ORG 0200H
COMMANDWORD2: DB 38H,0FH,0C0H,00H
ORG 0110H
ORG 0130H
RET
END
CONCLUSION:
Experiment No-15
AIM: Interfacing of a dc motor with 8051 microcontroller and rotate it in clockwise and anti-clockwise direction.
APPARATURS:
1. PC with windows
2. MCU8051
3. Development Board
PROGRAM:
ORG 0000H
REPEAT:
SETB P1.2
CLR P1.3
LCALL DELAY1
CLR P1.2
LCALL DELAY2
CLR P1.2
SETB P1.3
LCALL DELAY1
CLR P1.3
LCALL DELAY2
SJMP REPEAT
ORG 0030H
MOV R0,#200D
L1: MOV TH1,#4BH
MOV TL1,#0FDH
SETB TR1
CLR TR1
CLR TF1
DJNZ R0,L1
RET
ORG 0070H
MOV R0,#100D
MOV TL1,#0FDH
SETB TR1
CLR TR1
CLR TF1
DJNZ R0,L2
RET
END
CONCLUSION:
Experiment No-16
APPARATURS:
1. PC with windows
2. MCU8051
3. Development Board
PROGRAM:
ORG 0000H
REPEAT:
SETB P3.4
LCALL DELAY
CLR P3.4
LCALL DELAY
SJMP REPEAT
ORG 0030H
DJNZ R0, B2
RET
END
CONCLUSION: