Vortex Mathematics & The Fibonacci Spiral: Unlocking The Fibonacci Sequence
1. Algorithm to find the first ten terms of a Fibonacci series · PDF file ·...
Transcript of 1. Algorithm to find the first ten terms of a Fibonacci series · PDF file ·...
1. Algorithm to find the first ten terms of a Fibonacci series
Step 1: Start
Step 2: Load the memory to the DE pair
Step 3: Set Accumulator A=00
B=01
C=00
H=0A
Step 4: Compute
DE <- Acc
DE<- DE+1
C<-B
Acc<-Acc+B
B<-A
A<-C
H<-H-1
Step 5: If H!=0 Goto Step 4
Else Goto Step 6
Step 6: Stop
8085 Program for finding the first ten terms of Fibonacci series
Address
Opcode Label Mnemonics Operand Comments
8001
8002
8003
11
01
81
LXI D,8101 Load the Register pair D-E
with address 8001
8004
8005
3E
00
MVI A,00 Move 00 to Accumulator A
8006
8007
06
01
MVI B,01 Move 01 to Register B
8008
8009
0E
00
MVI C,00 Move 00 to Register C
800A
800B
26
0A
MVI H,0A Move 0A to H
800C 12 LOOP STAX D Store Accumulator A with
contents of memory specified
in D-E pair
800D 13 INX D Increment D-E pair
800E 48 MOV C,B Move content to Register B to
Register C
800F 80 ADD B Add the content of the Register
B to Accumulator
8010 47 MOV B,A Move content to Register A to
Register B
8011 79 MOV A,C Move content to Register C to
Register A
8012 25 DCR H Decrement HL Pair
8013
8014
8015
C2
0C
80
JNZ LOOP JUMP when HL pair is not
zero to LOOP
8016 76 HLT Stop
OUTPUT:
8101: 00
8102: 01
8103: 01
8104: 02
8105: 03
8106: 05
8107: 08
8108: 0D
8109: 15
810A: 22
2. Algorithm to find sum of first 10 terms of odd and even series
Step 1: Start
Step 2: Set
Acc<-00
B<-01
C<-0A
Step 3: Compute
Acc<- acc+B
B<-B+1
B<-B+1
C<-C+1
Step 4: If C!= 0 Goto Step 3
Else Goto Step 5
Step 5: Store the result in the specified address (in 8101)
Step 6: Compute
A<-A-0A
Step 7: Store the result in the specified address (in 8102)
Step 8: Stop
8085 Program to find sum of first 10 terms of odd and even series
Address Opcode Label Menunomics Operand Comments
8001
8002
3E
00
MVI C,0A Move 0A to Register C
8003
8004
06
01
MVI A,00 Move 00to Register A
8005
8006
0E
0A
MVI B,01 Move 01to Register B
8007 80 LOOP ADD B Add the contents of the
Register B to the Accumulator
A
8008 04 INR B Increment Register B
8009 04 INR B Increment B
800A 0D DCR C Decrement C
800B
800C
800D
C2
07
80
JNZ LOOP JUMP when Register C is not
zero to LOOP
800E
800F
8010
32
01
80
STA 8101 Store content of Accumulator
A at 8001
8011
8012
D6
0A
SUI 0A Subtract immediate 0A to
Accumulator A
8013
8014
8015
32
02
80
STA 8102 Store content of Accumulator
A at 8002
8016 76 HLT Stop
OUTPUT:
8101: 64
8102: 6E
3. Algorithm to interchange N one byte of data
Step 1: Start
Step 2: Load the starting memory address of one of the data’s in HL
pair.
Step 3: Load the starting memory address of one of the data’s in DE
pair.
Step 4: set B<-05
Step 5: Compute
C<-M
Step 6: Load the accumulator with the DE pair
Step 7: Compute
M<-A
A<-C
Step 8: Store Accumulator to DE pair
Step 9: Compute
H<-H+1
D<-D+1
B<-B+1
Step 10: If B!=0 Goto Step 5
Else Goto Step 11.
Step 11: Stop
8085 Program to interchange N one bytes of data
Address Opcode Label Menunomics Operand Comments
8020
8021
8022
21
40
80
LXI H,8040 Load the Register pair H-L
with address 8040
8023
8024
8025
11
50
80
LXI D,8050 Load the Register pair D-E
with address 8050
8026
8027
06
05
MVI B,05 Move 05 to Register B
8028 43 LOOP MOV C,M Move the contents of memory
to Register C
8029 1A LDAX D Load Accumulator A with
contents of memory specified
by D-E Pair
802A 77 MOV M,A Move the contents of
Accumulator A to memory
802B 79 MOV A,C Move the contents of Register
C to Register A
802C 12 STAX D Store Accumulator A with
contents of memory specified
by D-E Pair
802D 23 INX H Increment HL Pair
802E 13 INX D Increment DE Pair
802F 05 DCR B Decrement B
8030
8031
8032
C2
28
80
JNZ LOOP Jump when register B is not
Zero to LOOP
8033 76 HLT Stop
OUTPUT:
BEFORE EXECUTION AFTER EXECUTION 8040: AA
8041: BB
8042: CC
8043: DD
8044: EE
8050: 11
8051: 22
8052: 33
8053: 44
8054: 55
8040: 11
8041: 22
8042: 33
8043: 44
8044: 55
8050: AA
8051: BB
8052: CC
8053: DD
8054: EE
4. Algorithm to check whether the 4th
bit number is zero
or one. Display FF if 1 else display 00.
Step 1: Start
Step 2: Load the accumulator with the contents of the given memory
Step 3: Set
B<-00
A<-A & 10.
Step 4: If A!=0, Goto Step 5
Step 5: B<-B-1
Step 6: Compute
A<-B
Step 7: Print A
Step 8: Stop
8085 Program to check whether 4th
bit of a number is zero or one.
Display FF if 1 else display 00.
Address Opcode Label Menunomics Operand Comments
8100
8101
8102
3A
20
81
LDA 8120 Load Accumulator A with
address 8120
8103
8104
06
00
MVI B,00 Move 00 to Register B
8105
8106
E6
10
ANI 10 And immediate 16 (10 in
hexa) to the Accumulator A
8107
8108
8109
CA
0B
81
JZ LOOP JUMP on zero to LOOP
810A 05 DCR B Decrement B
810B 78 LOOP MOV A,B Move contents of Register b
to Accumulator A
810C
810D
810E
32
21
81
STA 8121 Store contents of the
Accumulator in 8121
810F 76 HLT Stop
INPUT: OUTPUT:
1. 8120: 55 8121: FF
2. 8120: 26 8121: 00
5. Algorithm to add N one byte numbers
Step 1: Start
Step 2: Load the starting memory address of the contents
Step 3: Set
C<-M
A<-00
B<-A
Step 4: Compute
HL <- HL +1
A<-HL+A
A<-BCD form
Step 5: If carry flag is set, then
B<-B+1
Step 6: Compute
C<-C+1
Step 7: If C!=0, then Goto Step 4
Step 8: Print A
Step 9: Stop
8085 Program to add N one byte numbers
Address Opcode Label Menunomics Operand Comments
8000
8001
8002
21
00
81
LXI H,8100 Load HL Pair with address
8100
8003 4E MOV C,M Move content of memory to
Register C
8004
8005
3E
00
MVI A,00 Move 00 to Accumulator A
8006 47 MOV B,A Move content of
Accumulator A to Register B
8007 23 LOOP2 INX H Increment HL Pair
8008 86 ADD M Add the content of memory
to Accumulator A
8009
800A
800B
D2
0D
80
JNC LOOP1 JUMP to LOOP1 if carry flag
is not set
800C 04 INR B Increment B
800D 0D LOOP1 DCR C Decrement C
800E
800F
8010
C2
07
80
JNZ LOOP2 JUMP when Register C is not
zero to LOOP2
8011
8012
8013
32
01
82
STA 8201 Store the content of the
Accumulator A at 8201
8014 78 MOV A,B Move content of Register B
to Accumulator A
8015
8016
8017
32
02
82
STA 8202 Store the content of the
Accumulator A at 8202
8018 76 HLT Stop
INPUT: OUTPUT:
8100: 05 8201: 0F
8101: 01 8202: 00
8102: 02
8103: 03
8104: 04
8105: 05
6. Algorithm to add two digit BCD numbers
Step 1: Start
Step 2: Load the contents of the memory address in HL Pair
Step 3: Set
C<-00
Step 4: Compute
A<-M
HL<-HL+1
A<-A+HL
A<-BCD Form
Step 5: If the carry flag is not set, then Goto Step 6
Step 6: C<-C+1
Step 7: Store the result in the specified address
Step 8: A<-C
Store the result in the next memory address
Step 9: Stop
8085 Program to add two digit BCD numbers
Address Opcode Label Mnemonics Operand Comments
8000
8001
8002
21
10
87
LXI H,8110 Load HL Pair with address
8110
8003 7E MOV A,M Move content of memory to
Accumulator A
8004
8005
0E
00
MVI C,00 Move 00 to Register /c
8006 23 INX H Increment HL Pair
8007 86 ADD M Add contents of M to
Accumulator A
8008 27 DAA Convert the contents of
Accumulator A to Decimal
8009
800A
800B
D2
0D
80
JNC LOOP JUMP when carry is not zero
to LOOP
800C 0C INR C Increment C
800D
800E
800F
32
12
81
LOOP STA 8112 Store the content of the
Accumulator A at 8112
8010 79 MOV A,C Move the content of the
Register C to Accumulator
A
8011
8012
8013
32
13
81
STA 8113 Store the content of the
Accumulator A at 8113
8014 76 HLT Stop
INPUT: OUTPUT:
8110: 05 8112: 06
8111: 01 8113: 00
7. Algorithm to check whether a byte belongs to the 2-out-of 5codes.
Display FF if it is a 2- out-of-5codes, otherwise 00.
Step 1: Start
Step 2: Load the accumulator with the content with the specified address.
Step 3: compute
[B] <- [A]
Step 4: AND the hexadecimal number with (E0).
Step 5: If the resultant value is zero, then Goto step 16.
Step 6: Compute
[A] <- [B]
[c] <- 05.
[B] <- 00.
Step 7: Rotate the accumulator Right using the instruction RAR.
Step 8: If the carry flag is not set, then Goto Step 10
Else Goto step 9.
Step 9: [B] <- [B] +1
Step 10: [C] <- [C]-1.
Step 11: If the result is not zero, then Goto step 7.
Else goto step 12.
Step 12: [A] <- [B]
[A]< – 02.
Step 13: If the result is not zero, then Goto step 16.
Step 14: [A] <- FF.
Step 15: Goto step 17.
Step 16: [A] <- 00.
Step 17: Print [A].
Step 18: Stop
8085 Program to check whether a byte belongs to the 2-out-of-5 codes.
Display FF if it is a 2-out-of-5 otherwise 00.
Address Opcode Label Mnemonics Operand Comments
8000
8001
8002
3A
00
81
LDA 8100 Load the contents of
Address 8100 to Register
A
8003
47 MOV B,A Move content of
Accumulator A to
Register B
8004
8005
E6
E0
ANI E0 AND content of
Accumulator A with E0
8006
8007
8008
C2
22
80
JNZ Loop1 Jump when Accumulator
A is not zero to Loop1
8009
800A
0E
05
MVI C,05 Move 05 to Register C
800B
78 MOV A,B Move content of Register
B to Accumulator A
800C
800D
06
00
MVI B,00 Move 00 to Register B
800E 1F Loop3 RAR Rotate Right circular
Accumulator A
800F
8010
8011
D2
13
80
JNC Loop2 Jump to Loop2 if carry
flag is not set
8012 04 INR B Increment B
8013 0D LooP2 DCR C Decrement c
8014
8015
8016
C2
0E
80
JNZ Loop3 Jump to Loop3 when
Register C is not zero
8017
78 MOV A,B Move content of Register
B to Accumulator A
8018
8019
FE
02
CPI 02 Compare immediate
INPUT: OUTPUT:
1. 8100: 06 8101: FF
2. 8100: E6 8101: 00
801A
801B
801C
C2
22
80
JNZ Loop1 Jump to Loop1 when
Accumulator A is zero
801D
801E
3E
FF
MVI A,FF Move FF to Accumulator A
801F
8020
C3
24
JMP Loop4 Jump to Loop4
8021 80
8022
8023
3E
00
Loop1 MVI A,00 Move 00 to Accumulator A
8024
8025
8026
32
02
81
Loop4 STA 8101 Store content of
Accumulator A at 8102
8027 76 HLT Stop
8. Algorithm to perform Linear Search over a set of N numbers. Display
FF and its position if found otherwise 00.
Step 1: Start
Step 2: Load the content of the specified address into the accumulator.
Step 3: compute
[C] <- [A]
Step 4: Load the contents of the specified address into the accumulator.
Step 5: Compute
[D] <- 01.
Step 6: Load the specified address into HL-pair.
Step 7: Compute
[B] <- [M]
[B] <- [A].
Step 8: If the result is Zero, Goto step 16.
Step 9: [C] <- [C]-1.
Step 10: If [C]! =0, goto step 14.
Step 11: set
[A]<- 00.
Step 12: store the contents of the accumulator in the specified memory address.
Step 13: Goto step 20.
Step 14: [D] <- [D] +1.
[HL] <- [HL] +1.
Step 15: Goto step 7.
Step 16: Compute
[A] <- AA
Step 17: Store the contents of the accumulator in the specified memory address..
Step 18: Compute
[A] <- [B].
Step 19: Store the contents of the accumulator in the specified memory address.
Step 20: Stop.
8085 Program to perform Linear Search over a set of N numbers.
Display FF and its position if found otherwise 00. Address Opcode Label Mnemonics Operand Comments
8000
8001
8002
3A
00
82
LDA 8200 Load the contents of address
8200 to Accumulator
8003
4F
MOV C,A Move contents of Accumulator
to Register C
8004
8005
8006
3A
00
83
LDA 8300 Load the contents of address
8300 to Accumulator
8007
8008
16
01
MVI D,01 Move 01 to DE pair
8009
800A
800B
21
00
81
LXI H,8100 Load the address location 8100
to HL pair
800C 46 Loop MOV B,M Move the contents of Memory
to the register B.
800D B8 CMP B Compare the content of
accumulator with memory
content.
800E
800F
8010
C4
22
80
JZ Last If zero flag is set jump to Last
8011 0D DCR C Decrement register C
8012
8013
8014
C2
1D
80
JNZ Loop2 Jump when register C is not to
Loop2
8015
8016
3E
00
MVI A,00 Move 00 to Accumulator A
8017
8018
8019
32
00
84
STA 8400 Store the contents of
accumulator A at 8400
801A
801B
801C
C3
2B
80
JMP Next Jump to Next
801D 14 Loop
2
INR D Increment Dl pair
801E 23 INX H Increment HL pair
801F
8020
8021
C3
0C
80
JMP Loop Jump to Loop
8022
8023
3E
FF
Last MVI A,FF Move FF to Accumulator A
8024
8025
8026
32
00
84
STA 8400 Store the contents of
Accumulator A at 8400
8027 78 MOV A,D Move the contents of Register D
to Accumulator.
8028
8029
802A
32
01
84
STA 8401 Store the contents of
Accumulator at 8401.
802B 76 Next HLT Stop.
INPUT: OUTPUT:
8200: 04
8300: 12 8400: FF
8100: 13 8401: 03
8101: 10
8102: 12
8103: 04
9. Algorithm to add 32-bit binary number
Step 1: Start.
Step 2: Load the HL pair with the contents of the specified memory address.
Step 3: Compute
[C] <- [M]
[H] <- [H] +1
Step 4: Load the DE pair with the contents of the specified memory address.
Step 5: Load the accumulator with the contents of DE pair.
Step 6: OR the content of the accumulator
Step 7: Compute
[A] <- [A] + [HL] +C
[M]<- [A]
[HL]<- [HL] +1
[DE]<- [DE] +1
[C]<- [C] +1
Step 8: If [C]! =0, then Go to Step 5.
Else Go to Step 9.
Step 9: Stop.
8085 Program to add two 32-bit binary numbers.
Address Opcode Label Mnemonics Operand Comments
8000
8001
8002
21
50
80
LXI H,8050 Load HL Pair with Address
8050
8003
8004
8005
11
60
80
LXI D,8060 Load DE pair with Address
8060
8006
8007
0E
04
MVI C,04 Move 04 to register C
8008 1A Loop LDAX D Load the Accumulator A with
the contents of D
8009 8E ADC M Add with carry the content of
the memory to Accumulator A
800A 77 MOV M,A Move the contents of
Accumulator to Memory.
800B 23 INX H Increment HL pair
800C 13 INX D Increment DE pair
800D 0D DCR C Decrement Register C
800E
800F
8010
C2
08
80
JNZ Loop Jump when C is not zero to
Loop
8011 76 HLT Stop
BEFORE EXCUTION: AFTER EXECTION:
8050: 04
8051: 12 8060: 02 8051: 14
8052: 13 8061: 02 8052: 15
8053: 10 8062: 04 8053: 14
8054: 12 8063: 12 8054: 24
10. Algorithm to add two 32-bit BCD numbers.
Step 1: Start.
Step 2: Load the contents of the specified memory address to the HL pair.
Step 3: Compute
[C] <- [M]
[H] <- [H] +1
Step 4: Load the contents of the specified memory address to the DE pair.
Step 5: Load the accumulator content to the DE pair.
Step 6: OR the content of [A].
Step 7: Compute
[A] <- [A] + [HL] +Carry
[A]<- BCD form
[M]<- [A]
[HL]<- [HL] +1
[DE]<- [DE] +1
[C]<- [C] -1
Step 8: If [C]! =0, then Go to Step 5.
Else Go to Step 9.
Step 9: Stop.
8085 Program to add two 32-bit BCD number.
Address Opcode Label Mnemonics Operand Comments
8000
8001
8002
21
50
80
LXI H,8050 Load HL Pair with Address
8050
8003
8004
8005
11
60
80
LXI D,8060 Load DE pair with Address
8060
8006
8007
0E
04
MOV C,M Move the content of memory to
register C
8008 97 INX H
8009 1A Loop LDAX D Load the Accumulator A with
the contents of D.
800A 8E ADC M Add with carry the content of
the memory to Accumulator A
800B 27 DAA
800C 77 MOV M,A Move the contents of
Accumulator to Memory.
800D 13 INX D Increment DE pair
800E 23 INX H
800F 0D DCR C Decrement Register C
8010
8011
8012
C2
09
80
JNZ Loop Jump when C is not zero to
Loop
8013 76 HLT Stop
BEFORE EXCUTION: AFTER EXECTION:
8050: 04
8051: 02 8060: 06 8051: 08
8052: 04 8061: 04 8052: 08
8053: 02 8062: 02 8053: 04
8054: 05 8063: 05 8054: 10
11. Algorithm to subtract a 16-bit number from another 16-bit
number.
Step 1 : Start. Step 2 : Load the HL pair with the specified memory address.
Step 3 : Load the DE pair with the specified memory address. Step 4 : Load the BC pair with the specified memory address.
Step 5 : Load the accumulator with the content of D register. Step 6 : Compute
[A] ← [A] – [B]
Step 7 : Store the content of the accumulator in the BE pair.
Step 8 : Compute
[HL] ← [HL] + 1
[DE] ← [DE] + 1
[BC] ← [BC] + 1
Step 9 : Load the accumulator with the content of D register. Step 10: Compute
[A] ← [A] – [B] –CY
Step 11: Store the content of the accumulator in the BE pair . Step 12: Stop.
8085 Program to subtract a 16-bit number from another 16-bit number.
Address Opcode Label Mnemonics Operand Comments
8600 8601 8602
21 00 84
LXI H,8400 Load HL pair with address 8400
8603 8604
8605
11 00
85
LXI D,8500 Load DE pair with address 8500
8606
8607
0E
02
MVI C,02 Move 02 to Register C
8608 1A LOOP LDAX D Load Accumulator A with content of D
8609 9E SBB M Subtract the content of memory from
Accumulator A
860A 77 MOV M,A Move the contents of
Accumulator to Memory
860B 23 INX H Increment HL pair
860C 13 INX D Increment DE pair
860D 0D DCR C Decrement Register C
860E 860F
8610
C2 08
86
JNZ LOOP Jump when C is not zero to Loop
8611 76 HLT Stop
BEFORE EXECUTION: AFTER EXECUTION:
8400 : 03 8400 : 07
8401 : 04 8401 : 06 8500 : 0A
8501 : 0A
12. Algorithm to Multiply two 8-bit number.
Step 1 : Start . Step 2 : Load the HL pair with the contents of the specified memory address.
Step 3 : Set
[A] ← 00
Step 4 : Compute
[B] ← [M]
[HL] ← [HL] + 1.
Step 5 : Compute
[A] ← [A] + [B].
[C] ← [C] – 1.
Step 6 : If [C]!=0, then Goto Step 5. Else Goto Step 7. Step 7 : Print [A].
Step 8 : Stop .
8085 Program to multiply two 8-bit number.
Address Opcode Label Mnemonics Operand Comments
8000
8001 8002
21
00 81
LXI H,8100 Load HL pair with
address 8100
8003 8004
3E 00
MVI A,00 Move 00 to register A
8005 46 MOV B,M Move the contents of memory to register B
8006 23 INX H Increment HL pair
8007 4E MOV C,M Move the contents of
Memory to Register C
8008 80 Loop ADD B Add the contents of register B to
Accumulator
8009 0D DCR C Decrement C
800A 800B
800C
C2 08
80
JNZ Loop Jump to Loop when C is not zero
800D
800E 800F
32
02 81
STA 8102 Store the contents of
Accumulator at 8102
8010 76 HLT Stop
INPUT: OUTPUT:
1. 8100 : 05 8102 : 0F 8101 : 03
2. 8100 : 04 8102 : 10
8101 : 04
13 . Algorithm to find the largest and smallest of N numbers.
Step 1 : Start . Step 2 : Load the HL pair with the contents of the specified memory address.
Step 3 : Compute
[C] ← [M]
[C] ← [C] – 1
Step 4 : Load the HL pair with the next memory address. Step 5 : Compute
[D] ← [M]
[B] ← [M]
Step 6 : Compute
[HL] ← [HL] + 1
[A] ← [M]
[A] – [B]. If the carry flag is not set, then Goto Step 8 .
Else Goto Step 7. Step 7 : Compute
[A] ← [B].
Step 8 : Compute
[A] – [D]. If the carry flag is set, then Goto Step 10.
Else Goto Step 9. Step 9 : Compute
[D] ← [A].
Step 10: Compute
[C] ← [C] – 1.
Step 11: If [C]!=0,then Goto Step 6. Else Goto Step 12.
Step 12: Compute
[A] ← [B].
Step 13: Print [A]. Step 14: Compute
[A] ← [D].
Step 15: Print [A]. Step 16: Stop.
8085 Program to find largest and smallest of N numbers.
Address
Opcode Label Mnemonics Operand Comments
8000
8001 8002
21
00 81
LXI H,8100 Load HL pair with
address 8100
8003 4E MOV C,M Move contents of Memory to C register
8004 0D DCR C Decrement C register
8005
8006 8007
21
01 81
LXI H,8101 Load HL pair with
address 8101
8008 56 MOV D,M Move contents of Memory to D register
8009 46 MOV B,M Move contents of Memory to B register
800A 23 Loop2 INX H Increment HL pair
800B 7E MOV A,M Move contents of
Memory to A register
800C B8 CMP B Compare A register
with B register
800D
800E 800F
D2
11 80
JNC Loop1 Jump if the carry flag
is not set.
8010 78 MOV A,B Move the contents of the B register to A
8011 BA Loop1 CMP D Compare the content of D with A register
8012
8013 8014
DA
16 80
JC Loop3 Jump if the carry flag
is set.
8015 57 MOV D,A Move the content of A register to D register
8016 0D Loop3 DCR C Decrement C register
8017
8018 8019
C2
0A 80
JNZ Loop2 Jump if the zero flag
is not set
801A 78 MOV A,B Move the contents of the B register to A
801B 801C
801D
32 50
80
STA 8050 Store the content of 8050 to Accumulator
801E 7A MOV A,D Move the contents of
the D register to A
801F
8020 8021
32
51 80
STA 8051 Store the content of
8051 to Accumulator
8022 76 HLT Stop
INPUT: OUTPUT:
8100 : 05 8050 : 03 8101 : 03 8051 : 0B
8102 : 05 8103 : 07
8104 : 09 8105 : 0B
14. Algorithm to sort n numbers in ascending order using
Bubble Sort.
Step 1 : Start . Step 2 : Load the accumulator with specified memory address. Step 3 : Compute
[A] ← [A] – 1
[B] ← [A]
Step 4 : Compute
[C] ← [B]
Load the HL pair with the specified memory address. Step 5 : Compute
[A] ← [M]
[HL] ← [HL] + 1
[A] – [M] Step 6 : If the carry flag is set, then Goto Step 8. Else Goto Step 6 .
Step 7 : Compute
[D] ← [M]
[M] ← [A]
[HL] ← [HL] - 1
[M] ← [D]
[HL] ← [HL] + 1
Step 8 : Compute
[C] ← [C] – 1
Step 9 : If [C]1=0,Goto Step 5.
Else Goto Step 10. Step10: Compute
[B] ← [B] – 1
Step11: If [B]!=0, Goto Step 4.
Else Goto Step 12. Step12: Stop .
8085 Program to sort n numbers in ascending order using Bubble
sort.
Address Opcode Label Mnemonics Operand Comments
8000
8001 8002
3A
00 8B
LDA
8B00 Load the accumulator
with the contents of the address 8B00
8003 3D DCR A Decrement the accumulator
8004 47 MOV B,A Move the content of the accumulator to the B
register
8005 48 Loop2 MOV C,B Move the content of B
register to the C register
8006
8007 8008
21
01 8B
LXI
H,8B01 Load the HL pair with the
contents of 8B01
8009 7E Loop3 MOV A,M Move the content of M to the accumulator
800A 23 INX H Increment the HL pair
800B BE CMP M Compare the contents of the Memory with the
accumulator
800C
800D 800E
DA
14 80
JC Loop1 Jump on carry to the
specified address
800F
56
MOV D,M Move the content of the memory to the D register
8010 77
MOV M,A Move the contents of the
accumulator to the memory
8011
2B
DCX H Decrement the HL pair
8012 72
MOV M,D Move the content of the D register to the memory
8013 23 INX H Increment the HL pair
8014 0D Loop1 DCR C Decrement the C register
8015 8016
8017
C2 09
80
JNZ Loop2 Jump when the zero flag is not set
8018 05 DCR B Decrement the B register
8019 801A
801B
C2 05
80
JNZ Loop3 Jump when the zero flag is not set
801C 76 HLT Stop
BEFORE EXECUTION: AFTER EXECUTION:
1) 8B00 : 04
8B01 : 06 8B01 : 04 8B02 : 05 8B02 : 05 8B03 : 04 8B03 : 06
8B04 : 07 8B04 : 07
2) 8B00 : 05
8B01 : 26 8B01 : 1D 8B02 : 3F 8B02 : 26
8B03 : 3E 8B03 : 2A 8B04 : 1D 8B04 : 3E 8B05 : 2A 8B05 : 3F
15. Algorithm to sort n numbers in descending order using
Bubble sort.
Step 1: Start.
Step 2: Load the memory address in the accumulator
Step 3: Compute
[B]�[B]-1.
[B] � [A]
Step 4: Compute
[B] �N-1
Step 5: Again load the memory address in HL pair.
Step 6: Compute [C]�[B].
Step 7: Compare the number pointed by memory by the next number.
Step 8: If the number is smaller than the next number, swap the 2 numbers.
Step 9: Compute
[C]�[C]-1,
M�M+1.
Step 10: If [C]! =0 Go to Step 7
Else go to step 11.
Step 11:Compute [B]�[B]-1.
Step 12: If [B]! =0 Go to Step 5
Else go to step 13.
Step 12:Stop.
8085 Program to sort n numbers in descending order using Bubble sort.
Address Opcode Label Mnemonics Operand Comments
8000
8001 8002
3A
00 8B
LDA
8B00 Load the accumulator with the
contents of the address 8B00
8003 3D DCR A Decrement the accumulator
8004 47 MOV B,A Move the content of the
accumulator to the B register
8005 48 Loop2 MOV C,B Move the content of B register
to the C register
8006
8007 8008
21
01 8B
LXI
H,8B01 Load the HL pair with the
contents of 8B01
8009 7E Loop3 MOV A,M Move the content of M to the
accumulator
800A 23 INX H Increment the HL pair
800B BE CMP M Compare the contents of the Memory with the accumulator
800C 800D
800E
D2 14
80
JNC Loop1 Jump if the carry flag is not set.
800F
56
MOV D,M Move the content of the
memory to the D register
8010 77
MOV M,A Move the contents of the accumulator to the memory
8011
2B
DCX H Decrement the HL pair
8012 72
MOV M,D Move the content of the D
register to the memory
8013 23 INX H Increment the HL pair
8014 0D Loop1 DCR C Decrement the C register
8015
8016 8017
C2
09 80
JNZ Loop2 Jump when the zero flag is
not set
8018 05 DCR B Decrement the B register
8019
801A 801B
C2
05 80
JNZ Loop3 Jump when the zero flag is
not set
801C 76 HLT Stop
BEFORE EXECUTION: AFTER EXECUTION:
1) 8B00 : 04
8B01 : 06 8B01 : 07 8B02 : 05 8B02 : 06
8B03 : 04 8B03 : 05 8B04 : 07 8B04 : 04
2) 8B00 : 04
8B01 : 26 8B01 : 3F
8B02 : 3F 8B02 : 3E 8B03 : 3E 8B03 : 26 8B04 : 1D 8B04 :1D
16. Algorithm to find HCF of two one-byte numbers.
Step 1 : Start.
Step 2 : Load the HL pair with the specified memory address. Step 3 : Compute
[B] ←[M]
[HL] ← [HL] + 1
[A] ← [M].
Step 4 : Compute
[A] – [B] Step 5 : If the resultant value is zero, then Goto Step 10. Else Goto Step 6.
Step 6 : If the carry flag is not set, Goto Step 8. Else Goto Step 7.
Step 7 : Compute
[C] ← [B]
[B] ← [A]
[A] ← [C] .
Step 8 : Compute
[A] ← [A] – [B].
Step 9 : Goto Step 4. Step 10: Print [A].
Step 11: Stop .
8085 Program to find HCF of two one-byte numbers.
Address Opcode Label Mnemonics Operand Comments
8000 8001
8002
21 00
88
LXI H,8800 Load HL pair with Address 8800
8003 46 MOV B,M Move the contents
of Memory to Register B
8004 23 INX H Increment HL pair
8005 7E MOV A,M Move the contents
of Memory to Accumulator A
8006 B8 Loop2 CMP B Compare contents of Register B with
Accumulator
8007 8008
8009
CA 14
80
JZ Loop1 Jump to Loop1 when carry is 00
800A
800B 800C
D2
10 80
JNC Next Jump to Next when
carry is not zero.
800D 48 MOV C,B Move the contents of Register B to
Register C
800E 47 MOV B,A Move the contents
of Accumulator to register B
800F 79 MOV A,C Move the contents of Register C to the
Accumulator
8010 90 Next SUB B Subtract the contents of Register
B from Accumulator
8011
8012 8013
C3
06 80
JMP Loop2 Jump to Loop2
8014 8015
8016
32 60
89
Loop1 STA 8802 Store the contents of the Accumulator
at address 8804
8017 76 HLT Stop
INPUT: OUTPUT: 8800 : 04 8802 : 02
8801 : 0A
17. Algorithm to display FF and 00 alternatively with 1.5 seconds delay.
Step 1: Start
Step 2: Set [A] ← 00H
Step 3: Store Accumulator A contents in a memory location . Step 4: Call the subroutines UPDAT
Step 5: Set [A]←03H
Step 6: Call the subroutine DELAY.
Step 7 : Set [A]←FFH
Step 8: Store Accumulator A, contents in the memory location Step 9: Call the subroutines UPDAT
Step 10: Set [A]←03H
Step 11: Call the subroutine DELAY. Step 12: Go to step 1.
8085 program to display FF and 00 alternatively with 1.5 seconds
delay
Address Opcode Label Mnemonics Operands Comments
8000 8001
3E 00
Start MVI A,00 Move 00 to Accumulator
8002 8003
8004
32 F1
8F
STA 8FF1 Store content of Accumulator at
8FF1
8005
8006 8007
CD
40 04
CALL UPDAT Call UPDAT
8008 8009
3E 03
MVI A,03 Move 03 to Accumulator
800A 800B 800C
CD 34 02
CALL DELAY Call DELAY
800D 800E
3E FF
MVI A,FF Move FF to Accumulator
8010 8011
8012
32 F1
8F
STA 8FF1 Store content of Accumulator at
8FF1
8013
8014 8015
CD
40 04
CALL UPDAT Call UPDAT
8016 8017
3E 03
MVI A,03 Move 03 to Accumulator
8018 8019
801A
CD 34
02
CALL DELAY Call DELAY
801B
801C 801D
C3
00 80
JMP Start Jump to Start
OUTPUT
Displays FF and 00 alternatively in the data field with 1.5 seconds
delay.
18. Algorithm to check whether 1-byte number is a palindrome or not. Store FF if it is a palindrome otherwise 00.
Step 1 : Start .
Step 2 : Load the accumulator with the specified memory address. Step 3 : Compute
[B] ←[A].
Step 4 : Rotate [A] register Right Circular four times. Step 5 : Compute [A] – [B].
Step 6 : If the result is zero, Goto Step 9. Step 7 : Set
[A] ← 00.
Step 8 : Goto Step 10.
Step 9 : Set
[A] ← FF.
Step 10: Print [A] .
Step 11: Stop .
8085 Program to check whether 1-byte number is a palindrome or not. Store FF if it is a palindrome otherwise 00.
Address Opcode Label Mnemonics Operand Comments
8000
8001 8002
3A
00 81
LDA 8100 Load the accumulator
with the content of 8100
8003 47 MOV B , A Move the contents of A to the B register
8004 0F RRC Rotate the accumulator Right
Circular
8005 0F RRC Rotate the
accumulator Right Circular
8006 0F RRC Rotate the
accumulator Right Circular
8007 0F RRC Rotate the accumulator Right
Circular
8008 B8 CMP B Compare the content
of register B with the accumulator
8009 800A 800B
CA 11 80
JZ Loop Jump on Zero to the Specified label
800C 800D
3E 00
MVI A,00 Move the immediate data to the
accumulator
800E
800F 8010
C3
13 80
JMP Loop1 Jump unconditionally
to the specified label
8011 8012
3E FF
Loop MVI A,FF Move the immediate data to the
accumulator
8013
8014 8015
32
00 82
Loop1 STA 8101 Store the accumulator
value to the address 8200
8016 76 HLT Stop
INPUT: OUTPUT:
1. 8100 : 55 8101 : FF 2. 8100 : 01 8101 : 00
19. Algorithm to prepare lookup table for squares of one-digit
BCD numbers.
Step 1 : Start . Step 2 : Load the accumulator with the specified memory address.
Step 3 : Compute
[L] ← [A]
[H] ← 8A
[A] ← [M] .
Step 4 : Print [A] . Step 5 : Stop .
8085 Program to prepare lookup table for squares of one-digit BCD numbers.
Address Opcode Label Mnemonics Operand Comments
8000
8001 8002
3A
00 88
LDA 8800 Load the accumulator
with the contents of 8800
8003 6F MOV L,A Move the contents of A to the L register
8004 8005
26 8A
MVI H,81 Move immediate data 81 to the H register
8006 7E MOV A,M Move the contents of M to the accumulator
8007
8008 8009
32
70 89
STA 8801 Store the accumulator
value in the address 8801
800A 76 HLT Stop
INPUT: 8100 : 00
8101 : 01 8102 : 04
8103 : 09 8104 : 16 8105 : 25
8106 : 36 8107 : 49
8108 : 64 8109 : 81
INPUT: OUTPUT:
1. 8800 : 04 8801 : 16
2. 8800 : 09 8801 : 81
20. Algorithm to determine the LCM of two one-byte numbers.
Step 1 : Start . Step 2 : Load the HL pair with the specified memory address. Step 3 : Compute
[B] ← [M]
[HL] ← [HL] + 1
[C] ← [M]
[A] ← [B]
[D] ← [B]
Step 4 : Compute
[A] ← [A] – [B] .
Step 5 : If [A]!=0, Goto Step 6. Else Goto Step 10.
Step 6 : If the result is positive , Goto Step 4. Else Goto Step 7. Step 7 : Compute
[A] ← [B]
[A] ← [A] + [D]
[B] ← [A]
Step 8 : Goto Step 4.
Step 9 : Compute
[A] ← [B] .
Step 10: Print [A] .
Step 11: Stop .
8085 Program to determine the LCM of two one-byte numbers.
Address Opcode Label Mnemonics Operand Comments
8000 8001
8002
21 00
88
LXI H,8100 Load the HL pair with 8100.
8003 46 MOV B,M Move the contents of
M to the B register.
8004 23 INX H Increment the HL –
pair
8005 4E MOV C,M Move the contents of
M to the C register
8006 78 MOV A,B Move the contents of
B to the Accumulator
8007 50 MOV D,B Move the contents of B to the D register
8008 91 Loop1 SUB C Subtract the contents of C register from A
8009 800A
800B
CA 15
80
JZ Loop Jump on Zero to the Label Loop
800C
800D 800E
12
08 80
JP Loop1 Jump on Positive to
Loop1
800F 78 Loop MOV A,B Move the contents of B to the accumulator
8010 82 ADD D Add the contents of the D register to the
accumulator
8011 47 MOV B,A Move the contents of
A to the B register
8012
8013 8014
C3
08 80
JMP Loop1 Jump to Loop1.
8015 78 MOV A,B Move the contents of B to the accumulator
8016 8017 8018
32 52 80
STA 8102 Store the contents of the accumulator to the address 8052
8019 76 HLT Stop
INPUT: OUTPUT:
8100 : 03
8101 : 04 8102 :0C