Вы находитесь на странице: 1из 20

ANKIT RATHI

DIVIDE 16 BIT NUMBER BY 8 BIT NUMBER


1 8000 .ORG 8000H
2 8000 78 10 MOV R0,#10H
3 8002 7F 03 MOV R7,#03H
4 8004 90 81 00 MOV DPTR,#8100H
5 8007 E0 MOVX A,@DPTR
6 8008 88 F0 L1:MOV B,R0
7 800A 84 DIV AB
8 800B AE F0 MOV R6,B
9 800D C0 E0 PUSH A
10 800F 74 10 MOV A,#10H
11 8011 A4 MUL AB
12 8012 F9 MOV R1,A
13 8013 A3 INC DPTR
14 8014 E0 MOVX A,@DPTR
15 8015 39 ADDC A,R1
16 8016 DF F0 DJNZ R7,L1
17 8018 D0 02 POP 02H
18 801A D0 01 POP 01H
19 801C D0 00 POP 00H
20 801E 12 00 03 LCALL 0003H
21 8021 12 00 03 LCALL 0003H
21 8021 12 00 03 LCALL 0003H

Page 1
ANKIT RATHI

GENERATE 10 FIBONACCI NUMBERS.

1 8000 .ORG 8000H


2 8000 7F 0A MOV R7,#0AH
3 8002 78 00 MOV R0,#00H
4 8004 79 01 MOV R1,#01H
5 8006 E8 MOV A,R0
6 8007 90 81 00 MOV DPTR,#8100H
7 800A F0 MOVX @DPTR,A
8 800B A3 INC DPTR
9 800C E9 MOV A,R1
10 800D F0 MOVX @DPTR,A
11 800E E8 L1:MOV A,R0
12 800F 29 ADD A,R1
13 8010 A3 INC DPTR
14 8011 F0 MOVX @DPTR,A
15 8012 FA MOV R2,A
16 8013 E9 MOV A,R1
17 8014 F8 MOV R0,A
18 8015 EA MOV A,R2
19 8016 F9 MOV R1,A
20 8017 DF F5 DJNZ R7,L1
21 8019 12 00 03 LCALL 0003H
22 801C 12 00 03 LCALL 0003H
22 801C 12 00 03 LCALL 0003H

Page 2
ANKIT RATHI

TO VERIFY ALL BIT MANIPULATION OPERATIONS.

1 8000 .ORG 8000H


2 8000 90 81 00 MOV DPTR,#8100H
3 8003 E0 MOVX A,@DPTR
4 8004 F8 MOV R0,A
5 8005 A3 INC DPTR
6 8006 E0 MOVX A,@DPTR
7 8007 F9 MOV R1,A
8 8008 58 ANL A,R0
9 8009 A3 INC DPTR
10 800A F0 MOVX @DPTR,A
11 800B E9 MOV A,R1
12 800C 48 ORL A,R0
13 800D A3 INC DPTR
14 800E F0 MOVX @DPTR,A
15 800F E9 MOV A,R1
16 8010 68 XRL A,R0
17 8011 A3 INC DPTR
18 8012 F0 MOVX @DPTR,A
19 8013 E9 MOV A,R1
20 8014 F4 CPL A
21 8015 A3 INC DPTR
22 8016 F0 MOVX @DPTR,A
23 8017 12 00 03 LCALL 0003H

Page 3
ANKIT RATHI

TO TRANSFER A BLOCK OF DATA FROM ONE MEMORY LOCATION TO ANOTHER MEMORY LOCATION.

1 8000 .ORG 8000H


