You are on page 1of 36

INDEX

S.No

Name of Experiment

1.

Write an ALP to add, subtract, multiply & divide of two 8 bit numbers

2.

Write an ALP to AND, OR, NOT & XOR of two 8 bit numbers

3.

Write an ALP to add of two byte number

4.

Write an ALP to subtract two byte from another two byte numbers

5.

Write an ALP to add n byte number stored in external RAM

6.

Write an ALP to move block of data bytes present in internal memory

7.

Write an ALP to move block of data bytes present in internal memory

8.

Write an ALP to move block of data bytes present in external memory

9.

Write an ALP to exchange block of data bytes present in external memory

10.

Write an ALP to illustrate hexadecimal up counter with up counter

11.

Write an ALP to illustrate hexadecimal down counter

12.

Write an ALP to illustrate decimal up counter

13.

Write an ALP to illustrate decimal down counter


Write an ALP to convert decimal number to its equivalent hexadecimal
number
Using only one pointer, R0, pack two arrays of BCD digit to create third
array

14.
15.

17.

Find the largest and smallest from N unsigned integers


Write an ALP to find largest elements in a given array present in external
memory

18.

Write an ALP to sort a given array present in external memory

19.

Write an ALP to search a byte in array of bytes

20.

Write an ALP to demonstrate call and return instruction


WAP to blink all LEDs together for 5 seconds and then all LEDs off for 5
seconds

16.

21.
22.
23.
24.

WAP to blink alternate LEDs together for 5 seconds


Develop a program so that LEDs interfaced with P1.0 blinks
continuously
Two keys and one LED are interfaced with 8051. Develop a software so
that K1 would turn the LED on and K2 would turn it off.

Page 1 of 36

Sign

Experiment:-1
1(a) Write an ALP to add, subtract, multiply & divide of two 8 bit numbers. Numbers are in resister
R1 & R2. Result of addition in register R0, subtraction in R3, borrow if any in R4, Result of
multiplication in Register R5 & R6, &Result of division , quotient in R7, Remainder in R0 of RB1.
Display all results on port 1 LED Bank with a 5 sec delay.

Code:
Address
8000

Label

Mnemonic
MOV R1,20H
MOV R2,10H

Comment
;Load 20H into R1
;Load 10H into R2

MOV A, R1

;Copy the content of R1 into A

ADD A, R2

;Add the content of R2 to content of A

MOV R0, A

;R0 = R1+R2

MOV P1,A
LCALL DELAY

;Time delay of 5 sec

MOV A, R1

;Copy the content of R1 into A

SUBB A, R2

;Subtract the content of R2 from content of A

MOV R3, A

;R3 = R1 -R2

MOV P1,A
LCALL DELAY

;Time delay of 5 sec

MOV A, R1

;Load 20H into R1

MOV B, R2

;Load 10H into R2

MUL AB
MOV R5,B
MOV R6,A
MOV P1,A
LCALL DELAY

;Time delay of 5 sec

MOV A, R1
MOV B,R2
DIV AB
MOV R7,A
MOV R0,B
MOV P1,A
LCALL DELAY

;Time delay of 5 sec

;---------------Time delay
DELAY:

MOV R6,#70

;Load 70 into R6 of RB1

HERE1:

MOV R7,#255

;Load 255 into R7 of RB1

HERE2:

MOV R1 ,#255

;Load 255 into R1 of RB1

HERE3:

DJNZ R1,HERE3
Page 2 of 36

DJNZ R7,HERE2
DJNZ R6,HERE1
Flowchart:

Page 3 of 36

1(b) Write an ALP to AND, OR, NOT & XOR of two 8 bit numbers. Numbers are in register R1 & R2.
Result of ADDING in register R0, ORING in R3, Negation in Register R4, &Result of XORING in R5.
Display all results on port 1 LED Bank with a 5 sec delay.

Code:
MOV A, R1

;Copy the content of R1 into A

ANL A, R2

;ANDING the content of R2 to content of A

MOV R0, A

;R0 = R1 AND R2

