# Ascending and Decending Order of N Numbers

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

# ASCENDING AND DECENDING ORDER OF N NUMBERS

AIM:
To determine the ascending and descending order of the given number using
8085 microprocessor.

APPARATUS REQUIRED:
 8085 Microprocessor Kit
 Power Chord

ASCENDING ORDER:

ALGORITHM:
Step1: Start the program
Step2: Get the first number and store it in B register and get the second number in
memory and move it to accumulator.
Step3: Increment memory and compare it with accumulator if carry is present
increment memory by decrementing B register if it is not zero.
Step4: If B register become zero decrement D register which contain number
first, zero is not obtained then get in the memory.
Step5: If it is zero store the result in the accumulator.
Step6: If the compared output contains no carry, move the value in memory to C
register and accumulator to memory and increment the value in memory.
Step7: stop the program.
MNEMONICS:
LDA 5000
MOV B,A
MOV D,A
MOV E,A
LXI H,5001
MOV A,M
MOV B,E
LOOP2 INX H
CMP M
JC LOOP1
MOV C,M
MOV M,A
DCX H
MOV M,C
INX H
LOOP1 MOV A, M
DCR B;
JNZ LOOP2
DCR B
JNZ LOOP3
HLT
TABLE: 1

Mnemonics HEX Description


Memory Label
Instruction Operand CODE
4500 LDA 5000 3A Get the first data to accumulator
4501 00
4502 50
4503 MOV B,A 47 Move the data from A to B
4504 MOV D,A 5F Move the data from A to D
4505 MOV E,A 57 Move the data from A to E
4506 LOOP 3 LXI H,5001 21 Move second data to memory
4507 01
4508 50
4509 MOV A,M 7E Move M to Accumulator
450A MOV B,E 43 Move E to B register
450B LOOP 2 INX H 25 Increment H Register
450C CMP M BE Compare A and M
450D JC LOOP1 DA Jump if carry to loop1
450E 15
450F 45
4510 MOV C,M 4E Move M to C register
4511 MOV M,A `77 Move A to Memory
4512 DCX H 2B Decrement H Register
4513 MOV M,C 71 Move the value from C to H
4514 INX H 23 Increment H Register
4515 LOOP 1 MOV A,M 7E Move the value from M to A
4516 DCR B O5 Decrement B Register
4517 JNZ LOOP 2 C2 Jump is no zero to LOOP 2
4518 0B
4519 45
451A DCR D 15 Decrement D Register
451B JNZ LOOP 3 C2 Jump is no zero to LOOP 3
451C 06
451D 45
451E HLT 76 End of Program

DESCENDING ORDER:

ALGORITHM:
Step1: Start the program
Step2: Get the first number and store it in B register and get the second number in
memory and move it to accumulator.
Step3: Increment memory and compare it with accumulator if carry is present
increment memory by decrementing B register if it is not zero.
Step4: If B register become zero decrement D register which contain number
first, zero is not obtained then get in the memory.
Step5: If it is zero store the result in the accumulator.
Step6: If the compared output contains no carry, move the value in memory to C
register and accumulator to memory and increment the value in memory.
Step7: stop the program.

MNEMONICS:
LDA 5000
MOV B,A
MOV D,A
MOV E,A
LXI H,5001
MOV A,M
MOV B,E
LOOP2 INX H
CMP M
JNC LOOP1
MOV C, M
MOV M,A
DCX H
MOV M,C
INX H

LOOP1 MOV A, M
DCR B;
JNZ LOOP2
DCR B
JNZ LOOP3
HL
Mnemonics HEX Description
Memory Label
Instruction Operand CODE
4500 LDA 5000 3A Get the first data to accumulator
4501 00
4502 50
4503 MOV B,A 47 Move the data from A to B
4504 MOV D,A 5F Move the data from A to D
4505 MOV E,A 57 Move the data from A to E
4506 LOOP 3 LXI H,5001 21 Move second data to memory
4507 01
4508 50
4509 MOV A,M 7E Move M to Accumulator
450A MOV B,E 43 Move E to B register
450B LOOP 2 INX H 25 Increment H Register
450C CMP M BE Compare A and M
450D JNC LOOP1 DA Jump if carry to loop1
450E 15
450F 45
4510 MOV C,M 4E Move M to C register
4511 MOV M,A `77 Move A to Memory
4512 DCX H 2B Decrement H Register
4513 MOV M,C 71 Move the value from C to H
4514 INX H 23 Increment H Register

4515 LOOP1 MOV A,M 7E Move the value from M to A


4516 DCR B O5 Decrement B Register
4517 JNZ LOOP 2 C2 Jump is no zero to LOOP 2
4518 0B
4519 45
451A DCR D 15 Decrement D Register
451B JNZ LOOP 3 C2 Jump is no zero to LOOP 3
451C 06
451D 45
451E HLT 76 End of Program

You might also like