2 8000 7F 0A MOV R7,#0AH
3 8002 79 81 MOV R1,#81H
4 8004 7A 00 MOV R2,#00H
5 8006 7B 82 MOV R3,#82H
6 8008 7C 00 MOV R4,#00H
7 800A 89 83 L1:MOV DPH,R1
8 800C 8A 82 MOV DPL,R2
9 800E E0 MOVX A,@DPTR
10 800F A3 INC DPTR
11 8010 A9 83 MOV R1,DPH
12 8012 AA 82 MOV R2,DPL
13 8014 8B 83 MOV DPH,R3
14 8016 8C 82 MOV DPL,R4
15 8018 F0 MOVX @DPTR,A
16 8019 A3 INC DPTR
17 801A AB 83 MOV R3,DPH
18 801C AC 82 MOV R4,DPL
19 801E DF EA DJNZ R7,L1
20 8020 12 00 03 LCALL 0003H

Page 4
ANKIT RATHI

TO FIND THE LARGEST NUMBER FROM GIVEN TEN 8-BIT NUMBERS.

1 8000 .ORG 8000H


2 8000 7F 09 MOV R7,#09H
3 8002 79 81 MOV R1,#81H
4 8004 7A 00 MOV R2,#00H
5 8006 89 83 MOV DPH,R1
6 8008 8A 82 MOV DPL,R2
7 800A E0 MOVX A,@DPTR
8 800B F5 00 MOV 00H,A
9 800D A3 L1:INC DPTR
10 800E E0 MOVX A,@DPTR
11 800F B5 00 00 CJNE A,00H,C1
12 8012 40 02 C1:JC L2
13 8014 F5 00 MOV 00H,A
14 8016 DF F5 L2:DJNZ R7,L1
15 8018 12 00 03 LCALL 0003H

Page 5
ANKIT RATHI

TO ARRANGE FIVE 8-BIT NUMBERS IN DESCENDING ORDER.

1 8000 .ORG 8000H


2 8000 79 05 MOV R1,#05H
3 8002 19 DEC R1
4 8003 89 00 L4:MOV 00H,R1
5 8005 90 81 00 MOV DPTR,#8100H
6 8008 E0 L3:MOVX A,@DPTR
7 8009 F5 F0 MOV 0F0H,A
8 800B A3 INC DPTR
9 800C E0 MOVX A,@DPTR
10 800D B5 F0 02 CJNE A,0F0H,L1
11 8010 80 0A SJMP L2
12 8012 40 08 L1:JC L2
13 8014 15 82 DEC 82H
14 8016 F0 MOVX @DPTR,A
15 8017 E5 F0 MOV A,0F0H
16 8019 05 82 INC 82H
17 801B F0 MOVX @DPTR,A
18 801C D8 EA L2:DJNZ R0,L3
19 801E D9 E3 DJNZ R1,L4
20 8020 12 00 03 LCALL 0003H

Page 6
ANKIT RATHI

TO ARRANGE FIVE 8-BIT NUMBERS IN ASCENDING ORDER.

1 8000 .ORG 8000H


2 8000 79 05 MOV R1,#05H
3 8002 19 DEC R1
4 8003 89 00 L4:MOV 00H,R1
5 8005 90 81 00 MOV DPTR,#8100H
6 8008 E0 L3:MOVX A,@DPTR
7 8009 F5 F0 MOV 0F0H,A
8 800B A3 INC DPTR
9 800C E0 MOVX A,@DPTR
10 800D B5 F0 02 CJNE A,0F0H,L1
11 8010 80 0A SJMP L2
12 8012 40 08 L1:JC L2
13 8014 15 82 DEC 82H
14 8016 F0 MOVX @DPTR,A
15 8017 E5 F0 MOV A,0F0H
16 8019 05 82 INC 82H
17 801B F0 MOVX @DPTR,A
18 801C D8 EA L2:DJNZ R0,L3
19 801E D9 E3 DJNZ R1,L4
20 8020 12 00 03 LCALL 0003H

Page 7
ANKIT RATHI

BCD UP COUNTER (00 to 99)

1 8000 .ORG 8000H