LCALL DELAY

;Time delay of 5 sec.

MOV A, R1

;Copy the content of R1 into A

ORL A, R2

;ORING the content of R2 to content of A

MOV R3, A

;R3 = R1 OR R2

LCALL DELAY

;Time delay of 5 sec

MOV A, R1

;Copy the content of R1 into A

CPL A

;1s complement

MOV R4,A

;R4 = ~R1

LCALL DELAY

;Time delay of 5 sec

MOV A, R1

;Copy the content of R1 into A

XRL A, R2

;XORING the content of R2 to content of A

MOV R5, A

;R5 = R1 XOR R2

LCALL DELAY

;Time delay of 5 sec.

;------Time delay
DELAY:

MOV R6,#70

;Load 70 into R6

HERE1:

MOV R7,#255

;Load 255 into R7

HERE2:

MOV R0 ,#255

;Load 255 into R0 of RB1

HERE3:

DJNZ R0,HERE3
DJNZ R7,HERE2
DJNZ R6,HERE1
RET
Page 4 of 36

Flowchart:

Page 5 of 36

(c) Write an ALP to add of two byte number. First two byte number are in resister R1 & R2 and
second two byte number are in resister R3 & R4. Result of addition in register R5, R6,R7. Display all
results on port 1 LED Bank with a 5 sec delay.

Code:
Address

label

8000

Mnemonic

comment

MOV R1, #12

;Load 12 into R1

MOV R2, #34

;Load 34 into R2

MOV R3, #56

;Load 56 into R3

MOV R4, #78

;Load 78 into R4

MOV R7,#00
CLR C

;3

MOV A, R1

;Copy the content of R1 into A

ADD A, R3

;Add the content of R3 to content of A

MOV R5, A

;R5 = R1+R3

rd

Byte=0

MOV P1,A
LCALL DELAY

;Time delay of 5 sec.

MOV A, R2

;Copy the content of R2 into A

ADDC A, R4

;Add the content of R4 to content of A

MOV R6, A

;R6 = R2+R4

MOV P1,A
LCALL DELAY

;Time delay of 5 sec.

JNC NEXT
MOV R7,#01
NEXT:

LCALL DELAY

;Time delay of 5 sec.

;---------------Time delay
DELAY:

MOV R6,#70

;Load 70 into R6

HERE1:

MOV R7,#255

;Load 255 into R

HERE2:

MOV R0 ,#255

;Load 255 into R0 of RB1

HERE3:

DJNZ R0,HERE3
DJNZ R7,HERE2
DJNZ R6,HERE1
RET
Page 6 of 36

Flowchart:

Page 7 of 36

1(d) Write an ALP to subtract two byte from another two byte numbers. First number is in
resister R1 & R2 and second two byte number are in Register R3 & R4. Result of subtraction
in Register R5 & R6 borrow if any in R7. Display all results on port 1 LED Bank with a 5 sec
delay.

Code:
Address

Label

8000

Mnemonic

Comment

MOV R1, #56

;Load 56 into R1

MOV R2, #78

;Load 78 into R2

MOV R3, #12

;Load 12 into R3

MOV R4, #34

;Load 34 into R4

CLR C
MOV A, R1

;Copy the content of R1 into A

SUBB A, R3

;Subtract the content of R3 to content of A

MOV R5, A

;R5 = R1 - R3

MOV P1,A
LCALL DELAY

;Time delay of 5 sec.

MOV A, R2

;Copy the content of R2 into A

SUBB A, R4

;Subtract the content of R4 to content of A

MOV R6, A

;R6 = R2-R4

MOV P1,A
LCALL DELAY

;Time delay of 5 sec.

;---------------Time delay
DELAY:

MOV R6,#70

;Load 70 into R6

HERE1:

MOV R7,#255

;Load 255 into R

HERE2:

MOV R0 ,#255

;Load 255 into R0 of RB1

HERE3:

DJNZ R0,HERE3
DJNZ R7,HERE2
DJNZ R6,HERE1
RET

Page 8 of 36

Flowchart:

