8086 program to sort an integer array in descending order

PROGRAM NO.6

OBJECT:Write a program to input 5 numbers and arrange them in descending order
INSTRUMENT REQUIRED: 8086 Microprocessor Trainer Kit.
PROGRAM:

MEMORY LOCATION MACHINE CODE OPCODE OPERAND
0200 BE 00 03 MOV SI,0300H
0203 8B 1C MOV BX,[SI]
0205 4B DEC BX
0206 8B 0C MOV CX,[SI]
0208 49 DEC CX
0209 BE 02 03 MOV SI,0302H
020C 8A 04 MOV AL,[SI]
020E 46 INC SI
020F 3A 04 CMP AL,[SI]
0211 73 06 JAE 0219
0213 86 04 XCHG AL,[SI]
0215 4E DEC SI
0216 88 04 MOV [SI],AL
0218 46 INC SI
0219 E2 F1 LOOP 020C
021B 4B DEC BX
021C BE 00 03 MOV SI,0300H
021F 75 E5 JNZ 0206
0221 F4 HLT  

DESCRIPTION:

To solve the given objective we have taken FIVE hexadecimal numbers in the memory locations of 0302H to 0306H and used bubble sorting to sort them up.

 To solve the given objective we have taken the following steps:

  1. Move the source index register (SI) pointer to the location where the total number of given numbers to be sorted is given.
  2. Store the number pointed by SI in the BX register.
  3. Decrement the value in BX and simultaneously store the value pointed by SI in another register CX and decrement it as well.
  4. Move the first number in the AX register using SI.
  5. Increment SI so as to enable it to point it to the next number.
  6. Compare the two numbers and jump if the one number is greater than or equal to the other else exchange the two numbers.
  7. Repeat the above process until all the numbers are arranged in descending order and the counters have been reduced to zero and then finally halt.

INPUT:

MEMORY LOCATION VALUE
0300H 05
0301H 00
0302H 20
0303H 25
0304H 28
0305H 15
0306H 07

OUTPUT:

MEMORY LOCATION VALUE
0300H 05
0301H 00
0302H 28
0303H 25
0304H 20
0305H 15
0306H 07

RESULT: The sorting is in the decreasing order as above using bubble sorting.

COMMENTS:

  1. MOV SI, 0300H: 16 bit data can be moved using immediate addressing. 0300 is moved to source index.
  2. DEC BX: these instruction decrements specified 16-bit register by one.
  3. JAE: It causes the program execution to jump to the label given in the instruction.
  4. LOOP: The instruction LOOP is used to repeat a sequence of instructions for the specified number of times.
  5. XCHG AL,[SI]: This instruction exchanges the contents of an 8-bit or 16-bit specified register with the content of an 8-bit or 16-bit specified register or memory location(s).
  6. HLT: This instruction stops program execution. The processor stops fetching and executing instructions.

FLOWCHART:

8086 program to sort an integer array in descending order


Most Important Question for Exam

1. The External device is connected to a pin caled the ______ pin on the processor chip




Answer is C)
Interrupt


2. In 8085 name the 16 bit registers?




Answer is C)
A & B


3. What is SIM




Answer is A)
Set Interrupt Mask

4. RIM is used to check whether_______




Answer is C)
The Interrupt is Marked or not

5. Which are the part of architecture of 8086:




Answer is B)
Both C & D

6. Which are the segement




Answer is D)
All of these

7. The Accumulator is 16 bit wide and is called:




Answer is C)
AX

8. The upper 8 bit are called___________:




Answer is D)
AH

9. The lower 8 bit called _________:




Answer is D)
AL

10. Which has great important in modular programing:




Answer is B)
Stack Segment

11. Which register containing the 8086/8088 flag:




Answer is C)
Status Register

12. How many bits the instruction pointer is wide:




Answer is B)
16 bit

13. How many type of addressing in memory:




Answer is B)
Both C & D

14. The size of each segment 8086 is:




Answer is D)
64 kb

15. The Physical address of memory is:




Answer is C)
20 bit

16. SBA stand for:




Answer is B)
Segment base address

17. Which memory is used to hold the address of data store:




Answer is C)
Associative Memory

18. A Microprocessor is a ________ chip integrating all the functions of a CPU of a computer.




Answer is C)
Single

19. Microprocessor is a ___________circuite that function as the CPU of the compute




Answer is D)
Electronic

20. Microprocessor is the________ of the computer and it perform all the computational tasks




Answer is C)
Heart

21. The purpose of the microprocessor is to control________




Answer is D)
Memory

22. The first digital electronic computer was built in the year_________




Answer is B)
1940

23. In 1960’s texas institute invented__________




Answer is C)
Integrated Circuits

24. The Intel 8086 Microprocessor is a ___________processor




Answer is B)
16 bit

25. The 16 bit flag of 8086 Microprocessor to indicate_________




Answer is C)
The condition of result of ALU

26. The CF is known as ____________




Answer is B)
Carry Flag

27. The SF is caled as _________




Answer is A)
Sign Flag

28. The OF is called as_________




Answer is C)
Overflow Flag

29. The register AX is formed by grouping_________




Answer is B)
AH & AL

30. The Index register are used to hold _____




Answer is C)
Memory Register

Related Link