2 8000 74 00 MOV A,#00H
3 8002 FE L1:MOV R6,A
4 8003 C0 E0 PUSH 0E0H
5 8005 12 66 D3 LCALL 66D3H
6 8008 78 FF MOV R0,#0FFH
7 800A 79 FF MOV R1,#0FFH
8 800C 12 67 98 LCALL 6798H
9 800F D0 E0 POP 0E0H
10 8011 24 01 ADD A,#01H
11 8013 D4 DA A
12 8014 50 EC JNC L1
13 8016 12 00 03 LCALL 0003H
14 8019 12 00 03 LCALL 0003H
14 8019 12 00 03 LCALL 0003H

Page 8
ANKIT RATHI

BCD DOWN COUNTER (99 to 00)

1 8000 .ORG 8000H


2 8000 74 99 MOV A,#99H
3 8002 FE L1:MOV R6,A
4 8003 C0 E0 PUSH 0E0H
5 8005 12 66 D3 LCALL 66D3H
6 8008 78 FF MOV R0,#0FFH
7 800A 79 FF MOV R1,#0FFH
8 800C 12 67 98 LCALL 6798H
9 800F D0 E0 POP 0E0H
10 8011 24 99 ADD A,#99H
11 8013 D4 DA A
12 8014 40 EC JC L1
13 8016 12 00 03 LCALL 0003H
14 8019 12 00 03 LCALL 0003H
14 8019 12 00 03 LCALL 0003H

Page 9
ANKIT RATHI

TO SQUARE A GIVEN 8-BIT NUMBER.

1 8000 .ORG 8000H


2 8000 90 81 00 MOV DPTR,#8100H
3 8003 E0 MOVX A,@DPTR
4 8004 F5 F0 MOV 0F0H,A
5 8006 A4 MUL AB
6 8007 12 00 03 LCALL 0003H
7 800A 12 00 03 LCALL 0003H
7 800A 12 00 03 LCALL 0003H

Page 10
ANKIT RATHI

TO FIND THE CUBE OF A GIVEN 8-BIT NUMBER.

1 8000 .ORG 8000H


2 8000 90 81 00 MOV DPTR,#8100H
3 8003 E0 MOVX A,@DPTR
4 8004 F9 MOV R1,A
5 8005 89 F0 MOV 0F0H,R1
6 8007 A4 MUL AB
7 8008 F8 MOV R0,A
8 8009 AA F0 MOV R2,0F0H
9 800B AB 01 MOV R3,01H
10 800D E8 MOV A,R0
11 800E 8B F0 MOV B,R3
12 8010 A4 MUL AB
13 8011 FE MOV R6,A
14 8012 AD F0 MOV R5,B
15 8014 EA MOV A,R2
16 8015 8B F0 MOV B,R3
17 8017 A4 MUL AB
18 8018 2D ADD A,R5
19 8019 FD MOV R5,A
20 801A 12 66 D3 LCALL 66D3H
21 801D AF F0 MOV R7,B
22 801F AE 05 MOV R6,05H
23 8021 12 66 C1 UP:LCALL 66C1H
24 8024 80 FB SJMP UP

Page 11
ANKIT RATHI

TO SUBTRACT TWO MULTIBYTE NUMBERS


1 8000 .ORG 8000H
2 8000 7F 0A MOV R7,#0AH
3 8002 79 81 MOV R1,#81H
4 8004 7A 00 MOV R2,#00H
5 8006 7B 81 MOV R3,#81H
6 8008 7C 20 MOV R4,#20H
7 800A 89 83 L1:MOV DPH,R1
8 800C 8A 82 MOV DPL,R2
9 800E E0 MOVX A,@DPTR
10 800F F8 MOV R0,A
11 8010 A3 INC DPTR
12 8011 A9 83 MOV R1,DPH
13 8013 AA 82 MOV R2,DPL
14 8015 8B 83 MOV DPH,R3
15 8017 8C 82 MOV DPL,R4
16 8019 E0 MOVX A,@DPTR
17 801A 98 SUBB A,R0
18 801B F0 MOVX @DPTR,A
19 801C A3 INC DPTR
20 801D AB 83 MOV R3,DPH
21 801F AC 82 MOV R4,DPL
22 8021 DF E7 DJNZ R7,L1
23 8023 12 00 03 LCALL 0003H

