You are on page 1of 34

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
Scanned by CamScanner
i~. M=”-51 PROGRAMMER’SGUIDE AND INSTRUCTION SET

M=@-51 INSTRUCTION SET


Table 10.8051 Inatruotion Set Summary

Interrupt ResponseTime: Refer to Hardware De- Oaeilfstor


Mnemonic Dsseription
scription Chapter. ‘m Period
Instructions that Affect Flag Settings(l) ---
ADD
.-
A,Rn
.
Ma registerto 1 12
Instruetkm Ffsg Inetmetion Flsg Accumulator
C OV AC C OV AC ADD A,direct Adddirectbyteto 2 12
ADD xx X CLRC o Accumulator
ADDC xx X CPLC x ADD A,@Ri Addindirect
RAM 1 12
SUBB xx X ANLC,bit X toAccumulator
MUL ox ANLC,/bit X ADD A,#date Addimmediate 2 12
DIV ox ORLC,bit X dateto
DA x ORLC,bit X Accumulator
RRC x MOVC,bit X ADDC A,Rn Addregister
to 1 12
RLC x CJNE x Accumulator
SETBC 1 withCarry
(l)FJotethat operationson SFR byte address 208or ADDC A,dirsct Adddirectbyteto 2 12
bit addresses 209-215(i.e., the PSW or bits in the Accumulator
PSW) will also afect flag settings. withCarry
ADDC A.@Ri Addindirect 1 12
Nota on inetruetionsat and ad&aesingmodes: RAMto
Rn — Register R7-RO of the currently se- Accumulator
lectedRegister Bank. withCarry
direct — 8-bit internal data location’s address. ADDC A,#date Addimmediate 2 12
This could been Internal Dsta RAM datetoAcc
locetion (0-127) or a SFR [i.e., I/O withCeny
pofi control register, status register, SUBB A,Rn Subtract
Register 1 12
etc. (128-255)]. fromAcewith
@Ri — 8-bit internal data RAM location (O- borrow
255)addreasedindirectly through reg- SUBB A,direct Subtrectdirect 2 12
ister R1 or RO. bytefromAcc
#data — 8-bitco~~t includedin instruction. withborrow
#data 16— 16-bitconstant includedin instmction. SUBB A.@Ri Subfrectindiract 1 12
addr 16 — 16-bit destination address. Used by RAMfromACC
LCALL & LJMP. A branch can be withborrow
anywhere within the 64K-byte Pro- A.#date Subtract 2 12
gram Memory SddR$S SpCCe. immediatedate
addr 1 — n-bit destination sddrrss. Used by fromAccwith
ACALL& AJMP. The branch willbe borrw
within the same 2K-byte page of pro- INC A Increment 1 12
gram memo~ as the first byte of the Accumulator
foil-g instruction. INC Rn Incrsmsnt
register 1 12
rel — Signed(two’scomplement)S-bitoffset INC direct Increment direct 2 12
byte.Usedby SJMP end all condition- byte
al jumps. Range is -128 to + 127 INC @Ri Incrementdirect 1 12
bytes relative to first byte of the fol- RAM
lowinginstruction. DEC A Decrement 1 12
bit — Direct Addressedbit in Internal Data Accumulator
W or SpecialFunction Register. DEC Rn Decrement 1 12
Regieter
DEC direct Decrement direct 2 12
byte
DEC @Ri Decrement 1 12
indirect
RAM
WImnemonics
copyrighted
@lntelCor’pxetion
1980

.
2-21
i~e McS@-51PROGRAMMER’SGUIDE AND INSTRUCTION SET

Table 10.8051 Inetruotion Sat Summary (Continued)


~we o:acw~r
Mnemonic Deaoription

tRITNWTIC OPERATIONS (Continued)


.LUUIGAL
------ urtm
----------
IIUNS {wmunuao)
,A . . ,.

NC DPTR Increment Date 1 24 RL A 1 12


