Professional Documents
Culture Documents
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
i~. M=”-51 PROGRAMMER’SGUIDE AND INSTRUCTION SET
.
2-21
i~e McS@-51PROGRAMMER’SGUIDE AND INSTRUCTION SET
2-23
int# MCS@-51PROGRAMMER’S GUIDE AND INSTRUCTION SET
2-24
DEPT. OF ELECTRICAL & ELECTRONICS ENGINEERING
1. ARITHMETIC OPERATIONS
1.1 ADDITION
AIM:-
To perform addition of two 8-bit hex numbers stored in consecutive memory
locations and store the result in the next memory location.
APPARATUS:-
8051 Microcontroller Kit
THEORY:-
The program is to add the 8-bit numbers stored at [9000h] and [9001h] using
ADD instruction, and store the result at [9002h].
PROGRAM:-
Hexadecimal Instruction
Address Opcode Label Mnemonic Operands Comments
4100 CLC C ;Clear carry flag
MOV DPTR,#9000
MOVX A,@DPTR
MOV B,A ;First data in B
INC DPTR
MOVX A,@DPTR ;Second data in A
ADD A,B ;sum in A
INC DPTR
MOVX @DPTR,A ;Result in [9002h]
END: SJMP END ;Halt
PROCEDURE:-
1. Enter the opcodes from [4100h] and data from [9000h].
2. Execute the program.
3. Check for the result at [9002h].
4. Change the data and see if the result at [9002h] changes accordingly.
OBSERVATIONS:-
Input: [9000h] =
[9001h] =
Output: [9002h] =
RESULT:-
16-BIT ADDITION
RGMCET 1/16 MP LAB MANUAL
DEPT. OF ELECTRICAL & ELECTRONICS ENGINEERING
AIM:-
To perform addition of two 16-bit hex numbers using immediate addressing
and store the result in memory location.
APPARATUS:-
8051 Microcontroller Kit
THEORY:-
As there is only one 16-bit register in 8051, 16-bit addition is performed by
using ADDC instruction twice, i.e. adding MSB first and LSB next.
PROGRAM:-
Hexadecimal Instruction
Address Opcode Label Mnemonic Operands Comments
4200 CLC C ;Clear carry flag
MOV A,#LSB1
ADDC A,#LSB2
MOV DPTR,#9000 ;First data in B
MOVX @DPTR,A
MOV A,#MSB1 ;Second data in A
ADDC A,#MSB2 ;sum in A
INC DPTR
MOVX @DPTR,A ;Result in [9002h]
END: SJMP END ;Halt
PROCEDURE:-
1. Enter the opcodes from [4200H].
2. Execute the program.
3. Check for the result at [9000H] and [9001H].
OBSERVATIONS: -
Example: DATA1 = 1234H
DATA2 = 5678H
Output: [9000h] = (LSB)
[9001h] = MSB)
RESULT:-
.3 SUBTRACTION
AIM:-
APPARATUS:-
8051 Microcontroller Kit
THEORY:-
The program is to add the 8-bit numbers stored at [9000h] and [9001h] using
SUBB instruction, and store the result at [9002h].
PROGRAM:-
Hexadecimal Instruction
Address Opcode Label Mnemonic Operands Comments
4300 CLC C ;Clear carry flag
MOV DPTR,#9000
MOVX A,@DPTR
MOV B,A ;Second data in B
INC DPTR
MOVX A,@DPTR ;First data in A
SUBB A,B ;Difference in A
INC DPTR
MOVX @DPTR,A ;Result in [9002h]
END: SJMP END ;Halt
PROCEDURE:-
1. Enter the opcodes from [4300h] and data from [9000h].
2. Execute the program.
3. Check for the result at [9002h].
4. Change the data and see if the result at [9002h] changes accordingly.
OBSERVATIONS:-
Input: [9000h] = 34h
[9001h] = 46h
Output: [9002h] = 12h
RESULT:-
1.4 MULTIPLICATION
AIM:-
To perform multiplication of two 8-bit hex numbers stored in consecutive
memory locations and store the result in the next memory location.
RGMCET 3/16 MP LAB MANUAL
DEPT. OF ELECTRICAL & ELECTRONICS ENGINEERING
APPARATUS:-
8051 Microcontroller Kit
THEORY:-
The program is to add the 8-bit numbers stored at [9000h] and [9001h] using
MUL instruction, and store the result at [9002h] and [9003h] respectively.
PROGRAM:-
Hexadecimal Instruction
Address Opcode Label Mnemonic Operands Comments
4400 CLC C ;Clear carry flag
MOV DPTR,#9000
MOVX A,@DPTR
MOV B,A ;Second data in B
INC DPTR
MOVX A,@DPTR ;First data in A
MUL AB ;Difference in A
INC DPTR
MOVX @DPTR,A ;Result in [9002h]
MOV A,B ; and [9003h]
MOVX @DPTR,A
END: SJMP END ;Halt
PROCEDURE:-
1. Enter the opcodes from [4400h] and data from [9000h].
2. Execute the program.
3. Check for the result at [9002h] and [9003h]
4. Change the data and see if the result at [9002h] & [9003h] changes
accordingly.
OBSERVATIONS:-
Input: [9000h] = 02h
[9001h] = 04h
Output: [9002h] = 08h
[9003h] = 00h
RESULT:-
1.5 DIVISION
AIM:-
To perform multiplication of two 8-bit hex numbers stored in consecutive
memory locations and store the result in the next memory location.
APPARATUS:-
RGMCET 4/16 MP LAB MANUAL
DEPT. OF ELECTRICAL & ELECTRONICS ENGINEERING
THEORY:-
The program is to add the 8-bit numbers stored at [9000h] and [9001h] using
DIV instruction, and store the result at [9002h] and [9003h] respectively.
PROGRAM:-
Hexadecimal Instruction
Address Opcode Label Mnemonic Operands Comments
4500 CLC C ;Clear carry flag
MOV DPTR,#9000
MOVX A,@DPTR
MOV B,A ;Second data in B
INC DPTR
MOVX A,@DPTR ;First data in A
DIV AB ;Difference in A
INC DPTR
MOVX @DPTR,A ; [9002h] and
MOV A,B ;Remainder in
INC DPTR
MOVX @DPTR,A ; [9003h]
END: SJMP END ;Halt
PROCEDURE:-
1. Enter the opcodes from [4500h] and data from [9000h].
2. Execute the program.
3. Check for the result at [9002h] and [9003h]
4. Change the data and see if the result at [9002h] & [9003h] changes
accordingly.
OBSERVATIONS:-
Input: [9000h] = 34h
[9001h] = 34h
Output: [9002h] = 01h
[9003h] = 00h
RESULT:-
APPARATUS:-
8051 Microcontroller Kit
THEORY:-
The program is to find the 1’s and 2’s Complent of 8-bit hex number stored at
[9000h] using CPL and INC instructions, and store the result at [9001h] and [9002h]
respectively.
PROGRAM:-
Hexadecimal Instruction
Address Opcode Label Mnemonic Operands Comments
4600 MOV DPTR,#9000
MOVX A,@DPTR ;Data in ACC
CPL A ;1’s Complement
INC DPTR ; in [9001h]
MOVX @DPTR,A
INC A ;2’s Complement
INC DPTR ; in [9002h]
MOVX @DPTR,A
END: SJMP END ;Halt
PROCEDURE:-
1. Enter the opcodes from [4600h] and data at [9000h].
2. Execute the program.
3. Check for the result at [9001h] and [9002h]
4. Change the data and see if the result at [9001h] & [9002h] changes
accordingly.
OBSERVATIONS:-
Input: [9000h] = 12h
RESULT:-
APPARATUS:-
8051 Microcontroller Kit
THEORY:-
Conversion of an ASCII number to Decimal number is very simple because all
the decimal numbers form a sequence in ASCII. Any ASCII number can be converted
to Decimal just by subtracting 30 from it.
PROGRAM:-
Hexadecimal Instruction
Address Opcode Label Mnemonic Operands Comments
4700 MOV DPTR,#9000
MOVX A,@DPTR ;Get ASCII no.
CLR C
SUBB A,#30 ;Subtract [A] by 30
CLR C
SUBB A,#0A ;Check if the no. is
JC STR ;decimal
MOV A,#0FF ;Else store FFh
SJMP NEXT
STR: ADD A,#0A
NEXT: MOVX @DPTR,A ;Store the result
END: SJMP END ;Halt
PROCEDURE:-
1. Enter the opcodes from [4700h] and data at [9000h].
2. Execute the program.
3. Check for the result at [9000].
4. Change the data and see if the result at [9000h] changes accordingly.
OBSERVATIONS:-
Input: [9000h] = 37h [9000h] = 40h
Output: [9000h] = 07h [9000h] = FFh
RESULT:-
APPARATUS:-
8051 Microcontroller Kit
THEORY:-
The hex number to be converted is brought to the accumulator and is divided
by 100D to find hundreds in it. DIV instruction of 8051 is used in this program. The
RGMCET 7/16 MP LAB MANUAL
DEPT. OF ELECTRICAL & ELECTRONICS ENGINEERING
remainder is now divided by 10D to count the number of tens in it. Finally, the
remainder obtained from the above division gives the number of units in the given hex
number. The result is stored in memory in the unpacked form.
PROGRAM:-
Hexadecimal Instruction
Address Opcode Label Mnemonic Operands Comments
5500 MOV DPTR,#9000
MOVX A,@DPTR ;Get Hex no..
MOV B,#64
DIV AB ;Find no. of 100s
INC DPTR
MOVX @DPTR,A
MOV A,B
MOV B,#0A
DIV AB ;Find no. of 10s
INC DPTR
MOVX @DPTR,A
INC DPTR
MOV A,B
MOVX @DPTR,A ;Store no. of units
END: SJMP END ;Halt
PROCEDURE:-
1. Enter the opcodes from [5500h] and data at [9000h].
2. Execute the program.
3. Check for the result at [9001] to [9003h].
4. Change the data and see if the result at [9001h] to [9003h] changes
accordingly.
OBSERVATIONS:-
Input: [9000h] = FFh
Output: [9001h] = 02h
[9002h] = 05h
[9003h] = 05h
5. DECIMAL TO HEX CONVERSION
AIM:-
To convert BCD digits in memory to the equivalent hex number
APPARATUS:-
8051 Microcontroller Kit
THEORY:-
Considering that out of the two unpacked BCD digits at [9000h] and [9002h],
the digit at [9000h] is the MSD, the logic is to multiply this by 0A (10D) and then add
the LSD at [9002h] to the product.
PROGRAM:-
RGMCET 8/16 MP LAB MANUAL
DEPT. OF ELECTRICAL & ELECTRONICS ENGINEERING
Hexadecimal Instruction
Address Opcode Label Mnemonic Operands Comments
7000 MOV DPTR,#9000
MOVX A,@DPTR ;Get decimal no..
MOV B,#0AH
MUL AB ;A (A)*10
MOV B,A
INC DPTR
MOVX A,@DPTR
ADD A,B ;Add LSB to (B)
INC DPTR
MONX @DPTR,A ;Store the hex no.
END: SJMP END ;Halt
PROCEDURE:-
1. Enter the opcodes from [7000h] and data at [9000h].
2. Execute the program.
3. Check for the result at [9002h].
4. Change the data and see if the result at [9002h] changes accordingly.
OBSERVATIONS:-
Input: [9000h] = 03h
[9001h] = 06h
Output: [9002h] = 24h
RESULT:-
APPARATUS:-
8051 Microcontroller Kit
THEORY:-
To find the biggest number in any given array, the contents of the array must
be compared with an arbitrary biggest number. In this experiment, since all numbers
are said to be unsigned 8-bit numbers, let internal memory location (say 40h) has the
biggest number i.e. zero. Now compare the first number with internal memory
location. If it is greater, move it to internal memory location. Further comparison is
with this biggest number and this comparison is done till the end of the array. Now
the biggest number in internal memory location is stored in memory as the result.
PROGRAM:-
Hexadecimal Instruction
Address Opcode Label Mnemonic Operands Comments
7500 MOV DPTR,#9000
MOV 40h,#00 ;let biggest no as 0
MOV R5,#05 ;Array length in R5
TWO: MOVX A,@DPTR ;Get number in A
CJNE A,40h,ONE
THREE: INC DPTR
DJNZ R5,TWO ;check for n=0
MOV A,40h
MOVX @DPTR,A ;Store biggest no.
END: SJMP END
ONE: JC THREE
MOV 40h,A
SJMP THREE
PROCEDURE:-
1. Enter the opcodes from [7500h] and data at [9000h] to [9004h] .
2. Execute the program.
3. Check for the result at [9005h].
4. Change the data and see if the result at [9005h] changes accordingly.
OBSERVATIONS:-
Input: [9000h] = 56h
[9001h] = 67h
[9002h] = 76h
[9003h] = 49h
[9004h] = 98h
Output: [9005h] = 98h ;Biggest number in the array
RESULT:-
APPARATUS:-
8051 Microcontroller Kit
THEORY:-
The sorting technique used here is relatively simple. First consider the first
two numbers of the array. See if this pair of numbers is out of order. Similarly
examine successively each pair of numbers in the array. If any pair is out of order,
interchange the numbers in the pair. Perform this step for count times, count being n-1
where n=array length.
PROGRAM:-
Hexadecimal Instruction
Address Opcode Label Mnemonic Operands Comments
MOV R3,#04 ;Count n-1
MOV R4,#04
MOV DPTR,#9000
ABOVE: MOV R5,DPL ;Preserve the addr
MOV R6,DPH ;of the element
MOVX A,@DPTR ;Get the no. in A
MOV B,A
BACK: INC DPTR
MOVX A,@DPTR
MOV R0,A ;next no. in R0
CLR C
SUBB A,B ;Compare two nos.
JNC NEXT
PUSH DPL ;Exchange A & B
PUSH DPH ;contents if carry
MOV DPL,R5
MOV DPH,R6
MOV A,R0
MOVX @DPTR,A
POP DPH
POP DPL
MOV A,B
MOVX @DPTR,A
MOV B,R0
NEXT: DJNZ R3,BACK ;if n≠0 repeat steps
DEC R4
MOV A,R4
MOV R3,A
INC R4
MOV DPL,R5
MOV DPH,R6
RGMCET 11/16 MP LAB MANUAL
DEPT. OF ELECTRICAL & ELECTRONICS ENGINEERING
INC DPTR
DJNZ R4,ABOVE
END: SJMP END
PROCEDURE:-
1. Enter the opcodes from [4100h] and data at [9000h] to [9004h] .
2. Execute the program.
3. Check for the result at the same locations i.e. [9000h] to [9004h].
4. Change the data and see if the result at [9000h] to [9004h] changes
accordingly.
OBSERVATIONS:-
Input: [9000h] = 56h
[9001h] = 76h
[9002h] = 67h
[9003h] = 49h
[9004h] = 98h
Output: [9000h] = 49h
[9001h] = 56h
[9002h] = 67h
[9003h] = 76h
[9004h] = 98h
RESULT:-
20. What is the capacity of external program memory that can be connected to 8051?
21. What is the capacity of external data memory that can be connected to 8051?
24. How is it possible to access both internal & external ROM using PC?
29. What is the reason behind connecting only 64KB of external program memory?
30. What is the reason behind connecting only 64KB of external data memory?
37. Whether external interrupts are edge triggered or level triggered type?
45. Which port will hold the higher order address information during memory access?
50. The number of clock cycles in one machine cycle of 8051 is?