Page 12
ANKIT RATHI

TO ADD TWO MULTIBYTE NUMBERS

1 8000 .ORG 8000H


2 8000 7F 0A MOV R7,#0AH
3 8002 79 81 MOV R1,#81H
4 8004 7A 00 MOV R2,#00H
5 8006 7B 81 MOV R3,#81H
6 8008 7C 20 MOV R4,#20H
7 800A 89 83 L1:MOV DPH,R1
8 800C 8A 82 MOV DPL,R2
9 800E E0 MOVX A,@DPTR
10 800F F8 MOV R0,A
11 8010 A3 INC DPTR
12 8011 A9 83 MOV R1,DPH
13 8013 AA 82 MOV R2,DPL
14 8015 8B 83 MOV DPH,R3
15 8017 8C 82 MOV DPL,R4
16 8019 E0 MOVX A,@DPTR
17 801A 38 ADDC A,R0
18 801B F0 MOVX @DPTR,A
19 801C A3 INC DPTR
20 801D AB 83 MOV R3,DPH
21 801F AC 82 MOV R4,DPL
22 8021 DF E7 DJNZ R7,L1
23 8023 40 03 JC L2
24 8025 12 00 03 LCALL 0003H
25 8028 A3 L2:INC DPTR
26 8029 74 01 MOV A,#01H
27 802B F0 MOVX @DPTR,A
28 802C 12 00 03 LCALL 0003H

Page 13
ANKIT RATHI

TO MULTIPLY A 16-BIT NUMBER WITH A 8-BIT NUMBER

1 8000 .ORG 8000H


2 8000 78 12 MOV R0,#12H
3 8002 79 34 MOV R1,#34H
4 8004 7A 12 MOV R2,#12H
5 8006 E9 MOV A,R1
6 8007 8A F0 MOV B,R2
7 8009 A4 MUL AB
8 800A FE MOV R6,A
9 800B AD F0 MOV R5,B
10 800D E8 MOV A,R0
11 800E 8A F0 MOV B,R2
12 8010 A4 MUL AB
13 8011 2D ADD A,R5
14 8012 FD MOV R5,A
15 8013 12 66 D3 LCALL 66D3H
16 8016 AF F0 MOV R7,B
17 8018 AE 05 MOV R6,R5
18 801A 12 66 C1 UP:LCALL 66C1H
19 801D 80 FB SJMP UP

Page 14
ANKIT RATHI

TO FIND WHETHER A GIVEN NUMBER IS EVEN OR ODD.

1 8000 .ORG 8000H


2 8000 90 81 00 MOV DPTR,#8100H
3 8003 E0 MOVX A,@DPTR
4 8004 13 RRC A
5 8005 40 05 JC L1
6 8007 74 FF MOV A,#FFH
7 8009 12 00 03 LCALL 0003H
8 800C 74 00 L1:MOV A,#00H
9 800E 12 00 03 LCALL 0003H

Page 15
ANKIT RATHI

TO FIND WHTHER A GIVEN NUMBER IS POSITIVE OR NEGATIVE.

1 8000 .ORG 8000H


2 8000 90 81 00 MOV DPTR,#8100H
3 8003 E0 MOVX A,@DPTR
4 8004 33 RLC A
5 8005 40 05 JC L1
6 8007 74 FF MOV A,#FFH
7 8009 12 00 03 LCALL 0003H
8 800C 74 00 L1:MOV A,#00H
9 800E 12 00 03 LCALL 0003H

Page 16
ANKIT RATHI

TO FIND THE LCM OF TWO 8-BIT NUMBERS.