Pointer Accumulator Left
dUL AB MultiPiy
A& B 1 48 RLC A Rotate 1 12
)IV AB Ditie A byB 1 48 Accumulator Left
)A A DecimelAdjuet 1 12 through theCarry
Accumulator RR A Rotate 1 12
.OGICALOPERATtONS Accumulator
\NL A,Rn ANDRegieterto 1 12 Right
Accumulator RRC A Rotate 1 12
tNL A,direct ANDdiractbyte 2 12 Accumulator
toAccumulator Rightthrough
4NL A,@Ri ANDindirect 1 12 mecerry
RAMto SWAP A Swapnibbles 1 12
Accumulator withinthe
4NL A,#date ANDimmediate 2 12 Accumulator
datato DATATRANSFER
Accumulator MOV A,Rn Move 1 12
4NL direct,A ANDAccumulator 2 12 register
to
todirectbyte Accumulator
4NL diract,#data ANDimmediate 3 24 MOV A,direct Movediract 2 12
datatodirectbyte byteto
)RL A,Rn ORregister to 1 12 Accumulator
Accumulator MOV A,@Ri Moveindirect 1 12
2RL A,direct ORdirectbyteto 2 12 RAMto
Accumulator Accumulator
2RL A,@Ri ORindiractRAM 1 12 MOV A,#date Move 2 12
toAccumulator immediate
3RL A,#date ORimmediate 2 12 dateto
datato Accumulator
Accumulator MOV Rn.A Move 1 12
3RL dirac4,A ORAccumulator 2 12 Accumulator
todirectbyte toregister
3RL dirsct,~date ORimmediate 3 24 MOV Rn,direot Movedirect 2 24
detetodiractbyte byteto
KRL A,Rn Excluaiva-OR 1 12 register
regieterto MOV Rn,#date Move 2 12
Armmulator immediate date
I(RL A,diraot ExclusMe-OR 2 12 toregister
directbyteto MOV direct,A Mova 2 12
Accumulator Accumulator
KRL A,@Ri Exclush/e-OR 1 12 todirectbyte
indirect
RAMto MOV direct,Rn Moveregister 2 24
Accumulator todirectbyte
KRL A,#data Exclusiva-OR 2 12 MOV diract,directMovedirect 3 24
immediate datato bytatodiract
Accumulator MOV direct,@Ri Moveindirect 2 24
KRL direct,A Excluaive-OR 2 12 RAMto
Accumulator to directbyte
directbyte MOV direct,#date Move 3 24
KRL direct,gdata Exclueive-OR 3 24 immediate data
immediate date todireotbyte
todirectbyte MOV @Ri,A Move 1 12
CLR A Clear 1 12 Accumulator to
Accumulate
Complement 1 12
I indirect
RAM
CPL A Allmnemonics
copyrighted@lnteiCorporation
19S0
Accumulator
.2-22
in~. M=”-51 PROGRAMMER’S GUIDE AND INSTRUCTION SET

Table 10.8051 Instruction Set Summary(Continued)

I Mnemonic OeecriptfonByte ~~k~o’ Mnemonic Description Byte


Oeciltetor
Period
IDATATRANSFER (continued) BOOLEAN VARIABLEMANIPULATION
MOV @Ri,direct Movedirect 2 24 GLH L wearwny 1 12
byteto CLR bit Clesrdirectbit 2 12
indirect RAM SETB c SetCarry 1 12
MOV @Ri,#date Move 2 12 bit Setdirectbit 2 12
immediate CPL c Complement 1 12
dateto carry
indirect RAM CPL bit Complement 2 12
MOV DPTR,#data16LoedDets 3 24 directbit
Pointerwitha ANL C,bit ANDdirectbit 2 24
16-bitconstant toCARRY
MOVC A,@A+DPTR MoveMe 1 24 ANL C,/bit ANDcomplement 2 24
byterelativeto ofdirectbit
DPTRtoAcc tocarry
MOVC A,@A+PC MoveCode 1 24 ORL C,bit ORdirectbit 2 24
byterelativeto tocarry
PCtoAcc ORL C,/bit ORcomplement 2 24
MOVX A,@Ri Move 1 24 ofdirectbit
External tocarry
RAM(8-bit MOV C,bit Movedirectbit 2 12
eddr)toAcc tocarry
MOVX A,@DPTR Move 1 24 MOV bit,C MoveCsrryto 2 24
External directbit
RAM(l&bit JC rel JumpifCsny 2 24
addr)toAcc isset
MOVX @Ri,A MoveAccto 1 24 JNC rel JumpifCarry 2 24
External RAM notset
(8-bitaddr) JB bit,rel Jumpifdirecf 3 24
MOVX @DPTR,A MoveAccto 1 24 Bitisset
External RAM JNB bi$rel Jumpifdirect 3 24
(lS-bitaddr) BitisNotset
PUSH direct Pushdirect 2 24 JBC bit.rel Jumoifdirect 3 24
byteonto Bitisset&
stack clearbit
POP direct Popdirect 2 24 PROGRAMBRANCHING
bytefrom ACALL addrl1 Absolute 2 24
stack Subroutine
XCH A,Rn Exchange 1 12 call
registerwith LCALL addr16 Long 3 24
Subroutine
XCH A,direct Exchange 2 12 call
directbyte RET Returnfrom 1 24
with Subroutine
RETI Retumfrom 1 24
XCH A,@Ri Exchange 1 12 intempt
indirect
RAM AJMP addrll Absolute 2 24
with Jump
WMP addr16 LongJump 3 24
XCHD A,@Ri Exchange low- 1 12 SJMP rel ShortJumo 2 24
orderDigif (relativeaddr)
indirect
RAM VImnemonicscopyrigMed @lntelCorporation
1980
with Acc
I

2-23
int# MCS@-51PROGRAMMER’S GUIDE AND INSTRUCTION SET

Table 10.8051 Instruction Set SummarY (Continued)

Mnemonic Description Byte ‘~or Mnemonic Description Syte ~~or


.FmWrIANI
. . . . . .. BmANGmNQ
-m . ..-,,,..- ,-- —.,....
(wnunueq
.’,
PROGRAM BRANCHING (Continued)
JMP @A+DPTR Jumpindirecf 1 24 CJNE Rn,#date,rei Compare 3 24
relativetothe immediate to
DPTR register
and
JZ rel Jumpif 2 24 JumpifNot
Accumulator Equal
isZero CJNE @Ri,#data,rel Compare 3 24
JNZ rel Jumpif 2 24 immediate to
Accumulator indirect
and
isNotZero JumpifNot
CJNE A,direct,rei Compare 3 24 Equal
directbyteto DJNZ Rn,rei Decrement 2 24
AccandJump registerand
ifNotEquai JumpifNot
CJNE A,#date,rel Compare 3 24 Zero
immediate to DJNZ direct,rel Decrement 3 24
AccandJumo directbyte
ifNotEqual andJumpif
NotZero
NOP NoOperation 1 12
dlmnemonics
copyrighted @intelCorporation
1980

2-24
DEPT. OF ELECTRICAL & ELECTRONICS ENGINEERING

EXPERIMENTS ON MICROCONTROLLER (8051) KITS:-

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:-

RGMCET 2/16 MP LAB MANUAL


DEPT. OF ELECTRICAL & ELECTRONICS ENGINEERING

To perform subtraction 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
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

8051 Microcontroller Kit

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:-

2. 1’s & 2’s COMPLEMENT


AIM:-
To perform 1’s and 2’s Complement of 8-bit hex number stored in memory
location and store the result in the next memory location.

APPARATUS:-
8051 Microcontroller Kit

RGMCET 5/16 MP LAB MANUAL


DEPT. OF ELECTRICAL & ELECTRONICS ENGINEERING

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

Output: [9001h] = (1’s COMPLEMENT)

[9002h] = (2’s COMPLEMENT)

RESULT:-

3. ASCII TO DECIMAL CONVERSION


AIM:-
To convert the ASCII number in the accumulator to its equivalent Decimal
number.

APPARATUS:-
8051 Microcontroller Kit

RGMCET 6/16 MP LAB MANUAL


DEPT. OF ELECTRICAL & ELECTRONICS ENGINEERING

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:-

4. HEX TO DECIMAL CONVERSION


AIM:-
To obtain the Decimal equivalent of an 8-bit Hex number stored in memory.

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:-

6. LARGEST ELEMENT IN AN ARRAY


AIM:-
To find the biggest number in an array of 8-bit unsigned numbers of
predetermined order.

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

RGMCET 9/16 MP LAB MANUAL


DEPT. OF ELECTRICAL & ELECTRONICS ENGINEERING

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:-

RGMCET 10/16 MP LAB MANUAL


DEPT. OF ELECTRICAL & ELECTRONICS ENGINEERING

ASCENDING ORDER OF AN ARRAY


AIM:-
To arrange an array of 8-bit unsigned numbers in ascending order.

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:-

RGMCET 12/16 MP LAB MANUAL


DEPT. OF ELECTRICAL & ELECTRONICS ENGINEERING

Question’s can be asked at viva voce:-

1. Who has introduced MCS-51 family of microcontrollers?

2. MCS-51 family of microcontrollers contains which ICs?

3. What is the difference between MP and MC?

4. Give any Example of Microcontrollers?

5. Is 8051 an 8-bit controller?

6. Why 8051 is an 8-bit controller?

7. What is the on chip ROM capacity of 8051?

8. What is the on chip RAM capacity of 8051?

9. How many IO ports are available on 8051 on chip?

10. How many timers are available on 8051 on chip?

11. Which version of 8051 doesn’t have on chip ROM?

12. Which version of 8051 contains EPROM on chip?

13. 8051 contains which type of ROM?


RGMCET 13/16 MP LAB MANUAL
DEPT. OF ELECTRICAL & ELECTRONICS ENGINEERING

14. What is the purpose of ROM in 8051?

15. What is the purpose of RAM in 8051?

16. Whether ROM is accessible randomly or not?

17. What is the capacity of on chip EPROM on 8751?

18. Can you connect external program memory to 8051?

19. Can you connect external data memory to 8051?

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?

22. How can you access internal program memory?

23. How can you access external program memory?

24. How is it possible to access both internal & external ROM using PC?

25. How can you access internal data memory?

26. How can you access external data memory?

RGMCET 14/16 MP LAB MANUAL


DEPT. OF ELECTRICAL & ELECTRONICS ENGINEERING

27. Do you require any signal to access external data memory?

28. Do you require any signal to access external program memory?

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?

31. Expand DPTR?

32. Is a DPTR an 8-bit register?

33. Can we access PC as two 8-bit registers?

34. Is there any register in 8086 similar to PC in 8051?

35. Expand SFR?

36. Is PC a special function register?

37. Whether external interrupts are edge triggered or level triggered type?

38. Expand ALE?

39. Expand PSEN?

RGMCET 15/16 MP LAB MANUAL


DEPT. OF ELECTRICAL & ELECTRONICS ENGINEERING

40. What is the function of PSEN pin?

41. For serial communication the pins of which IO port is used?

42. Which register is used to operate 8051 in different modes?

43. What are the modes of operation of 8051?

44. Whether PCON is a bit addressable SFR?

45. Which port will hold the higher order address information during memory access?

46. Which Io port of 8051 doesn’t have dual function?

47. What is the Architecture of 8051?

48. What is stack?

49. What is the function of SP register?

50. The number of clock cycles in one machine cycle of 8051 is?

RGMCET 16/16 MP LAB MANUAL

You might also like