Arrange in ascending order using 8085
Ø An
Assembly Language Program to arrange an array of data in ascending order using
8085?
Algorithm
1) Initialize
HL pair as memory pointer.
2) Get
the count at 4200 in to C register.
3) Copy
it in D register.
4) Get
the first vale in Accumulator.
5) Compare
it with the value at next location.
6) If
they are out of order, exchange the contents of accumulator and memory.
7) Decrement
D register’s content by 1.
8) Repeat
steps 5 and 7 till the value in D register become zero.
9) Decrement
C register’s content by 1.
10) Repeat
steps 3 to 9 till the value in C register becomes zero.
11) Terminate
the program.
Program
MEMORY
|
LABEL
|
MNEMONIC
|
HEX CODE
|
COMMENT
|
4400
|
LXI H,4200
|
21
|
Load the array
size to the HL pair
|
|
4401
|
00
|
|||
4402
|
42
|
|||
4403
|
MOV C,M
|
4E
|
Copy the array
size to C register
|
|
4404
|
DCR C
|
0D
|
Decrement C by
1
|
|
4405
|
REPEAT
|
MOV D,C
|
51
|
Copy content
of C to D register
|
4406
|
LXI H,4201
|
21
|
Load the first
data to the HL pair
|
|
4407
|
01
|
|||
4408
|
42
|
|||
4409
|
LOOP
|
MOV A,M
|
7E
|
Copy the data
to the accumulator
|
440A
|
INX H
|
23
|
Increment
memory by 1
|
|
440B
|
CMP M
|
BE
|
Compare
accumulator and memory content
|
|
440C
|
JC SKIP
|
DA
|
Jump on carry
to the label SKIP
|
|
440D
|
14
|
|||
440E
|
44
|
|||
440F
|
MOV B,M
|
46
|
Copy memory
content to B register
|
|
4410
|
MOV M,A
|
77
|
Copy
accumulator content to memory
|
|
4411
|
DCX H
|
2B
|
Decrement
memory by 1
|
|
4412
|
MOV M,B
|
70
|
Copy B
register’s content to memory
|
|
4413
|
INX H
|
23
|
Increment
memory by 1
|
|
4414
|
SKIP
|
DCR D
|
15
|
Decrement D by
1
|
4415
|
JNZ LOOP
|
C2
|
Jump on
non-zero to the label LOOP
|
|
4416
|
09
|
|||
4417
|
44
|
|||
4418
|
DCR C
|
0D
|
Decrement C by
1
|
|
4419
|
JNZ REPEAT
|
C2
|
Jump on
non-zero to the label REPEAT
|
|
441A
|
05
|
|||
441B
|
44
|
|||
441C
|
HLT
|
76
|
Program ends
|
Observation
Input at 4200 : 05H ---------- Array Size
4201 : 05H
4202 : 04H
4203 : 03H
4204 : 02H
4205 : 01H
Output at 4200 : 05H ---------- Array Size
4201 : 01H
4202 : 02H
4203 : 03H
4204 : 04H
4205 : 05H
----------------------------------------------------------------------------------------Arrange in descending order using 8085
Ø An
Assembly Language Program to arrange an array of data in descending order using
8085?
Algorithm
1) Initialize
HL pair as memory pointer.
2) Get
the count at 4200 in to C register.
3) Copy
it in D register.
4) Get
the first vale in Accumulator.
5) Compare
it with the value at next location.
6) If
they are out of order, exchange the contents of accumulator and memory.
7) Decrement
D register’s content by 1.
8) Repeat
steps 5 and 7 till the value in D register become zero.
9) Decrement
C register’s content by 1.
10) Repeat
steps 3 to 9 till the value in C register becomes zero.
11) Terminate
the program.
Program
MEMORY
|
LABEL
|
MNEMONIC
|
HEX CODE
|
COMMENT
|
4400
|
LXI H,4200
|
21
|
Load the array
size to the HL pair
|
|
4401
|
00
|
|||
4402
|
42
|
|||
4403
|
MOV C,M
|
4E
|
Copy the array
size to C register
|
|
4404
|
DCR C
|
0D
|
Decrement C by
1
|
|
4405
|
REPEAT
|
MOV D,C
|
51
|
Copy content
of C to D register
|
4406
|
LXI H,4201
|
21
|
Load the first
data to the HL pair
|
|
4407
|
01
|
|||
4408
|
42
|
|||
4409
|
LOOP
|
MOV A,M
|
7E
|
Copy the data
to the accumulator
|
440A
|
INX H
|
23
|
Increment
memory by 1
|
|
440B
|
CMP M
|
BE
|
Compare
accumulator and memory content
|
|
440C
|
JNC SKIP
|
D2
|
Jump on no
carry to the label SKIP
|
|
440D
|
14
|
|||
440E
|
44
|
|||
440F
|
MOV B,M
|
46
|
Copy memory
content to B register
|
|
4410
|
MOV M,A
|
77
|
Copy
accumulator content to memory
|
|
4411
|
DCX H
|
2B
|
Decrement
memory by 1
|
|
4412
|
MOV M,B
|
70
|
Copy B
register’s content to memory
|
|
4413
|
INX H
|
23
|
Increment
memory by 1
|
|
4414
|
SKIP
|
DCR D
|
15
|
Decrement D by
1
|
4415
|
JNZ LOOP
|
C2
|
Jump on
non-zero to the label LOOP
|
|
4416
|
09
|
|||
4417
|
44
|
|||
4418
|
DCR C
|
0D
|
Decrement C by
1
|
|
4419
|
JNZ REPEAT
|
C2
|
Jump on
non-zero to the label REPEAT
|
|
441A
|
05
|
|||
441B
|
44
|
|||
441C
|
HLT
|
76
|
Program ends
|
Observation
Input at 4200 : 05H ---------- Array Size
4201 : 01H
4202 : 02H
4203 : 03H
4204 : 04H
4205 : 05H
Output at 4200 : 05H ---------- Array Size
4201 : 05H
4202 : 04H
4203 : 03H
4204 : 02H
4205 : 01H
-------------------------------------------------------------------------------------
there should be HEXCODE in place of OPCODE. as opcodes are included in mnemonics.
ReplyDeleteBTW thank you so much
My Mistake. Thank you for pointing out. Will correct it.
Deletegreat job !!
ReplyDeleteopcode for jnz is D2 and not DA
ReplyDeleteI think you meant JNC. Corrected. Thank you for pointing out.
Delete