1 8000 .ORG 8000H


2 8000 90 81 00 MOV DPTR,#8100H
3 8003 E0 MOVX A,@DPTR
4 8004 F5 F0 MOV 0F0H,A
5 8006 A3 INC DPTR
6 8007 E0 MOVX A,@DPTR
7 8008 FB MOV R3,A
8 8009 C0 E0 BACK:PUSH A
9 800B C0 F0 PUSH B
10 800D 84 DIV AB
11 800E A9 F0 MOV R1,0F0H
12 8010 B9 00 06 CJNE R1,#00,L1
13 8013 D0 F0 POP B
14 8015 D0 E0 POP A
15 8017 80 07 SJMP L2
16 8019 D0 F0 L1:POP B
17 801B D0 E0 POP A
18 801D 29 ADD A,R1
19 801E 01 09 JMP BACK
20 8020 FE L2:MOV R6,A
21 8021 12 00 03 L4:LCALL 0003H
22 8024 80 FB SJMP L4

Page 17
ANKIT RATHI

2 OUT OF 5 CODE.

1 8000 .ORG 8000H


2 8000 7A 00 MOV R2,#00H
3 8002 90 81 00 MOV DPTR,#8100H
4 8005 E0 MOVX A,@DPTR
5 8006 B4 1F 00 CJNE A,#1FH,L1
6 8009 40 04 L1:JC L2
7 800B 78 00 L5:MOV R0,#00H
8 800D 80 0E SJMP L3
9 800F 79 05 L2:MOV R1,#05H
10 8011 03 BACK:RR A
11 8012 50 01 JNC L4
12 8014 0A INC R2
13 8015 D9 FA L4:DJNZ R1,BACK
14 8017 EA MOV A,R2
15 8018 B4 02 F0 CJNE A,#02H,L5
16 801B 78 FF MOV R0,#0FFH
17 801D 00 L3:NOP
18 801E 12 00 03 LCALL 0003H

Page 18
ANKIT RATHI

TO CHECK WHETHER A GIVEN 8-BIT NUMBER IS PALINDROME OR NOT.

1 8000 .ORG 8000H


2 8000 90 81 00 MOV DPTR,#8100H
3 8003 E0 MOVX A,@DPTR
4 8004 F8 MOV R0,A
5 8005 C4 SWAP A
6 8006 B5 00 04 CJNE A,00H,L1
7 8009 79 FF MOV R1,#0FFH
8 800B 80 02 SJMP L2
9 800D 79 00 L1:MOV R1,#00H
10 800F 00 L2:NOP
11 8010 12 00 03 LCALL 0003H
12 8013 12 00 03 LCALL 0003H
12 8013 12 00 03 LCALL 0003H

Page 19
ANKIT RATHI

TO CONVERT A HEXADECIMAL NUMBER TO A DECIMAL NUMBER.

1 8000 .ORG 8000H


2 8000 90 81 00 MOV DPTR,#8100H
3 8003 E0 MOVX A,@DPTR
4 8004 75 F0 64 MOV 0F0H,#64H
5 8007 B4 64 00 CJNE A,#64H,L1
6 800A 40 05 L1:JC L2
7 800C 84 DIV AB
8 800D A3 INC DPTR
9 800E F0 MOVX @DPTR,A
10 800F E5 F0 MOV A,0F0H
11 8011 B4 0A 00 L2:CJNE A,#0AH,L3
12 8014 40 0B L3:JC L4
13 8016 75 F0 0A MOV 0F0H,#0AH
14 8019 84 DIV AB
15 801A 78 04 MOV R0,#04H
16 801C 23 BACK:RL A
17 801D D8 FD DJNZ R0,BACK
18 801F 25 F0 ADD A,0F0H
19 8021 A3 L4:INC DPTR
20 8022 F0 MOVX @DPTR,A
21 8023 12 00 03 LCALL 0003H

Page 20