Page 9 of 36

1(e) Write an ALP to add n byte number stored in external RAM (Starting address 9000 and
no of bytes is 10 or0AH). First two byte number are in resister R0 & R1 and second two byte
number are in Register R2 & R3. Result of addition in Register R4 ,R5 & R6 . Display all results
on port 1 LED Bank with a 5 sec delay.
Code:

Address

8000

Label

Mnemonic

Comment

ORG 00
MOV R0,10
MOV R1,#00
MOV DPTR,#9000
LOOP: MOVX A,@DPTR
ADD A,R1
INC DPTR
DJNZ R0,LOOP
END
ORG 00

Flowchart:

Page 10 of 36

Experiment:-2
2(a) Write an ALP to move block of data bytes present in internal memory with starting address
10H and ending address 20H to the destination memory with starting address 30H (Without
overlap).

Code:
Address
8000

Label

Mnemonic

Comment

ORG 00H
MOV R2,#10
MOV R0,#10H
MOV R1,#30H
CLR C
BACK: MOV A,@R0
MOV @R1,A
INC R0
INC R1
DJNZ R2,BACK
END

Flowchart:

Page 11 of 36

2(b) Write an ALP to move block of data bytes present in internal memory with starting
address 10H and ending address 20H to the destination memory with starting address 15H
(With overlap).

Code
Address
8000

Label

Mnemonic

Comment

MOV R2,#10
MOV R0,#20H
MOV R1,#25H
CLR C
COPYIT:

MOV A,@R0

MOV @R1,A
DEC R0
DEC R1
DJNZ R2,COPYIT
OVER: SJMP OVER

Flowchart:

Page 12 of 36

2(c) Write an ALP to move block of data bytes present in external memory with starting
address 800H to the destination memory with starting address 900H and size of array is 10H.

Code:
Address
8000

Label

Mnemonic

Comment

ORG 0
MOV R0,#10
MOV 82H,#00H
LOOP:
MOVX A,@DPTR
MOV 83H,#09H
MOVX @DPTR,A
INC DPTR
DJNZ R0,LOOP
END

Flowchart:

Page 13 of 36

2(d) Write an ALP to exchange block of data bytes present in external memory. Starting address of
first is 8000H and starting address of other block 9000H and size of array is 10H.

Code:
Address
8000

Label

Mnemonic
MOV R0,#10
MOV 82H,#00H
LOOP: MOV 83H,#80H
MOVX A,@DPTR
MOV R1, A
MOV 83H,#90H
MOV @DPTR,A
XCH A, R1
MOVX @DPTR,A
MOV 83H, #80H
MOV A, R1
MOVX @DPTR,A
INC DPTR
DJNZ R0,LOOP
END

Page 14 of 36

Comment

Experiment:-3
3(a) Write an ALP to illustrate hexadecimal up counter with up counter with a given starting and ending
value. Starting Range is 00H, Ending Range is 0FFH. Registers are used R0,R1,R3,R6.
Address
8000

Label

Mnemonic

Comment

ORG 00
MOV R0, #05H
MOV R1, #0E5H
MOV A, R0
MOV R3,A
MOV A, R1
MOV R6, A
HERE: INC R3
MOV A, R3
SUBB A, R6
JNZ HERE
END

Flowchart:

Page 15 of 36

3. B) Write an ALP to illustrate hexadecimal down counter with a given starting and ending value.
Starting range is 0FFH and ending range is 00H
Address

Label

Mnemonic

Comment

8000
MOV TMOD,#2H
MOV TH0 ,#0
AGAIN: MOV R5,#250
ACALL DELAY
CPL P1.0
SJMP AGAIN
DELAY: SETB TR0
BACK: JNB TF0,BACK
CLR TR0
CLR TF0
DJNZ R5,DELAY
RET

Flowchart:

Page 16 of 36

3.C) Write an ALP to illustrate decimal up counter with a given starting and ending value. Starting
Range is 00H, ending range is 099H, registers used are R0, R1, R3, R6
Address

Label

8000

Mnemonic

Comment

ORG 00
MOV R0, #00H
MOV R1, #99H
MOV A, R0
MOV R3,A
MOV A, R1
MOV R6, A
HERE:
MOV A, #07H
ADD A, R3
JB 0D6H, IN
JNB 0D6H, OUT
IN:

MOV R3,A
JMP IT

OUT:

INC R3

IT:

MOV A, R3
SUBB A, R6
JNZ HERE
END

Page 17 of 36

Flowchart:

Page 18 of 36

3. D) Write an ALP to illustrate decimal down counter with a given starting and ending value.
Starting Range is 099H, ending range is 00H, registers used are R0, R1, R3, R6
Address

Label

8000

Mnemonic

Comment

ORG 00
MOV R0, #06H
MOV R1, #99H
MOV A, R0
MOV R3,A
MOV A, R1
MOV R6, A
HERE:

DEC R6
MOV 05H, R6
ANL 05H, #0FH
CJNE R5,#00, IT
MOV A,R6
SUBB A, #07H
MOV R6,A

IT:

MOV A, R3
SUBB A, R6
JNZ HERE
END

Page 19 of 36

Flowchart:

Page 20 of 36

3. E) Write an ALP to convert decimal number to its equivalent hexadecimal number. Input
register is R0, output register is R1
Address
8000

Label

Mnemonic

Comment

MOV R0,#255
MOV 01,R0
MOV A,R1
MOV B,#10H
DIV AB
SWAP A
ADD A,B
END

Flowchart:

Page 21 of 36

Experiment:-4
4. A) Using only one pointer, R0, pack two arrays of BCD digit to create third array. The highest digits are
available from 30H to 3FH. Lower digits are available from 40H to 4FH. Packed BCD numbers are to be
stored from 50H to 5FH
Address
8000

Label

Mnemonic

Comment

ORG 0000H
MOV PSW ,#00H
MOV R7,#10H
MOV R0, #30H
LOOP: MOV A, @R0
RL A
RL A
RL A
RL A
ANL 00H, #0FH
ORL 00H, #40H
ORL A, @R0
ANL 00H, #0FH
ORL 00H, #50H
MOV @R0,A
ANL 00H, #0FH
ORL 00H, #30H
INC R0
DJNZ R7,LOOP
END

Page 22 of 36

4. B) Find the largest and smallest from N unsigned integers. Assume the value of N to be
available in the internal data memory location 30H. The array starts from location 31H. Store the
maximum integers in R4 and Minimum in R3
Address
8000

Label

Mnemonic

Comment

ORG 0000H
MOV PSW ,#00H
MOV R7,30H
MOV R0, #31H
MOV R4,#00H
MOV R3, #0FFH
LOOP: MOV A, @R0
CJNE A, 04H, NEXT
NEXT : JC CHKMIN
MOV R4, A
SJMP NXTNUM
CHKMIN: CJNE A, 03H, AGAIN
AGAIN: JNC NXTNUM
MOV R3,A
NXTNUM: INC R0
DJNZ R7,LOOP
END

Page 23 of 36

Flowchart:

Page 24 of 36

Experiment:-5
5. Write an ALP to find largest elements in a given array present in external memory with starting
address 900H and size of array is 10H.
Address
8000

Label

Mnemonic

Comment

ORG 00H
MOV R0,10
MOV DPTR, #0900H
MOV B,0
BACK: MOV A,@DPTR
CJNE A,B,LOOP
LOOP: JC LOOP1
MOV B,A
INC DPTR
DJNZ R0,BACK
SJMP NEXT
LOOP 1:
DJNZ R0,BACK
NEXT:
END

Page 25 of 36

Flowchart:

Page 26 of 36

Experiment:-6
6. Write an ALP to sort a given array present in external memory with a starting address 900H and size of
the array is 10H using bubble sort technique.
Address
8000

Label

Mnemonic

Comment

ORG 0000H
SJMP 30H
ORG 30H
MOV R0,#05
L1: MOV dptr, #9000h
MOV A,R0
MOV R1,A
L2: MOVX a, @dptr
MOV B, A
MOVX a, @dptr
CLR C
MOV R2, A
SUBB A, B
JC NOEXCHG
MOV A,B
MOVX @dptr,a
DEC DPL
MOV a,R2
MOVX @dptr,a
INC DPTR
NOEXCHG: DJNZ R1,L2
DJNZ R0,L1
here: SJMP here

Page 27 of 36

Flowchart:

Page 28 of 36

Experiment:-7
7. Write an ALP to search a byte in array of bytes stored in external RAM

Address
8000

Label

Mnemonic

Comment

ORG 00H
LOOP:MOV R0,#0AH
MOV R1,#10
SKIP:MOV R2,#00H
MOV DPTR,#9000H
MOVX A,@DPTR
SUBB A,R1
CLR C
INC DPTR
JNZ SKIP
INC R2
DJNZ R0,LOOP
END

Flowchart:

Page 29 of 36

Experiment:-8
8(a) A few random unsigned numbers are stored in internal data memory location 31H onwards. Number
of terms is available in 30H. Assuming that none of these numbers are is greater than 5, find the
factorials of these integers and then find their sum. Assume that the sum would not exceed 8-bit value.
Address
8000

Label

Mnemonic

Comment

MOV R2, 30H


MOV R0, 31H
AGAIN: MOV A, @R0
MOV B, A
DEC B
MULTI: MUL AB
MOV @R0, A
DJNZ B, MULTI
INC R0
DJNZ R2, AGAIN
MOV R2, 30H
CLR A
ADDI: DEC R0
ADD A, @R0
DJNZ R2, ADDI
MOV R4, A

Page 30 of 36

Flowchart:

Page 31 of 36

8. B) Write an ALP to demonstrate call and return instruction using a program to find the factorial of a
number
Address
8000

Label

Mnemonic

Comment

ORG 0000H
MOV R0, #04H
MOV A, R0
CALL FACT
DEC R0
DJNZ R0, L1
ORG 0011H
FACT: CJNE R0, #01H, LOOP
RET
LOOP: DEC R0
MOV B,R0
MUL AB
LJMP FACT
L1:
END

Page 32 of 36

Experiment:-9
9.a) WAP to blink all LEDs together for 5 seconds and then all LEDs off for 5 seconds. This should go on
continuously.
Address
8000

Label

Mnemonic

Comment

MOV TMOD, #01


MOV A, #00H
MOV P1, A
LOOP1: MOV R0, #70
LOOP: MOV TL0, #0
MOV TH0, #0FFH
SETB TR0
AGAIN: JNB TF0, AGAIN
CLR TF0
DJNZ R0, LOOP
CPL A
MOV P1, A
SJMP LOOP1

Page 33 of 36

9.B) WAP to blink alternate LEDs together for 5 seconds. This should go on continuously

Address
8000

Label

Mnemonic

Comment

MOV TMOD, #01


MOV A, #AAH
MOV P1, A
LOOP1: MOV R0, #70
LOOP: MOV TL0, #0
MOV TH0, #0FFH
SETB TR0
AGAIN: JNB TF0, AGAIN
CLR TF0
DJNZ R0, LOOP
CPL A
MOV P1, A
SJMP LOOP1

Page 34 of 36

9.C) Develop a program so that LEDs interfaced with P1.0 blinks continuously
Address
8000

Label

Mnemonic

Comment

ORG 0000H
LOOP: MOV R0, #0FFH
HERE: DJNZ R0, HERE
CPL P1.0
SJMP LOOP

Page 35 of 36

9. D) Two keys and one LED are interfaced with 8051. Develop a software so that K1 would turn
the LED on and K2 would turn it off.
Address
8000

Label

Mnemonic

Comment

ORG 0000H
LEDONF: MOV P0, #83H
RDKEY: MOV A, P0
RRC A
JC RDKEY
JNC L1
L1: SETB P1.0
RRC A
JC RDKEY
JNC L2
L2: CLR P1.0
SJMP RDKEY

Page 36 of 36

You might also like